Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
Signed-off-by: Friedrich Gonzalez <friedrichg@gmail.com>
  • Loading branch information
friedrichg committed Mar 25, 2024
1 parent bf3f815 commit a9efb9b
Show file tree
Hide file tree
Showing 28 changed files with 54 additions and 59 deletions.
3 changes: 2 additions & 1 deletion cmd/e2ealerting/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions cmd/logtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
}

}
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/alerting/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyse/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/bench/query_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/bench/write_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/chunk/cassandra/storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
2 changes: 1 addition & 1 deletion pkg/chunk/migrate/writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/client/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/access_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions pkg/commands/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/analyse_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down
8 changes: 2 additions & 6 deletions pkg/commands/analyse_grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down Expand Up @@ -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)))
}
8 changes: 2 additions & 6 deletions pkg/commands/analyse_prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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)))
}
6 changes: 1 addition & 5 deletions pkg/commands/analyse_ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
5 changes: 3 additions & 2 deletions pkg/commands/analyse_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/block_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/bucket_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/push_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit a9efb9b

Please sign in to comment.