Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
Signed-off-by: Friedrich Gonzalez <[email protected]>
  • Loading branch information
friedrichg committed Mar 25, 2024
1 parent bf3f815 commit 40e222c
Show file tree
Hide file tree
Showing 32 changed files with 79 additions and 84 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
6 changes: 3 additions & 3 deletions 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 All @@ -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
Expand All @@ -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")
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)))
}
2 changes: 1 addition & 1 deletion pkg/commands/analyse_rulefiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
8 changes: 2 additions & 6 deletions pkg/commands/analyse_ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down 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
4 changes: 2 additions & 2 deletions pkg/commands/bucket_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down 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
Loading

0 comments on commit 40e222c

Please sign in to comment.