Skip to content
Open
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linters:
- godox # we sometimes leave TODOS right in the code
- gomoddirectives # we use replace directives
- gomodguard # deprecated
- mnd # too annoying
- nlreturn # too annoying
- paralleltest
- protogetter # we need direct access to proto fields
Expand Down
11 changes: 4 additions & 7 deletions agent/agentlocal/agent_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,12 @@ func (s *Server) Run(ctx context.Context, reloadCh chan bool) {
// l is closed by runGRPCServer

var wg sync.WaitGroup
wg.Add(2) //nolint:mnd
go func() {
defer wg.Done()
wg.Go(func() {
s.runGRPCServer(serverCtx, l)
}()
go func() {
defer wg.Done()
})
wg.Go(func() {
Comment thread
maxkondr marked this conversation as resolved.
Comment thread
maxkondr marked this conversation as resolved.
s.runJSONServer(serverCtx, l.Addr().String())
}()
})

select {
case <-s.reload:
Expand Down
2 changes: 1 addition & 1 deletion agent/agents/mongodb/mongolog/internal/mongolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (l *Mongolog) Start(ctx context.Context) error {
// start a goroutine and Add() it to WaitGroup
// so we could later Wait() for it to finish
l.wg = &sync.WaitGroup{}
l.wg.Add(2) //nolint:mnd
l.wg.Add(2)

// create ready sync.Cond so we could know when goroutine actually started getting data from db
ready := sync.NewCond(&sync.Mutex{})
Expand Down
4 changes: 2 additions & 2 deletions agent/agents/mongodb/realtimeanalytics/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (m *MongoDBRTA) collectCurrentOps(ctx context.Context) ([]*rtav1.QueryData,

// Buffered channel to store results from goroutines(parsers)
// and avoid blocking when sending results to the channel.
resultsChan := make(chan *rtav1.QueryData, 10) //nolint:mnd
resultsChan := make(chan *rtav1.QueryData, 10)

for cur.Next(ctx) {
// check if the context is done to avoid unnecessary processing
Expand Down Expand Up @@ -295,7 +295,7 @@ func buildCurrentOpsPipeline() mongo.Pipeline {
// Get operations/commands that are active.
bson.D{{Key: "active", Value: true}},
// Get operations/commands that have execution duration => 0.01s.
bson.D{{Key: "microsecs_running", Value: bson.D{{Key: "$gte", Value: 10_000}}}}, //nolint:mnd
bson.D{{Key: "microsecs_running", Value: bson.D{{Key: "$gte", Value: 10_000}}}},
// Exclude operations from internal MongoDB tools.
bson.D{{Key: "desc", Value: bson.D{{Key: "$nin", Value: bson.A{"Checkpointer", "JournalFlusher"}}}}},
// Exclude operations from RTA agent itself.
Expand Down
2 changes: 1 addition & 1 deletion agent/agents/mongodb/realtimeanalytics/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func parseGenericFields(raw bson.Raw, q *rtav1.QueryData) {
d := time.Duration(usRunning) * time.Microsecond
// Round duration to 0.01s to avoid too much precision,
// because it doesn't make sense to have microsecond precision in query execution time.
q.QueryExecutionDuration = durationpb.New(d.Round(10 * time.Millisecond)) //nolint:mnd
q.QueryExecutionDuration = durationpb.New(d.Round(10 * time.Millisecond))
}

q.ClientAddress, _ = raw.Lookup("client").StringValueOK()
Expand Down
2 changes: 1 addition & 1 deletion agent/agents/postgres/pgstatmonitor/pgstatmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func getPGVersion(q *reform.Querier) (pgVersion, error) {
return pgVersion(parsed), err
}

//nolint:mnd,cyclop
//nolint:cyclop
func getPGMonitorVersion(q *reform.Querier) (pgStatMonitorVersion, pgStatMonitorPrerelease, error) {
Comment thread
Copilot marked this conversation as resolved.
var result string
err := q.QueryRow(fmt.Sprintf("SELECT /* %s */ pg_stat_monitor_version()", queryTag)).Scan(&result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (v *pgStatMonitorAllViewType) NewStruct() reform.Struct { //nolint:ireturn

// String returns a string representation of this struct or record.
func (s pgStatMonitor) String() string {
res := make([]string, 54) //nolint:mnd
res := make([]string, 54)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is 54 here? Don't we want to know?

res[0] = "Bucket: " + reform.Inspect(s.Bucket, true)
res[1] = "BucketStartTime: " + reform.Inspect(s.BucketStartTime, true)
res[2] = "UserID: " + reform.Inspect(s.UserID, true)
Expand Down
2 changes: 1 addition & 1 deletion agent/client/channel/rta_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *RTAChannel) Send(msg *rtav1.CollectRequest) {
// Do not waste resources in case debug level is not enabled.
if c.l.Logger.IsLevelEnabled(logrus.DebugLevel) {
// do not use default compact representation for large/complex messages
if size := proto.Size(msg); size < 100 { //nolint:mnd
if size := proto.Size(msg); size < 100 {
c.l.Debugf("Sending message (%d bytes): %s.", size, msg)
} else {
c.l.Debugf("Sending message (%d bytes):\n%s\n", size, prototext.Format(msg))
Expand Down
2 changes: 1 addition & 1 deletion agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func SaveToFile(path string, cfg *Config, comment string) error {
}
}

return os.WriteFile(path, res, 0o640) //nolint:gosec,mnd
return os.WriteFile(path, res, 0o640) //nolint:gosec
}

// IsWritable checks if specified path is writable.
Expand Down
4 changes: 2 additions & 2 deletions agent/utils/templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (tr *TemplateRenderer) RenderFiles(templateParams map[string]any) (map[stri
if err != nil {
return nil, err
}
err = os.MkdirAll(tr.TempDir, 0o700) //nolint:mnd
err = os.MkdirAll(tr.TempDir, 0o700)
if err != nil {
return nil, err
}
Expand All @@ -93,7 +93,7 @@ func (tr *TemplateRenderer) RenderFiles(templateParams map[string]any) (map[stri
}

path := filepath.Join(tr.TempDir, name)
err = os.WriteFile(path, b, 0o600) //nolint:mnd
err = os.WriteFile(path, b, 0o600)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions managed/models/agent_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func FindDBConfigForService(q *reform.Querier, serviceID string) (*DBConfig, err
default:
return nil, status.Error(codes.FailedPrecondition, "Unsupported service.")
}
p := strings.Join(q.Placeholders(2, len(agentTypes)), ", ") //nolint:mnd
p := strings.Join(q.Placeholders(2, len(agentTypes)), ", ")
tail := fmt.Sprintf("WHERE service_id = $1 AND agent_type IN (%s) ORDER BY agent_id", p)

args := make([]any, len(agentTypes)+1)
Expand Down Expand Up @@ -985,7 +985,7 @@ func CreateAgent(q *reform.Querier, agentType AgentType, params *CreateAgentPara
case RTAMongoDBAgentType:
row.RTAOptions = RTAOptions{
// default value
CollectInterval: new(2 * time.Second), //nolint:mnd
CollectInterval: new(2 * time.Second),
}
// RTA options
row.RTAOptions.Merge(&params.RTAOptions)
Expand Down
6 changes: 3 additions & 3 deletions managed/models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,8 @@ func OpenDB(params SetupDBParams) (*sql.DB, error) {
}

db.SetConnMaxLifetime(0)
db.SetMaxIdleConns(5) //nolint:mnd
db.SetMaxOpenConns(10) //nolint:mnd
db.SetMaxIdleConns(5)
db.SetMaxOpenConns(10)

return db, nil
}
Expand Down Expand Up @@ -1704,7 +1704,7 @@ func setupPMMServerAgents(q *reform.Querier, params SetupDBParams) error {
// parsePGAddress parses PostgreSQL address into address:port; if no port specified returns default port number.
func parsePGAddress(address string) (string, uint16, error) {
if !strings.Contains(address, ":") {
return address, 5432, nil //nolint:mnd
return address, 5432, nil
}
address, portStr, err := net.SplitHostPort(address)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion managed/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (

// MergeLabels merges unified labels of Node, Service, and Agent (each can be nil).
func MergeLabels(node *Node, service *Service, agent *Agent) (map[string]string, error) {
res := make(map[string]string, 16) //nolint:mnd
res := make(map[string]string, 16)

if node != nil {
labels, err := node.UnifiedLabels()
Expand Down
2 changes: 1 addition & 1 deletion managed/models/postgresql_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetPostgreSQLVersion(ctx context.Context, q reform.DBTXContext) (PostgreSQL
}

text := postgresDBRegexp.FindStringSubmatch(version)
if len(text) < 2 { //nolint:mnd
if len(text) < 2 {
return PostgreSQLVersion{}, errors.New("postgresql version not found")
}

Expand Down
14 changes: 7 additions & 7 deletions managed/models/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,32 +203,32 @@ func (s *Settings) fillDefaults() {
// no default for Telemetry UUID - it set by telemetry service

if s.MetricsResolutions.HR == 0 {
s.MetricsResolutions.HR = 5 * time.Second //nolint:mnd
s.MetricsResolutions.HR = 5 * time.Second
}
if s.MetricsResolutions.MR == 0 {
s.MetricsResolutions.MR = 10 * time.Second //nolint:mnd
s.MetricsResolutions.MR = 10 * time.Second
}
if s.MetricsResolutions.LR == 0 {
s.MetricsResolutions.LR = 60 * time.Second //nolint:mnd
s.MetricsResolutions.LR = 60 * time.Second
}

if s.DataRetention == 0 {
s.DataRetention = 30 * 24 * time.Hour //nolint:mnd
s.DataRetention = 30 * 24 * time.Hour
}

if len(s.AWSPartitions) == 0 {
s.AWSPartitions = []string{awsPartitionID}
}

if s.SaaS.AdvisorRunIntervals.RareInterval == 0 {
s.SaaS.AdvisorRunIntervals.RareInterval = 78 * time.Hour //nolint:mnd
s.SaaS.AdvisorRunIntervals.RareInterval = 78 * time.Hour
}

if s.SaaS.AdvisorRunIntervals.StandardInterval == 0 {
s.SaaS.AdvisorRunIntervals.StandardInterval = 24 * time.Hour //nolint:mnd
s.SaaS.AdvisorRunIntervals.StandardInterval = 24 * time.Hour
}

if s.SaaS.AdvisorRunIntervals.FrequentInterval == 0 {
s.SaaS.AdvisorRunIntervals.FrequentInterval = 4 * time.Hour //nolint:mnd
s.SaaS.AdvisorRunIntervals.FrequentInterval = 4 * time.Hour
}
}
2 changes: 1 addition & 1 deletion managed/pi/alert/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (p *Parameter) validateRange() error {
return nil

case Float:
if len(p.Range) != 2 { //nolint:mnd
if len(p.Range) != 2 {
return fmt.Errorf("range should be empty or have two elements, but it has %d elements", len(p.Range))
}

Expand Down
10 changes: 5 additions & 5 deletions managed/pi/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var nameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)
// Verify checks signature of passed data with provided public key and
// returns error in case of any problem.
func Verify(data []byte, publicKey, sig string) error {
lines := strings.SplitN(sig, "\n", 4) //nolint:mnd
if len(lines) < 4 { //nolint:mnd
lines := strings.SplitN(sig, "\n", 4)
if len(lines) < 4 {
return errors.New("incomplete signature")
}

Expand Down Expand Up @@ -71,7 +71,7 @@ func Verify(data []byte, publicKey, sig string) error {
}

// For pre-hashed signature get data hash.
if sAlg[1] == 0x44 { //nolint:mnd
if sAlg[1] == 0x44 {
h, _ := blake2b.New512(nil)
h.Write(data)
data = h.Sum(nil)
Expand Down Expand Up @@ -298,7 +298,7 @@ func (c *Check) GetFamily() Family {
case MetricsInstant, MetricsRange, ClickHouseSelect:
return "" // Unsupported query types for V1, check is invalid
}
case 2: //nolint:mnd
case 2:
return c.Family
}

Expand Down Expand Up @@ -342,7 +342,7 @@ func (c *Check) Validate() error {
switch c.Version {
case 1:
return c.validateV1()
case 2: //nolint:mnd
case 2:
return c.validateV2()
default:
return fmt.Errorf("unexpected version %d", c.Version)
Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func getArgs(exporter *models.Agent, tdp *models.DelimiterPair, listenAddress st
}
}

collstatsLimit := int32(200) //nolint:mnd // default limit
collstatsLimit := int32(200) // default limit
if exporter.MongoDBOptions.CollectionsLimit != -1 {
collstatsLimit = exporter.MongoDBOptions.CollectionsLimit
}
Expand Down
6 changes: 3 additions & 3 deletions managed/services/agents/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ func NewRegistry(db *reform.DB, vmParams victoriaMetricsParams, ha haService) *R
Subsystem: prometheusSubsystem,
Name: "round_trip_seconds",
Help: "Round-trip time.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, //nolint:mnd
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
}),
mClockDrift: prom.NewSummary(prom.SummaryOpts{
Namespace: prometheusNamespace,
Subsystem: prometheusSubsystem,
Name: "clock_drift_seconds",
Help: "Clock drift.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, //nolint:mnd
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
}),

isExternalVM: vmParams.ExternalVM(),
Expand Down Expand Up @@ -432,7 +432,7 @@ func (r *Registry) ping(ctx context.Context, agent *pmmAgentInfo) error {
}
roundtrip := time.Since(start)
agentTime := resp.(*agentv1.Pong).CurrentTime.AsTime() //nolint:forcetypeassert
clockDrift := agentTime.Sub(start) - roundtrip/2 //nolint:mnd
clockDrift := agentTime.Sub(start) - roundtrip/2
if clockDrift < 0 {
clockDrift = -clockDrift
}
Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (u *StateUpdater) UpdateAgentsState(ctx context.Context) error {
return fmt.Errorf("cannot find pmmAgentsIDs for AgentsState update: %w", err)
}
var wg sync.WaitGroup
limiter := make(chan struct{}, 10) //nolint:mnd
limiter := make(chan struct{}, 10)
for _, pmmAgentID := range pmmAgents {
wg.Add(1)
limiter <- struct{}{}
Expand Down
2 changes: 1 addition & 1 deletion managed/services/alerting/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func (s *Service) CreateRule(ctx context.Context, req *alerting.CreateRuleReques
RefID: "A",
DatasourceUID: metricsDatasourceUID,
// TODO: https://community.grafana.com/t/grafana-requires-time-range-for-alert-rule-creation-with-instant-promql-quieriy/70919
RelativeTimeRange: services.RelativeTimeRange{From: 600, To: 0}, //nolint:mnd
RelativeTimeRange: services.RelativeTimeRange{From: 600, To: 0},
Model: services.Model{
Expr: expr,
RefID: "A",
Expand Down
2 changes: 1 addition & 1 deletion managed/services/ha/haservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (w *memberlistLogWriter) Write(p []byte) (int, error) {

// Parse memberlist log format: "2025/12/22 21:43:27 [DEBUG|INFO|WARN|ERR] message"
matches := w.logRegex.FindStringSubmatch(msg)
if len(matches) == 3 { //nolint:mnd
if len(matches) == 3 {
level := strings.ToLower(matches[1])
message := matches[2]

Expand Down
2 changes: 1 addition & 1 deletion managed/services/nomad/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Nomad struct {

// New creates a new Nomad client.
func New(db *reform.DB, clientConfig *models.NomadClient) (*Nomad, error) {
err := os.MkdirAll(pathToCerts, 0o750) //nolint:mnd
err := os.MkdirAll(pathToCerts, 0o750)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion managed/services/realtimeanalytics/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ func (s *Service) Collect(stream grpc.ClientStreamingServer[rtav1.CollectRequest

if l.Logger.IsLevelEnabled(logrus.DebugLevel) {
// do not use default compact representation for large/complex messages
if size := proto.Size(msg); size < 100 { //nolint:mnd
if size := proto.Size(msg); size < 100 {
l.Debugf("Received message (%d bytes): %s.", size, msg)
} else {
l.Debugf("Received message (%d bytes):\n%s\n", proto.Size(msg), prototext.Format(msg))
Expand Down
2 changes: 1 addition & 1 deletion managed/services/realtimeanalytics/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *Store) getShard(serviceID string) *shard {
// Uses prime multiplier (31) for good distribution
hash := uint32(0)
for i := range len(serviceID) {
hash = hash*31 + uint32(serviceID[i]) //nolint:mnd
hash = hash*31 + uint32(serviceID[i])
}

return s.shards[hash%numShards]
Expand Down
8 changes: 4 additions & 4 deletions managed/services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ func (s *Server) CheckUpdates(ctx context.Context, req *serverv1.CheckUpdatesReq

if v.Installed.BuildTime != nil {
// return only date
t := v.Installed.BuildTime.UTC().Truncate(24 * time.Hour) //nolint:mnd
t := v.Installed.BuildTime.UTC().Truncate(24 * time.Hour)
res.Installed.Timestamp = timestamppb.New(t)
}

if v.Latest.DockerImage != "" {
// return only date
t := v.Latest.BuildTime.UTC().Truncate(24 * time.Hour) //nolint:mnd
t := v.Latest.BuildTime.UTC().Truncate(24 * time.Hour)
res.Latest.Timestamp = timestamppb.New(t)
}

Expand Down Expand Up @@ -708,13 +708,13 @@ func (s *Server) writeSSHKey(sshKey string) error {
return fmt.Errorf("failed to lookup OS user %s: %w", username, err)
}
sshDirPath := path.Join(usr.HomeDir, ".ssh")
err = os.MkdirAll(sshDirPath, 0o700) //nolint:mnd
err = os.MkdirAll(sshDirPath, 0o700)
if err != nil {
return fmt.Errorf("failed to create SSH dir %s: %w", sshDirPath, err)
}

keysPath := path.Join(sshDirPath, "authorized_keys")
err = os.WriteFile(keysPath, []byte(sshKey), 0o600) //nolint:mnd
err = os.WriteFile(keysPath, []byte(sshKey), 0o600)
if err != nil {
return fmt.Errorf("failed to write SSH keys to %s: %w", keysPath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions managed/services/supervisord/maintail.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ type event struct {

// parseEvent returns parsed event from supervisord maintail line, or nil.
func parseEvent(line string) *event {
parts := strings.SplitN(line, " ", 4) //nolint:mnd
if len(parts) != 4 { //nolint:mnd
parts := strings.SplitN(line, " ", 4)
if len(parts) != 4 {
return nil
}

Expand Down
Loading
Loading