Skip to content

Commit

Permalink
K8SPSMDB-996: fix mongodb-healthcheck logs (#1355)
Browse files Browse the repository at this point in the history
https://jira.percona.com/browse/K8SPSMDB-996

Co-authored-by: Viacheslav Sarzhan <slava.sarzhan@percona.com>
  • Loading branch information
pooknull and hors authored Mar 14, 2024
1 parent ab96d35 commit fbe5da8
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 276 deletions.
2 changes: 2 additions & 0 deletions cmd/mongodb-healthcheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

uzap "go.uber.org/zap"
"go.uber.org/zap/zapcore"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/percona/percona-server-mongodb-operator/healthcheck"
Expand Down Expand Up @@ -54,6 +55,7 @@ func main() {
Level: getLogLevel(),
}
log := zap.New(zap.UseFlagOptions(&opts))
logf.SetLogger(log)

restoreInProgress, err := fileExists("/opt/percona/restore-in-progress")
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/percona/percona-backup-mongodb v1.8.1-0.20230920143330-3b1c2e263901
github.com/pkg/errors v0.9.1
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
go.mongodb.org/mongo-driver v1.13.1
go.uber.org/zap v1.26.0
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,6 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
Expand Down Expand Up @@ -631,7 +629,6 @@ golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down
171 changes: 0 additions & 171 deletions healthcheck/tools/command/command.go

This file was deleted.

13 changes: 5 additions & 8 deletions healthcheck/tools/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"time"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
mgo "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/percona/percona-server-mongodb-operator/pkg/psmdb/mongo"
)
Expand All @@ -32,16 +32,13 @@ var (
)

func Dial(ctx context.Context, conf *Config) (mongo.Client, error) {
log.WithFields(log.Fields{
"hosts": conf.Hosts,
"ssl": conf.SSL.Enabled,
"ssl_secure": conf.SSL.Insecure,
}).Debug("Connecting to mongodb")

if err := conf.configureTLS(); err != nil {
return nil, errors.Wrap(err, "configure TLS")
}

log := logf.FromContext(ctx)
log.V(1).Info("Connecting to mongodb", "hosts", conf.Hosts, "ssl", conf.SSL.Enabled, "ssl_insecure", conf.SSL.Insecure)

opts := options.Client().
SetHosts(conf.Hosts).
SetReplicaSet(conf.ReplSetName).
Expand All @@ -51,7 +48,7 @@ func Dial(ctx context.Context, conf *Config) (mongo.Client, error) {
SetServerSelectionTimeout(10 * time.Second)

if conf.Username != "" && conf.Password != "" {
log.WithFields(log.Fields{"user": conf.Username}).Debug("Enabling authentication for session")
log.V(1).Info("Enabling authentication for session", "user", conf.Username)
}

client, err := mgo.Connect(ctx, opts)
Expand Down
8 changes: 5 additions & 3 deletions healthcheck/tools/db/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"os"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

var lastSSLErr error
Expand Down Expand Up @@ -48,6 +48,8 @@ func LastSSLError() error {
}

func (cnf *Config) configureTLS() error {
log := logf.Log

if !cnf.SSL.Enabled {
return nil
}
Expand All @@ -62,7 +64,7 @@ func (cnf *Config) configureTLS() error {
return errors.Wrapf(err, "check if file with name %s exists", cnf.SSL.PEMKeyFile)
}

log.Debugf("Loading SSL/TLS PEM certificate: %s", cnf.SSL.PEMKeyFile)
log.V(1).Info("Loading SSL/TLS PEM certificate", "certificate", cnf.SSL.PEMKeyFile)
certificates, err := tls.LoadX509KeyPair(cnf.SSL.PEMKeyFile, cnf.SSL.PEMKeyFile)
if err != nil {
return errors.Wrapf(err, "load key pair from '%s' to connect to server '%s'", cnf.SSL.PEMKeyFile, cnf.Hosts)
Expand All @@ -77,7 +79,7 @@ func (cnf *Config) configureTLS() error {
return errors.Wrapf(err, "check if file with name %s exists", cnf.SSL.CAFile)
}

log.Debugf("Loading SSL/TLS Certificate Authority: %s", cnf.SSL.CAFile)
log.V(1).Info("Loading SSL/TLS Certificate Authority: %s", "ca", cnf.SSL.CAFile)
ca, err := cnf.SSL.loadCaCertificate()
if err != nil {
return errors.Wrapf(err, "load client CAs from %s", cnf.SSL.CAFile)
Expand Down
90 changes: 0 additions & 90 deletions healthcheck/tools/util.go

This file was deleted.

0 comments on commit fbe5da8

Please sign in to comment.