From e10eca4c3b0615b1b03e6a15e19702e6bed75d6d Mon Sep 17 00:00:00 2001 From: Friedrich Gonzalez Date: Mon, 25 Mar 2024 14:02:09 +0100 Subject: [PATCH] Fix linting Signed-off-by: Friedrich Gonzalez --- cmd/e2ealerting/main.go | 3 ++- cmd/logtool/main.go | 12 ++++++------ pkg/alerting/runner.go | 5 +++-- pkg/analyse/ruler.go | 3 ++- pkg/bench/query_runner.go | 4 ++-- pkg/bench/write_client.go | 2 +- pkg/chunk/cassandra/storage_client.go | 2 +- pkg/chunk/migrate/writer/writer.go | 2 +- pkg/client/alerts.go | 6 +++--- pkg/client/client.go | 2 +- pkg/client/rules.go | 10 +++++----- pkg/commands/access_control.go | 2 +- pkg/commands/alerts.go | 12 ++++++------ pkg/commands/analyse_dashboards.go | 2 +- pkg/commands/analyse_grafana.go | 8 ++------ pkg/commands/analyse_prometheus.go | 8 ++------ pkg/commands/analyse_rulefiles.go | 2 +- pkg/commands/analyse_ruler.go | 8 ++------ pkg/commands/analyse_rules_test.go | 5 +++-- pkg/commands/block_gen.go | 5 +++-- pkg/commands/bucket_validation.go | 4 ++-- pkg/commands/chunks.go | 8 ++++---- pkg/commands/loadgen.go | 2 +- pkg/commands/logger.go | 2 +- pkg/commands/migrate.go | 2 +- pkg/commands/overrides_exporter.go | 2 +- pkg/commands/push_gateway.go | 2 +- pkg/commands/remote_read.go | 6 +++--- pkg/commands/rules.go | 26 +++++++++++++------------- pkg/commands/rules_test.go | 3 ++- pkg/rules/compare_test.go | 3 ++- pkg/rules/rules.go | 2 +- 32 files changed, 80 insertions(+), 85 deletions(-) diff --git a/cmd/e2ealerting/main.go b/cmd/e2ealerting/main.go index d6804706d..32ed77204 100644 --- a/cmd/e2ealerting/main.go +++ b/cmd/e2ealerting/main.go @@ -4,9 +4,10 @@ import ( "flag" "os" - "github.com/cortexproject/cortex-tools/pkg/alerting" "github.com/go-kit/log/level" + "github.com/cortexproject/cortex-tools/pkg/alerting" + "github.com/cortexproject/cortex/pkg/util/flagext" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/client_golang/prometheus" diff --git a/cmd/logtool/main.go b/cmd/logtool/main.go index df0b77306..d64e77d70 100644 --- a/cmd/logtool/main.go +++ b/cmd/logtool/main.go @@ -45,7 +45,7 @@ func main() { for scanner.Scan() { show := false var qt time.Time - var dur, len time.Duration + var dur, length time.Duration var status, path, query, trace string var err error @@ -99,13 +99,13 @@ func main() { fmt.Println(err, line) continue } - len = et.Sub(st) + length = et.Sub(st) } else { // Loki queries are nanosecond, simple check to see if it's a second or nanosecond timestamp if st > 9999999999 { - len = time.Unix(0, et).Sub(time.Unix(0, st)) + length = time.Unix(0, et).Sub(time.Unix(0, st)) } else { - len = time.Unix(et, 0).Sub(time.Unix(st, 0)) + length = time.Unix(et, 0).Sub(time.Unix(st, 0)) } } @@ -132,9 +132,9 @@ func main() { ts = fmt.Sprint(qt.Local()) } if *showQuery { - fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\n", ts, trace, len, dur, status, path, query) + fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\n", ts, trace, length, dur, status, path, query) } else { - fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\n", ts, trace, len, dur, status, path) + fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\n", ts, trace, length, dur, status, path) } //If looking at stdin, flush after every line as someone would only paste one line at a time at the terminal if !isPipe { diff --git a/pkg/alerting/runner.go b/pkg/alerting/runner.go index b96a3c9d0..3586894b2 100644 --- a/pkg/alerting/runner.go +++ b/pkg/alerting/runner.go @@ -9,12 +9,13 @@ import ( "sync" "time" - "github.com/cortexproject/cortex-tools/pkg/client" - "github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" yaml "gopkg.in/yaml.v3" + + "github.com/cortexproject/cortex-tools/pkg/client" + "github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt" ) // Case represents a metric that can be used for exporting, then verified against an Alertmanager webhook diff --git a/pkg/analyse/ruler.go b/pkg/analyse/ruler.go index 999391f5b..9fe3d192a 100644 --- a/pkg/analyse/ruler.go +++ b/pkg/analyse/ruler.go @@ -3,10 +3,11 @@ package analyse import ( "sort" - "github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt" "github.com/pkg/errors" "github.com/prometheus/prometheus/promql/parser" log "github.com/sirupsen/logrus" + + "github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt" ) type MetricsInRuler struct { diff --git a/pkg/bench/query_runner.go b/pkg/bench/query_runner.go index 792b817c5..362e1a81c 100644 --- a/pkg/bench/query_runner.go +++ b/pkg/bench/query_runner.go @@ -204,8 +204,8 @@ func (q *queryRunner) executeQuery(ctx context.Context, queryReq query) error { now := time.Now() var ( - queryType string = "instant" - status string = "success" + queryType = "instant" + status = "success" ) if queryReq.timeRange > 0 { queryType = "range" diff --git a/pkg/bench/write_client.go b/pkg/bench/write_client.go index eb98f0e3d..770e67ad7 100644 --- a/pkg/bench/write_client.go +++ b/pkg/bench/write_client.go @@ -39,7 +39,7 @@ type writeClient struct { } // newWriteClient creates a new client for remote write. -func newWriteClient(name string, tenantName string, conf *remote.ClientConfig, logger log.Logger, requestHistogram *prometheus.HistogramVec) (*writeClient, error) { +func newWriteClient(name string, tenantName string, conf *remote.ClientConfig, _ log.Logger, requestHistogram *prometheus.HistogramVec) (*writeClient, error) { httpClient, err := config_util.NewClientFromConfig(conf.HTTPClientConfig, "bench_write_client", config_util.WithHTTP2Disabled()) if err != nil { return nil, err diff --git a/pkg/chunk/cassandra/storage_client.go b/pkg/chunk/cassandra/storage_client.go index 64aaf828e..2b770443a 100644 --- a/pkg/chunk/cassandra/storage_client.go +++ b/pkg/chunk/cassandra/storage_client.go @@ -196,4 +196,4 @@ func (noopConvictionPolicy) AddFailure(err error, host *gocql.HostInfo) bool { } // Implementats gocql.ConvictionPolicy. -func (noopConvictionPolicy) Reset(host *gocql.HostInfo) {} +func (noopConvictionPolicy) Reset(_ *gocql.HostInfo) {} diff --git a/pkg/chunk/migrate/writer/writer.go b/pkg/chunk/migrate/writer/writer.go index bbe23b798..604f3fba3 100644 --- a/pkg/chunk/migrate/writer/writer.go +++ b/pkg/chunk/migrate/writer/writer.go @@ -91,7 +91,7 @@ func (w *Writer) Run(ctx context.Context, inChan chan chunk.Chunk) { } } -func (w *Writer) writeLoop(ctx context.Context, workerID int, inChan chan chunk.Chunk, errChan chan error) { +func (w *Writer) writeLoop(ctx context.Context, _ int, inChan chan chunk.Chunk, errChan chan error) { defer w.workerGroup.Done() for { diff --git a/pkg/client/alerts.go b/pkg/client/alerts.go index 61e4f41e0..c9cc2f868 100644 --- a/pkg/client/alerts.go +++ b/pkg/client/alerts.go @@ -17,7 +17,7 @@ type configCompat struct { } // CreateAlertmanagerConfig creates a new alertmanager config -func (r *CortexClient) CreateAlertmanagerConfig(ctx context.Context, cfg string, templates map[string]string) error { +func (r *CortexClient) CreateAlertmanagerConfig(_ context.Context, cfg string, templates map[string]string) error { payload, err := yaml.Marshal(&configCompat{ TemplateFiles: templates, AlertmanagerConfig: cfg, @@ -37,7 +37,7 @@ func (r *CortexClient) CreateAlertmanagerConfig(ctx context.Context, cfg string, } // DeleteAlermanagerConfig deletes the users alertmanagerconfig -func (r *CortexClient) DeleteAlermanagerConfig(ctx context.Context) error { +func (r *CortexClient) DeleteAlermanagerConfig(_ context.Context) error { res, err := r.doRequest(alertmanagerAPIPath, "DELETE", nil) if err != nil { return err @@ -49,7 +49,7 @@ func (r *CortexClient) DeleteAlermanagerConfig(ctx context.Context) error { } // GetAlertmanagerConfig retrieves a rule group -func (r *CortexClient) GetAlertmanagerConfig(ctx context.Context) (string, map[string]string, error) { +func (r *CortexClient) GetAlertmanagerConfig(_ context.Context) (string, map[string]string, error) { res, err := r.doRequest(alertmanagerAPIPath, "GET", nil) if err != nil { log.Debugln("no alert config present in response") diff --git a/pkg/client/client.go b/pkg/client/client.go index fb055d377..e78925a41 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -102,7 +102,7 @@ func New(cfg Config) (*CortexClient, error) { } // Query executes a PromQL query against the Cortex cluster. -func (r *CortexClient) Query(ctx context.Context, query string) (*http.Response, error) { +func (r *CortexClient) Query(_ context.Context, query string) (*http.Response, error) { query = fmt.Sprintf("query=%s&time=%d", query, time.Now().Unix()) escapedQuery := url.PathEscape(query) diff --git a/pkg/client/rules.go b/pkg/client/rules.go index 52c1dc3d2..a41775f01 100644 --- a/pkg/client/rules.go +++ b/pkg/client/rules.go @@ -14,7 +14,7 @@ import ( ) // CreateRuleGroup creates a new rule group -func (r *CortexClient) CreateRuleGroup(ctx context.Context, namespace string, rg rwrulefmt.RuleGroup) error { +func (r *CortexClient) CreateRuleGroup(_ context.Context, namespace string, rg rwrulefmt.RuleGroup) error { payload, err := yaml.Marshal(&rg) if err != nil { return err @@ -34,7 +34,7 @@ func (r *CortexClient) CreateRuleGroup(ctx context.Context, namespace string, rg } // DeleteRuleGroup deletes a rule group -func (r *CortexClient) DeleteRuleGroup(ctx context.Context, namespace, groupName string) error { +func (r *CortexClient) DeleteRuleGroup(_ context.Context, namespace, groupName string) error { escapedNamespace := url.PathEscape(namespace) escapedGroupName := url.PathEscape(groupName) path := r.apiPath + "/" + escapedNamespace + "/" + escapedGroupName @@ -50,7 +50,7 @@ func (r *CortexClient) DeleteRuleGroup(ctx context.Context, namespace, groupName } // DeleteRuleNamespace deletes a rule namespace -func (r *CortexClient) DeleteRuleNamespace(ctx context.Context, namespace string) error { +func (r *CortexClient) DeleteRuleNamespace(_ context.Context, namespace string) error { escapedNamespace := url.PathEscape(namespace) path := r.apiPath + "/" + escapedNamespace @@ -65,7 +65,7 @@ func (r *CortexClient) DeleteRuleNamespace(ctx context.Context, namespace string } // GetRuleGroup retrieves a rule group -func (r *CortexClient) GetRuleGroup(ctx context.Context, namespace, groupName string) (*rwrulefmt.RuleGroup, error) { +func (r *CortexClient) GetRuleGroup(_ context.Context, namespace, groupName string) (*rwrulefmt.RuleGroup, error) { escapedNamespace := url.PathEscape(namespace) escapedGroupName := url.PathEscape(groupName) path := r.apiPath + "/" + escapedNamespace + "/" + escapedGroupName @@ -97,7 +97,7 @@ func (r *CortexClient) GetRuleGroup(ctx context.Context, namespace, groupName st } // ListRules retrieves a rule group -func (r *CortexClient) ListRules(ctx context.Context, namespace string) (map[string][]rwrulefmt.RuleGroup, error) { +func (r *CortexClient) ListRules(_ context.Context, namespace string) (map[string][]rwrulefmt.RuleGroup, error) { path := r.apiPath if namespace != "" { path = path + "/" + namespace diff --git a/pkg/commands/access_control.go b/pkg/commands/access_control.go index 0c2c73fee..52dd71ea6 100644 --- a/pkg/commands/access_control.go +++ b/pkg/commands/access_control.go @@ -25,7 +25,7 @@ func (a *AccessControlCommand) Register(app *kingpin.Application) { generateHeaderCmd.Flag("rule", "The access control rules (Prometheus selectors). Set it multiple times to set multiple rules.").Required().StringsVar(&a.ACLs) } -func (a *AccessControlCommand) generateHeader(k *kingpin.ParseContext) error { +func (a *AccessControlCommand) generateHeader(_ *kingpin.ParseContext) error { for _, acl := range a.ACLs { _, err := parser.ParseMetricSelector(acl) if err != nil { diff --git a/pkg/commands/alerts.go b/pkg/commands/alerts.go index 61e37665c..6c69c0dbe 100644 --- a/pkg/commands/alerts.go +++ b/pkg/commands/alerts.go @@ -83,7 +83,7 @@ func (a *AlertmanagerCommand) Register(app *kingpin.Application) { loadalertCmd.Arg("template-files", "The template files to load").ExistingFilesVar(&a.TemplateFiles) } -func (a *AlertmanagerCommand) setup(k *kingpin.ParseContext) error { +func (a *AlertmanagerCommand) setup(_ *kingpin.ParseContext) error { cli, err := client.New(a.ClientConfig) if err != nil { return err @@ -93,7 +93,7 @@ func (a *AlertmanagerCommand) setup(k *kingpin.ParseContext) error { return nil } -func (a *AlertmanagerCommand) getConfig(k *kingpin.ParseContext) error { +func (a *AlertmanagerCommand) getConfig(_ *kingpin.ParseContext) error { cfg, templates, err := a.cli.GetAlertmanagerConfig(context.Background()) if err != nil { if err == client.ErrResourceNotFound { @@ -108,7 +108,7 @@ func (a *AlertmanagerCommand) getConfig(k *kingpin.ParseContext) error { return p.PrintAlertmanagerConfig(cfg, templates) } -func (a *AlertmanagerCommand) loadConfig(k *kingpin.ParseContext) error { +func (a *AlertmanagerCommand) loadConfig(_ *kingpin.ParseContext) error { content, err := ioutil.ReadFile(a.AlertmanagerConfigFile) if err != nil { return errors.Wrap(err, "unable to load config file: "+a.AlertmanagerConfigFile) @@ -132,7 +132,7 @@ func (a *AlertmanagerCommand) loadConfig(k *kingpin.ParseContext) error { return a.cli.CreateAlertmanagerConfig(context.Background(), cfg, templates) } -func (a *AlertmanagerCommand) deleteConfig(k *kingpin.ParseContext) error { +func (a *AlertmanagerCommand) deleteConfig(_ *kingpin.ParseContext) error { err := a.cli.DeleteAlermanagerConfig(context.Background()) if err != nil && err != client.ErrResourceNotFound { return err @@ -155,7 +155,7 @@ func (a *AlertCommand) Register(app *kingpin.Application) { verifyAlertsCmd.Flag("frequency", "Setting this value will turn cortextool into a long-running process, running the alerts verify check every # of minutes specified").IntVar(&a.CheckFrequency) } -func (a *AlertCommand) setup(k *kingpin.ParseContext) error { +func (a *AlertCommand) setup(_ *kingpin.ParseContext) error { cli, err := client.New(a.ClientConfig) if err != nil { return err @@ -179,7 +179,7 @@ type metric struct { Metric map[string]string `json:"metric"` } -func (a *AlertCommand) verifyConfig(k *kingpin.ParseContext) error { +func (a *AlertCommand) verifyConfig(_ *kingpin.ParseContext) error { var empty interface{} if a.IgnoreString != "" { a.IgnoreAlerts = make(map[string]interface{}) diff --git a/pkg/commands/analyse_dashboards.go b/pkg/commands/analyse_dashboards.go index 491f5176e..c99bb2e4e 100644 --- a/pkg/commands/analyse_dashboards.go +++ b/pkg/commands/analyse_dashboards.go @@ -16,7 +16,7 @@ type DashboardAnalyseCommand struct { outputFile string } -func (cmd *DashboardAnalyseCommand) run(k *kingpin.ParseContext) error { +func (cmd *DashboardAnalyseCommand) run(_ *kingpin.ParseContext) error { output := &analyse.MetricsInGrafana{} output.OverallMetrics = make(map[string]struct{}) diff --git a/pkg/commands/analyse_grafana.go b/pkg/commands/analyse_grafana.go index 90cbfd5c6..26d2b7332 100644 --- a/pkg/commands/analyse_grafana.go +++ b/pkg/commands/analyse_grafana.go @@ -23,7 +23,7 @@ type GrafanaAnalyseCommand struct { outputFile string } -func (cmd *GrafanaAnalyseCommand) run(k *kingpin.ParseContext) error { +func (cmd *GrafanaAnalyseCommand) run(_ *kingpin.ParseContext) error { output := &analyse.MetricsInGrafana{} output.OverallMetrics = make(map[string]struct{}) @@ -70,9 +70,5 @@ func writeOut(mig *analyse.MetricsInGrafana, outputFile string) error { return err } - if err := ioutil.WriteFile(outputFile, out, os.FileMode(int(0666))); err != nil { - return err - } - - return nil + return ioutil.WriteFile(outputFile, out, os.FileMode(int(0666))) } diff --git a/pkg/commands/analyse_prometheus.go b/pkg/commands/analyse_prometheus.go index b2e32d12e..b5fa42ca6 100644 --- a/pkg/commands/analyse_prometheus.go +++ b/pkg/commands/analyse_prometheus.go @@ -31,7 +31,7 @@ type PrometheusAnalyseCommand struct { outputFile string } -func (cmd *PrometheusAnalyseCommand) run(k *kingpin.ParseContext) error { +func (cmd *PrometheusAnalyseCommand) run(_ *kingpin.ParseContext) error { var ( hasGrafanaMetrics, hasRulerMetrics = false, false grafanaMetrics = analyse.MetricsInGrafana{} @@ -228,9 +228,5 @@ func (cmd *PrometheusAnalyseCommand) run(k *kingpin.ParseContext) error { return err } - if err := ioutil.WriteFile(cmd.outputFile, out, os.FileMode(int(0666))); err != nil { - return err - } - - return nil + return ioutil.WriteFile(cmd.outputFile, out, os.FileMode(int(0666))) } diff --git a/pkg/commands/analyse_rulefiles.go b/pkg/commands/analyse_rulefiles.go index 19b12410a..5e9551d91 100644 --- a/pkg/commands/analyse_rulefiles.go +++ b/pkg/commands/analyse_rulefiles.go @@ -13,7 +13,7 @@ type RuleFileAnalyseCommand struct { outputFile string } -func (cmd *RuleFileAnalyseCommand) run(k *kingpin.ParseContext) error { +func (cmd *RuleFileAnalyseCommand) run(_ *kingpin.ParseContext) error { output := &analyse.MetricsInRuler{} output.OverallMetrics = make(map[string]struct{}) diff --git a/pkg/commands/analyse_ruler.go b/pkg/commands/analyse_ruler.go index 553ce86a2..59d7a171a 100644 --- a/pkg/commands/analyse_ruler.go +++ b/pkg/commands/analyse_ruler.go @@ -20,7 +20,7 @@ type RulerAnalyseCommand struct { outputFile string } -func (cmd *RulerAnalyseCommand) run(k *kingpin.ParseContext) error { +func (cmd *RulerAnalyseCommand) run(_ *kingpin.ParseContext) error { output := &analyse.MetricsInRuler{} output.OverallMetrics = make(map[string]struct{}) @@ -65,9 +65,5 @@ func writeOutRuleMetrics(mir *analyse.MetricsInRuler, outputFile string) error { return err } - if err := ioutil.WriteFile(outputFile, out, os.FileMode(int(0666))); err != nil { - return err - } - - return nil + return ioutil.WriteFile(outputFile, out, os.FileMode(int(0666))) } diff --git a/pkg/commands/analyse_rules_test.go b/pkg/commands/analyse_rules_test.go index e6bce4a01..4214cf226 100644 --- a/pkg/commands/analyse_rules_test.go +++ b/pkg/commands/analyse_rules_test.go @@ -4,10 +4,11 @@ import ( "sort" "testing" - "github.com/cortexproject/cortex-tools/pkg/analyse" - "github.com/cortexproject/cortex-tools/pkg/rules" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/cortexproject/cortex-tools/pkg/analyse" + "github.com/cortexproject/cortex-tools/pkg/rules" ) var metricsInRuleGroup = []string{ diff --git a/pkg/commands/block_gen.go b/pkg/commands/block_gen.go index c3cc2f45b..613dd27ea 100644 --- a/pkg/commands/block_gen.go +++ b/pkg/commands/block_gen.go @@ -7,7 +7,6 @@ import ( "sort" "time" - "github.com/cortexproject/cortex-tools/pkg/bench" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/pkg/errors" @@ -17,6 +16,8 @@ import ( "github.com/prometheus/prometheus/tsdb" "gopkg.in/alecthomas/kingpin.v2" "gopkg.in/yaml.v3" + + "github.com/cortexproject/cortex-tools/pkg/bench" ) // BlockGenCommand is the kingpin command to generate blocks of mock data. @@ -41,7 +42,7 @@ func (f *BlockGenCommand) Register(app *kingpin.Application) { app.Action(f.run) } -func (f *BlockGenCommand) run(k *kingpin.ParseContext) error { +func (f *BlockGenCommand) run(_ *kingpin.ParseContext) error { logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) content, err := os.ReadFile(f.configFile) diff --git a/pkg/commands/bucket_validation.go b/pkg/commands/bucket_validation.go index 2b08f9f25..2d37fb7d5 100644 --- a/pkg/commands/bucket_validation.go +++ b/pkg/commands/bucket_validation.go @@ -100,7 +100,7 @@ func (b *BucketValidationCommand) Register(app *kingpin.Application) { bvCmd.Flag("bucket-config-help", "Help text explaining how to use the -bucket-config parameter").BoolVar(&b.bucketConfigHelp) } -func (b *BucketValidationCommand) validate(k *kingpin.ParseContext) error { +func (b *BucketValidationCommand) validate(_ *kingpin.ParseContext) error { if b.bucketConfigHelp { b.printBucketConfigHelp() return nil @@ -299,7 +299,7 @@ func (b *BucketValidationCommand) deleteTestObjects(ctx context.Context) error { return errors.Wrapf(err, "failed to list objects") } if foundDeletedDir { - return errors.Errorf("List returned directory which is supposed to be deleted.") + return errors.Errorf("list returned directory which is supposed to be deleted") } expectedDirCount := len(b.objectNames) - iteration if foundDirCount != expectedDirCount { diff --git a/pkg/commands/chunks.go b/pkg/commands/chunks.go index a4daa07b0..8da6aa30e 100644 --- a/pkg/commands/chunks.go +++ b/pkg/commands/chunks.go @@ -181,7 +181,7 @@ func setup(k *kingpin.ParseContext) error { return nil } -func (c *chunkCleanCommandOptions) run(k *kingpin.ParseContext) error { +func (c *chunkCleanCommandOptions) run(_ *kingpin.ParseContext) error { cortexCfg := &cortex.Config{} flagext.RegisterFlags(cortexCfg) err := LoadConfig(c.CortexConfigFile, true, cortexCfg) @@ -342,7 +342,7 @@ func expandEnv(config []byte) []byte { })) } -func (c *deleteChunkCommandOptions) run(k *kingpin.ParseContext) error { +func (c *deleteChunkCommandOptions) run(_ *kingpin.ParseContext) error { err := c.Schema.Load() if err != nil { return errors.Wrap(err, "unable to load schema") @@ -500,7 +500,7 @@ func (c *deleteChunkCommandOptions) run(k *kingpin.ParseContext) error { return nil } -func (c *deleteSeriesCommandOptions) run(k *kingpin.ParseContext) error { +func (c *deleteSeriesCommandOptions) run(_ *kingpin.ParseContext) error { err := c.Schema.Load() if err != nil { return errors.Wrap(err, "unable to load schema") @@ -607,7 +607,7 @@ func (c *deleteSeriesCommandOptions) run(k *kingpin.ParseContext) error { return nil } -func (v *validateIndexCommandOptions) run(k *kingpin.ParseContext) error { +func (v *validateIndexCommandOptions) run(_ *kingpin.ParseContext) error { cortexCfg := &cortex.Config{} flagext.RegisterFlags(cortexCfg) err := LoadConfig(v.CortexConfigFile, true, cortexCfg) diff --git a/pkg/commands/loadgen.go b/pkg/commands/loadgen.go index d46da158f..434bb94b3 100644 --- a/pkg/commands/loadgen.go +++ b/pkg/commands/loadgen.go @@ -100,7 +100,7 @@ func (c *LoadgenCommand) Register(app *kingpin.Application) { Default(":8080").StringVar(&loadgenCommand.metricsListenAddress) } -func (c *LoadgenCommand) run(k *kingpin.ParseContext) error { +func (c *LoadgenCommand) run(_ *kingpin.ParseContext) error { if c.writeURL == "" && c.queryURL == "" { return errors.New("either a -write-url or -query-url flag must be provided to run the loadgen command") } diff --git a/pkg/commands/logger.go b/pkg/commands/logger.go index ab87c6f41..4e28fd9b8 100644 --- a/pkg/commands/logger.go +++ b/pkg/commands/logger.go @@ -11,7 +11,7 @@ type LoggerConfig struct { Level string } -func (l *LoggerConfig) registerLogLevel(pc *kingpin.ParseContext) error { +func (l *LoggerConfig) registerLogLevel(_ *kingpin.ParseContext) error { var logLevel logrus.Level switch l.Level { case "debug": diff --git a/pkg/commands/migrate.go b/pkg/commands/migrate.go index 0060e50a3..b804253d9 100644 --- a/pkg/commands/migrate.go +++ b/pkg/commands/migrate.go @@ -23,7 +23,7 @@ func registerMigrateChunksCommandOptions(cmd *kingpin.CmdClause) { migrateChunksCommandOptions.Planner.Register(migrateChunksCommand) } -func (c *migrateChunksCommandOptions) run(k *kingpin.ParseContext) error { +func (c *migrateChunksCommandOptions) run(_ *kingpin.ParseContext) error { f, err := os.Open(c.ConfigFile) if err != nil { return err diff --git a/pkg/commands/overrides_exporter.go b/pkg/commands/overrides_exporter.go index 8ed5c0ba3..8e52b0c13 100644 --- a/pkg/commands/overrides_exporter.go +++ b/pkg/commands/overrides_exporter.go @@ -138,7 +138,7 @@ func (o *OverridesExporterCommand) updateMetrics(limitsMap map[string]*validatio o.lastLimitsMtx.Unlock() } -func (o *OverridesExporterCommand) run(k *kingpin.ParseContext) error { +func (o *OverridesExporterCommand) run(_ *kingpin.ParseContext) error { if o.overridesFilePath == "" { return errors.New("empty overrides file path") } diff --git a/pkg/commands/push_gateway.go b/pkg/commands/push_gateway.go index 3b77738d7..70886c048 100644 --- a/pkg/commands/push_gateway.go +++ b/pkg/commands/push_gateway.go @@ -29,7 +29,7 @@ func (l *PushGatewayConfig) Register(app *kingpin.Application) { app.Flag("push-gateway.interval", "interval to forward metrics to the push gateway").Default("1m").DurationVar(&l.Interval) } -func (l *PushGatewayConfig) setup(pc *kingpin.ParseContext) error { +func (l *PushGatewayConfig) setup(_ *kingpin.ParseContext) error { if l.Endpoint == nil || l.JobName == "" { logrus.Debugln("push-gateway not configured") return nil diff --git a/pkg/commands/remote_read.go b/pkg/commands/remote_read.go index 9375301a0..5d0828f40 100644 --- a/pkg/commands/remote_read.go +++ b/pkg/commands/remote_read.go @@ -263,7 +263,7 @@ func (c *RemoteReadCommand) prepare() (query func(context.Context) ([]*prompb.Ti }, from, to, nil } -func (c *RemoteReadCommand) dump(k *kingpin.ParseContext) error { +func (c *RemoteReadCommand) dump(_ *kingpin.ParseContext) error { query, _, _, err := c.prepare() if err != nil { return err @@ -296,7 +296,7 @@ func (c *RemoteReadCommand) dump(k *kingpin.ParseContext) error { return nil } -func (c *RemoteReadCommand) stats(k *kingpin.ParseContext) error { +func (c *RemoteReadCommand) stats(_ *kingpin.ParseContext) error { query, _, _, err := c.prepare() if err != nil { return err @@ -378,7 +378,7 @@ func (c *RemoteReadCommand) stats(k *kingpin.ParseContext) error { return nil } -func (c *RemoteReadCommand) export(k *kingpin.ParseContext) error { +func (c *RemoteReadCommand) export(_ *kingpin.ParseContext) error { query, from, to, err := c.prepare() if err != nil { return err diff --git a/pkg/commands/rules.go b/pkg/commands/rules.go index 94c1a42ce..6c3111afa 100644 --- a/pkg/commands/rules.go +++ b/pkg/commands/rules.go @@ -241,7 +241,7 @@ func (r *RuleCommand) Register(app *kingpin.Application) { listCmd.Flag("disable-color", "disable colored output").BoolVar(&r.DisableColor) } -func (r *RuleCommand) setup(k *kingpin.ParseContext) error { +func (r *RuleCommand) setup(_ *kingpin.ParseContext) error { prometheus.MustRegister( ruleLoadTimestamp, ruleLoadSuccessTimestamp, @@ -331,7 +331,7 @@ func (r *RuleCommand) setupFiles() error { return nil } -func (r *RuleCommand) listRules(k *kingpin.ParseContext) error { +func (r *RuleCommand) listRules(_ *kingpin.ParseContext) error { rules, err := r.cli.ListRules(context.Background(), "") if err != nil { log.Fatalf("unable to read rules from cortex, %v", err) @@ -342,7 +342,7 @@ func (r *RuleCommand) listRules(k *kingpin.ParseContext) error { return p.PrintRuleSet(rules, r.Format, os.Stdout) } -func (r *RuleCommand) printRules(k *kingpin.ParseContext) error { +func (r *RuleCommand) printRules(_ *kingpin.ParseContext) error { rules, err := r.cli.ListRules(context.Background(), "") if err != nil { if err == client.ErrResourceNotFound { @@ -356,7 +356,7 @@ func (r *RuleCommand) printRules(k *kingpin.ParseContext) error { return p.PrintRuleGroups(rules) } -func (r *RuleCommand) getRuleGroup(k *kingpin.ParseContext) error { +func (r *RuleCommand) getRuleGroup(_ *kingpin.ParseContext) error { group, err := r.cli.GetRuleGroup(context.Background(), r.Namespace, r.RuleGroup) if err != nil { if err == client.ErrResourceNotFound { @@ -370,7 +370,7 @@ func (r *RuleCommand) getRuleGroup(k *kingpin.ParseContext) error { return p.PrintRuleGroup(*group) } -func (r *RuleCommand) deleteRuleGroup(k *kingpin.ParseContext) error { +func (r *RuleCommand) deleteRuleGroup(_ *kingpin.ParseContext) error { err := r.cli.DeleteRuleGroup(context.Background(), r.Namespace, r.RuleGroup) if err != nil && err != client.ErrResourceNotFound { log.Fatalf("unable to delete rule group from cortex, %v", err) @@ -378,7 +378,7 @@ func (r *RuleCommand) deleteRuleGroup(k *kingpin.ParseContext) error { return nil } -func (r *RuleCommand) deleteRuleNamespace(k *kingpin.ParseContext) error { +func (r *RuleCommand) deleteRuleNamespace(_ *kingpin.ParseContext) error { err := r.cli.DeleteRuleNamespace(context.Background(), r.Namespace) if err != nil && err != client.ErrResourceNotFound { log.Fatalf("unable to delete namespace from cortex, %v", err) @@ -386,7 +386,7 @@ func (r *RuleCommand) deleteRuleNamespace(k *kingpin.ParseContext) error { return nil } -func (r *RuleCommand) loadRules(k *kingpin.ParseContext) error { +func (r *RuleCommand) loadRules(_ *kingpin.ParseContext) error { nss, err := rules.ParseFiles(r.RuleFilesList) if err != nil { return errors.Wrap(err, "load operation unsuccessful, unable to parse rules files") @@ -443,7 +443,7 @@ func (r *RuleCommand) shouldCheckNamespace(namespace string) bool { return !ignored } -func (r *RuleCommand) diffRules(k *kingpin.ParseContext) error { +func (r *RuleCommand) diffRules(_ *kingpin.ParseContext) error { err := r.setupFiles() if err != nil { return errors.Wrap(err, "diff operation unsuccessful, unable to load rules files") @@ -506,7 +506,7 @@ func (r *RuleCommand) diffRules(k *kingpin.ParseContext) error { return p.PrintComparisonResult(changes, r.Verbose) } -func (r *RuleCommand) syncRules(k *kingpin.ParseContext) error { +func (r *RuleCommand) syncRules(_ *kingpin.ParseContext) error { err := r.setupFiles() if err != nil { return errors.Wrap(err, "sync operation unsuccessful, unable to load rules files") @@ -567,7 +567,7 @@ func (r *RuleCommand) syncRules(k *kingpin.ParseContext) error { err = r.executeChanges(context.Background(), changes) if err != nil { - return errors.Wrap(err, "sync operation unsuccessful, unable to complete executing changes.") + return errors.Wrap(err, "sync operation unsuccessful, unable to complete executing changes") } return nil @@ -628,7 +628,7 @@ func (r *RuleCommand) executeChanges(ctx context.Context, changes []rules.Namesp return nil } -func (r *RuleCommand) prepare(k *kingpin.ParseContext) error { +func (r *RuleCommand) prepare(_ *kingpin.ParseContext) error { err := r.setupFiles() if err != nil { return errors.Wrap(err, "prepare operation unsuccessful, unable to load rules files") @@ -666,7 +666,7 @@ func (r *RuleCommand) prepare(k *kingpin.ParseContext) error { return nil } -func (r *RuleCommand) lint(k *kingpin.ParseContext) error { +func (r *RuleCommand) lint(_ *kingpin.ParseContext) error { err := r.setupFiles() if err != nil { return errors.Wrap(err, "prepare operation unsuccessful, unable to load rules files") @@ -700,7 +700,7 @@ func (r *RuleCommand) lint(k *kingpin.ParseContext) error { return nil } -func (r *RuleCommand) checkRecordingRuleNames(k *kingpin.ParseContext) error { +func (r *RuleCommand) checkRecordingRuleNames(_ *kingpin.ParseContext) error { err := r.setupFiles() if err != nil { return errors.Wrap(err, "check operation unsuccessful, unable to load rules files") diff --git a/pkg/commands/rules_test.go b/pkg/commands/rules_test.go index a9cd59be3..706912955 100644 --- a/pkg/commands/rules_test.go +++ b/pkg/commands/rules_test.go @@ -3,10 +3,11 @@ package commands import ( "testing" - "github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt" "github.com/prometheus/prometheus/model/rulefmt" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" + + "github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt" ) func TestCheckDuplicates(t *testing.T) { diff --git a/pkg/rules/compare_test.go b/pkg/rules/compare_test.go index 390c9a8df..40671686f 100644 --- a/pkg/rules/compare_test.go +++ b/pkg/rules/compare_test.go @@ -3,9 +3,10 @@ package rules import ( "testing" - "github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt" "github.com/prometheus/prometheus/model/rulefmt" yaml "gopkg.in/yaml.v3" + + "github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt" ) func Test_rulesEqual(t *testing.T) { diff --git a/pkg/rules/rules.go b/pkg/rules/rules.go index d66b9ba4a..8e9bd6b37 100644 --- a/pkg/rules/rules.go +++ b/pkg/rules/rules.go @@ -25,7 +25,7 @@ type RuleNamespace struct { // LintExpressions runs the `expr` from a rule through the PromQL parser and // compares its output. If it differs from the parser, it uses the parser's instead. func (r RuleNamespace) LintExpressions() (int, int, error) { - var parseFn func(string) (fmt.Stringer, error) = func(s string) (fmt.Stringer, error) { + var parseFn = func(s string) (fmt.Stringer, error) { return parser.ParseExpr(s) }