From c00bf123c63a06742438bf59fc287dd5fb53b48e Mon Sep 17 00:00:00 2001 From: Alex Tymchuk Date: Tue, 26 Sep 2023 20:00:02 +0300 Subject: [PATCH] PMM-7 fix linter config and some errors --- .golangci.yml | 30 +++++++++++-------- agent/runner/jobs/pbm_helpers.go | 2 +- managed/services/agents/grpc/agent_server.go | 2 +- managed/services/agents/log_level.go | 4 +-- .../services/backup/pitr_timerange_service.go | 2 +- .../management/grpc/actions_server.go | 2 +- .../management/grpc/mongodb_server.go | 2 +- .../services/management/grpc/mysql_server.go | 2 +- .../services/management/grpc/node_server.go | 2 +- managed/services/telemetry/telemetry.go | 2 +- 10 files changed, 27 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ff07ed391b..9ba704817d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,19 +7,19 @@ linters-settings: max-complexity: 30 depguard: - list-type: blacklist - include-go-root: true - packages: - # use "github.com/pkg/errors" instead - - errors - # use "github.com/golang/protobuf/proto" instead - - github.com/gogo/protobuf/proto - # use only forked parser - - github.com/percona/go-mysql/log/slow - # use "github.com/percona-platform/saas" instead - - github.com/percona-platform/platform - # use "gopkg.in/yaml.v3" instead - - gopkg.in/yaml.v2 + rules: + main: + deny: + - pkg: "errors" + desc: use "github.com/pkg/errors" instead + - pkg: "github.com/gogo/protobuf/proto" + desc: use "github.com/golang/protobuf/proto" instead + - pkg: "github.com/percona/go-mysql/log/slow" + desc: only use the forked parser + - pkg: "github.com/percona-platform/platform" + desc: use "github.com/percona-platform/saas" instead + - pkg: "gopkg.in/yaml.v2" + desc: use "gopkg.in/yaml.v3" instead gci: sections: @@ -103,8 +103,12 @@ linters: - maligned # deprecated - nlreturn # too annoying - nosnakecase # deprecated + - rowserrcheck # disabled because of generics - scopelint # too many false positives + - structcheck # replaced by unused + - varcheck # replaced by unused - varnamelen # useless + - wastedassign # disabled because of generics - wrapcheck # we do not use wrapping everywhere - wsl # too annoying diff --git a/agent/runner/jobs/pbm_helpers.go b/agent/runner/jobs/pbm_helpers.go index 09e9c4006b..0ede95084a 100644 --- a/agent/runner/jobs/pbm_helpers.go +++ b/agent/runner/jobs/pbm_helpers.go @@ -279,7 +279,7 @@ func waitForPBMBackup(ctx context.Context, l logrus.FieldLogger, dbURL *string, return nil case "canceled": return errors.New("backup was canceled") - case "error": //nolint:goconst + case "error": return errors.New(info.Error) } diff --git a/managed/services/agents/grpc/agent_server.go b/managed/services/agents/grpc/agent_server.go index da6e23502d..69eced0a99 100644 --- a/managed/services/agents/grpc/agent_server.go +++ b/managed/services/agents/grpc/agent_server.go @@ -40,7 +40,7 @@ func (s *agentServer) Connect(stream agentpb.Agent_ConnectServer) error { return s.handler.Run(stream) } -// check interfaces +// check interfaces. var ( _ agentpb.AgentServer = (*agentServer)(nil) ) diff --git a/managed/services/agents/log_level.go b/managed/services/agents/log_level.go index a7cc24c273..2b33b472f8 100644 --- a/managed/services/agents/log_level.go +++ b/managed/services/agents/log_level.go @@ -22,11 +22,11 @@ import ( "github.com/percona/pmm/version" ) -// Log level available in exporters with pmm 2.28 +// Log level available in exporters with pmm 2.28. var exporterLogLevelCommandVersion = version.MustParse("2.27.99") // withLogLevel - append CLI args --log.level -// mysqld_exporter, node_exporter and postgres_exporter don't support --log.level=fatal +// mysqld_exporter, node_exporter and postgres_exporter don't support --log.level=fatal. func withLogLevel(args []string, logLevel *string, pmmAgentVersion *version.Parsed, supportLogLevelFatal bool) []string { level := pointer.GetString(logLevel) diff --git a/managed/services/backup/pitr_timerange_service.go b/managed/services/backup/pitr_timerange_service.go index 000ca1c22c..34d406850c 100644 --- a/managed/services/backup/pitr_timerange_service.go +++ b/managed/services/backup/pitr_timerange_service.go @@ -251,7 +251,7 @@ func getTimelines(slices []*oplogChunk) []Timeline { var timelines []Timeline var prevEnd primitive.Timestamp for _, s := range slices { - if prevEnd.T != 0 && primitive.CompareTimestamp(prevEnd, s.StartTS) == -1 { + if prevEnd.T != 0 && prevEnd.Compare(s.StartTS) == -1 { timelines = append(timelines, tl) tl = Timeline{} } diff --git a/managed/services/management/grpc/actions_server.go b/managed/services/management/grpc/actions_server.go index cfcfdac444..b1c2ba947a 100644 --- a/managed/services/management/grpc/actions_server.go +++ b/managed/services/management/grpc/actions_server.go @@ -340,7 +340,7 @@ func (s *actionsServer) StartPostgreSQLShowIndexAction(ctx context.Context, req }, nil } -// StartMongoDBExplainAction starts MongoDB Explain action +// StartMongoDBExplainAction starts MongoDB Explain action. func (s *actionsServer) StartMongoDBExplainAction(ctx context.Context, req *managementpb.StartMongoDBExplainActionRequest) ( *managementpb.StartMongoDBExplainActionResponse, error, ) { diff --git a/managed/services/management/grpc/mongodb_server.go b/managed/services/management/grpc/mongodb_server.go index 8836f2f230..201b04fd10 100644 --- a/managed/services/management/grpc/mongodb_server.go +++ b/managed/services/management/grpc/mongodb_server.go @@ -22,7 +22,7 @@ import ( "github.com/percona/pmm/managed/services/management" ) -// TODO merge into ../mongodb.go +// TODO merge into ../mongodb.go. type mongoDBServer struct { svc *management.MongoDBService diff --git a/managed/services/management/grpc/mysql_server.go b/managed/services/management/grpc/mysql_server.go index 43048d48cc..6753a6c4db 100644 --- a/managed/services/management/grpc/mysql_server.go +++ b/managed/services/management/grpc/mysql_server.go @@ -22,7 +22,7 @@ import ( "github.com/percona/pmm/managed/services/management" ) -// TODO merge into ../mysql.go +// TODO merge into ../mysql.go. type mySQLServer struct { svc *management.MySQLService diff --git a/managed/services/management/grpc/node_server.go b/managed/services/management/grpc/node_server.go index e8922fc62c..1191ee3081 100644 --- a/managed/services/management/grpc/node_server.go +++ b/managed/services/management/grpc/node_server.go @@ -22,7 +22,7 @@ import ( "github.com/percona/pmm/managed/services/management" ) -// TODO merge into ../node.go +// TODO merge into ../node.go. type nodeServer struct { svc *management.NodeService diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index 867f31f211..99b491b0e9 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -169,7 +169,7 @@ func (s *Service) DistributionMethod() serverpb.DistributionMethod { func (s *Service) processSendCh(ctx context.Context) { var reportsBufSync sync.Mutex var reportsBuf []*pmmv1.ServerMetric - var sendCtx context.Context + var sendCtx context.Context //nolint:contextcheck var cancel context.CancelFunc for {