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..fc1ec69a9 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, 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_ruler.go b/pkg/commands/analyse_ruler.go index 553ce86a2..2e53e3747 100644 --- a/pkg/commands/analyse_ruler.go +++ b/pkg/commands/analyse_ruler.go @@ -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..940e78158 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. diff --git a/pkg/commands/bucket_validation.go b/pkg/commands/bucket_validation.go index 2b08f9f25..d83508642 100644 --- a/pkg/commands/bucket_validation.go +++ b/pkg/commands/bucket_validation.go @@ -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..6436a3521 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) 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/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/rules.go b/pkg/commands/rules.go index 94c1a42ce..70f367c0d 100644 --- a/pkg/commands/rules.go +++ b/pkg/commands/rules.go @@ -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 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) }