Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-7 Fix linter config and some errors #2504

Merged
merged 6 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion agent/runner/jobs/pbm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/grpc/agent_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
4 changes: 2 additions & 2 deletions managed/services/agents/log_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion managed/services/backup/backup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ func checkArtifactMode(artifact *models.Artifact, pitrTimestamp time.Time) error
return nil
}

// inTimeSpan checks whether given time is in the given range
// inTimeSpan checks whether given time is in the given range.
func inTimeSpan(start, end, check time.Time) bool {
if start.Before(end) {
return !check.Before(start) && !check.After(end)
Expand Down
2 changes: 1 addition & 1 deletion managed/services/backup/compatibility_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (s *CompatibilityService) CheckArtifactCompatibility(artifactID, targetDBVe
return s.artifactCompatibility(artifactModel, serviceModel, targetDBVersion)
}

// artifactCompatibility contains logic for CheckArtifactCompatibility
// artifactCompatibility contains logic for CheckArtifactCompatibility.
func (s *CompatibilityService) artifactCompatibility(artifactModel *models.Artifact, serviceModel *models.Service, targetDBVersion string) error {
var err error
if artifactModel.DBVersion != "" && artifactModel.DBVersion != targetDBVersion {
Expand Down
16 changes: 8 additions & 8 deletions managed/services/backup/pitr_timerange_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (

var errUnsupportedLocation = errors.New("unsupported location config")

// PBMPITRService helps to perform PITR chunks lookup in a backup storage
// PBMPITRService helps to perform PITR chunks lookup in a backup storage.
type PBMPITRService struct {
l *logrus.Entry
}
Expand All @@ -49,7 +49,7 @@ func NewPBMPITRService() *PBMPITRService {
}
}

// oplogChunk is index metadata for the oplog chunks
// oplogChunk is index metadata for the oplog chunks.
type oplogChunk struct {
RS string `bson:"rs"`
FName string `bson:"fname"`
Expand All @@ -59,7 +59,7 @@ type oplogChunk struct {
size int64 `bson:"-"`
}

// Timeline is an internal representation of a PITR Timeline
// Timeline is an internal representation of a PITR Timeline.
type Timeline struct {
ReplicaSet string `json:"replica_set"`
Start uint32 `json:"start"`
Expand All @@ -79,7 +79,7 @@ func (x gaps) Less(i, j int) bool {
}
func (x gaps) Swap(i, j int) { x[i], x[j] = x[j], x[i] }

// compressionType is the type of compression used for PITR oplog
// compressionType is the type of compression used for PITR oplog.
type compressionType string

const (
Expand All @@ -91,7 +91,7 @@ const (
compressionTypeZstandard compressionType = "zstd"
)

// file return compression alg based on given file extension
// file return compression alg based on given file extension.
func file(ext string) compressionType {
switch ext {
case "gz":
Expand Down Expand Up @@ -190,7 +190,7 @@ func trimTimelines(timelines []Timeline) {
// current format is 20200715155939-0.20200715160029-1.oplog.snappy
// (https://github.com/percona/percona-backup-mongodb/wiki/PITR:-storage-layout)
//
// !!! Should be agreed with pbm/pitr.chunkPath()
// !!! Should be agreed with pbm/pitr.chunkPath().
func pitrMetaFromFileName(prefix, f string) *oplogChunk {
ppath := strings.Split(f, "/")
if len(ppath) < 2 {
Expand Down Expand Up @@ -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{}
}
Expand All @@ -269,7 +269,7 @@ func getTimelines(slices []*oplogChunk) []Timeline {
}

// mergeTimelines merges overlapping sets on timelines
// it presumes timelines are sorted and don't start from 0
// it presumes timelines are sorted and don't start from 0.
func mergeTimelines(timelines ...[]Timeline) []Timeline {
// fast paths
if len(timelines) == 0 {
Expand Down
34 changes: 17 additions & 17 deletions managed/services/dbaas/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// Package client TODO
// Package client TODO.
package client

import (
Expand Down Expand Up @@ -107,7 +107,7 @@ type Client struct {
namespace string
}

// SortableEvents implements sort.Interface for []api.Event based on the Timestamp field
// SortableEvents implements sort.Interface for []api.Event based on the Timestamp field.
type SortableEvents []corev1.Event

func (list SortableEvents) Len() int {
Expand Down Expand Up @@ -192,7 +192,7 @@ func NewFromInCluster() (*Client, error) {
}

// NewFromKubeConfigString creates a new client for the given config string.
// It's intended for clients that expect to be running outside of a cluster
// It's intended for clients that expect to be running outside of a cluster.
func NewFromKubeConfigString(kubeconfig string) (*Client, error) {
config, err := clientcmd.BuildConfigFromKubeconfigGetter("", NewConfigGetter(kubeconfig).loadFromString)
if err != nil {
Expand Down Expand Up @@ -235,7 +235,7 @@ func (c *Client) setup() error {
return c.initOperatorClients()
}

// Initializes clients for operators
// Initializes clients for operators.
func (c *Client) initOperatorClients() error {
dbClusterClient, err := database.NewForConfig(c.restConfig)
if err != nil {
Expand All @@ -246,7 +246,7 @@ func (c *Client) initOperatorClients() error {
return err
}

// GetSecretsForServiceAccount returns secret by given service account name
// GetSecretsForServiceAccount returns secret by given service account name.
func (c *Client) GetSecretsForServiceAccount(ctx context.Context, accountName string) (*corev1.Secret, error) {
serviceAccount, err := c.clientset.CoreV1().ServiceAccounts(c.namespace).Get(ctx, accountName, metav1.GetOptions{})
if err != nil {
Expand All @@ -263,7 +263,7 @@ func (c *Client) GetSecretsForServiceAccount(ctx context.Context, accountName st
metav1.GetOptions{})
}

// GenerateKubeConfig generates kubeconfig
// GenerateKubeConfig generates kubeconfig.
func (c *Client) GenerateKubeConfig(secret *corev1.Secret) ([]byte, error) {
conf := &Config{
Kind: configKind,
Expand Down Expand Up @@ -301,7 +301,7 @@ func (c *Client) GenerateKubeConfig(secret *corev1.Secret) ([]byte, error) {
return c.marshalKubeConfig(conf)
}

// GetServerVersion returns server version
// GetServerVersion returns server version.
func (c *Client) GetServerVersion() (*version.Info, error) {
return c.clientset.Discovery().ServerVersion()
}
Expand All @@ -320,27 +320,27 @@ func (c *Client) GetDatabaseCluster(ctx context.Context, name string) (*dbaasv1.
return cluster, nil
}

// GetStorageClasses returns all storage classes available in the cluster
// GetStorageClasses returns all storage classes available in the cluster.
func (c *Client) GetStorageClasses(ctx context.Context) (*storagev1.StorageClassList, error) {
return c.clientset.StorageV1().StorageClasses().List(ctx, metav1.ListOptions{})
}

// GetDeployment returns deployment by name
// GetDeployment returns deployment by name.
func (c *Client) GetDeployment(ctx context.Context, name string) (*appsv1.Deployment, error) {
return c.clientset.AppsV1().Deployments(c.namespace).Get(ctx, name, metav1.GetOptions{})
}

// GetSecret returns secret by name
// GetSecret returns secret by name.
func (c *Client) GetSecret(ctx context.Context, name string) (*corev1.Secret, error) {
return c.clientset.CoreV1().Secrets(c.namespace).Get(ctx, name, metav1.GetOptions{})
}

// ListSecrets returns secrets
// ListSecrets returns secrets.
func (c *Client) ListSecrets(ctx context.Context) (*corev1.SecretList, error) {
return c.clientset.CoreV1().Secrets(c.namespace).List(ctx, metav1.ListOptions{})
}

// DeleteObject deletes object from the k8s cluster
// DeleteObject deletes object from the k8s cluster.
func (c *Client) DeleteObject(obj runtime.Object) error {
groupResources, err := restmapper.GetAPIGroupResources(c.clientset.Discovery())
if err != nil {
Expand Down Expand Up @@ -459,12 +459,12 @@ func (c *Client) marshalKubeConfig(conf *Config) ([]byte, error) {
return yaml.Marshal(jsonObj)
}

// GetPersistentVolumes returns Persistent Volumes available in the cluster
// GetPersistentVolumes returns Persistent Volumes available in the cluster.
func (c *Client) GetPersistentVolumes(ctx context.Context) (*corev1.PersistentVolumeList, error) {
return c.clientset.CoreV1().PersistentVolumes().List(ctx, metav1.ListOptions{})
}

// GetPods returns list of pods
// GetPods returns list of pods.
func (c *Client) GetPods(ctx context.Context, namespace string, labelSelector *metav1.LabelSelector) (*corev1.PodList, error) {
options := metav1.ListOptions{}
if labelSelector != nil && (labelSelector.MatchLabels != nil || labelSelector.MatchExpressions != nil) {
Expand All @@ -474,12 +474,12 @@ func (c *Client) GetPods(ctx context.Context, namespace string, labelSelector *m
return c.clientset.CoreV1().Pods(namespace).List(ctx, options)
}

// GetNodes returns list of nodes
// GetNodes returns list of nodes.
func (c *Client) GetNodes(ctx context.Context) (*corev1.NodeList, error) {
return c.clientset.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
}

// GetLogs returns logs for pod
// GetLogs returns logs for pod.
func (c *Client) GetLogs(ctx context.Context, pod, container string) (string, error) {
defaultLogLines := int64(3000)
options := &corev1.PodLogOptions{}
Expand Down Expand Up @@ -671,7 +671,7 @@ func translateTimestampSince(timestamp metav1.Time) string {
}

// ApplyFile accepts manifest file contents, parses into []runtime.Object
// and applies them against the cluster
// and applies them against the cluster.
func (c *Client) ApplyFile(fileBytes []byte) error {
objs, err := c.getObjects(fileBytes)
if err != nil {
Expand Down
26 changes: 13 additions & 13 deletions managed/services/dbaas/kubernetes/client/kubeclient_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading