Skip to content

Commit

Permalink
fix: linter happiness
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrgm committed Jan 5, 2024
1 parent 948bd89 commit 6a80eb4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
1 change: 0 additions & 1 deletion .errcheck_excludes.txt

This file was deleted.

14 changes: 14 additions & 0 deletions cmd/promcheck/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (app *promcheckApp) checkRules() error {
func (app *promcheckApp) checkRulesFromRuleFiles() error {
matches, err := filepath.Glob(app.optFilesRegexp)
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to parse rule group file paths", "err", err)
return err
}
Expand All @@ -151,13 +152,15 @@ func (app *promcheckApp) checkRulesFromRuleFiles() error {
for _, file := range matches {
ruleGroups, err := processFile(file)
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to parse rule group files", "err", err)
return err
}
ruleGroupsToCheck = append(ruleGroupsToCheck, ruleGroups...)
}

if len(ruleGroupsToCheck) == 0 {
// nolint: errcheck
level.Error(app.logger).Log("msg", "no rule groups to check. Please check for --check.file flag spelling mistakes")
return err
}
Expand All @@ -171,6 +174,7 @@ func (app *promcheckApp) checkRulesFromRuleFiles() error {
eg.Go(func() error {
checked, err := app.check.CheckRuleGroup(group)
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to check rule groups", "file", group.File, "err", err)
return err
}
Expand All @@ -184,6 +188,7 @@ func (app *promcheckApp) checkRulesFromRuleFiles() error {

go func() {
if err := eg.Wait(); err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to check rule groups", "err", err)
close(resultChan)
return
Expand Down Expand Up @@ -212,6 +217,7 @@ func (app *promcheckApp) checkRulesFromRuleFiles() error {
if hasExpressionsWithoutResult && app.optStrictMode {
err := app.report.Dump()
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to print report", "err", err)
}
os.Exit(1)
Expand Down Expand Up @@ -260,12 +266,14 @@ func (app *promcheckApp) checkRulesFromPrometheusInstance() error {
RoundTripper: app.roundTripper,
})
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to create Prometheus client", "err", err)
return err
}
promAPI := prometheusv1.NewAPI(client)
apiResponse, err := promAPI.Rules(context.TODO()) // TODO: Can we somehow only load the ones we're interested in if filtered?
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to receive rules from prometheus instance", "err", err)
return err
}
Expand All @@ -276,6 +284,7 @@ func (app *promcheckApp) checkRulesFromPrometheusInstance() error {
}

if len(ruleGroupsToCheck) == 0 {
// nolint: errcheck
level.Error(app.logger).Log("msg", "no rule groups to check. Please check whether the Prometheus instance contains any rules.")
return err
}
Expand All @@ -289,6 +298,7 @@ func (app *promcheckApp) checkRulesFromPrometheusInstance() error {
eg.Go(func() error {
checked, err := app.check.CheckRuleGroup(group)
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to check rule groups", "file", group.File, "err", err)
return err
}
Expand All @@ -302,6 +312,7 @@ func (app *promcheckApp) checkRulesFromPrometheusInstance() error {

go func() {
if err := eg.Wait(); err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to check rule groups", "err", err)
close(resultChan)
return
Expand Down Expand Up @@ -329,6 +340,7 @@ func (app *promcheckApp) checkRulesFromPrometheusInstance() error {
if hasExpressionsWithoutResult && app.optStrictMode {
err := app.report.Dump()
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to print report", "err", err)
}
os.Exit(1)
Expand Down Expand Up @@ -375,6 +387,7 @@ func (app *promcheckApp) checkRulesFromInlineQueries() error {
checkResults := []promcheck.CheckResult{}
checked, err := app.check.CheckRuleGroup(group)
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to check rule groups", "file", group.File, "err", err)
return err
}
Expand All @@ -399,6 +412,7 @@ func (app *promcheckApp) checkRulesFromInlineQueries() error {
if hasExpressionsWithoutResult && app.optStrictMode {
err := app.report.Dump()
if err != nil {
// nolint: errcheck
level.Error(app.logger).Log("msg", "failed to print report", "err", err)
}
os.Exit(1)
Expand Down
2 changes: 2 additions & 0 deletions cmd/promcheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ func main() {

// validation
if cfg.ExporterInterval < 0 {
// nolint: errcheck
level.Error(logger).Log("msg", "configuration error", "err", "--exporter.interval must be > 0")
os.Exit(1)
}

if cfg.CheckDelay < 0 {
// nolint: errcheck
level.Error(logger).Log("msg", "configuration error", "err", "--check.delay must be > 0")
os.Exit(1)
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/promcheck/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (app *promcheckApp) runPromcheckExporter() error {
{
httpLogger := log.With(app.logger, "component", "exporter")
m := http.NewServeMux()
handleHealth := func(w http.ResponseWriter, r *http.Request) {
handleHealth := func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
}
m.HandleFunc("/health", handleHealth)
Expand All @@ -40,7 +40,7 @@ func (app *promcheckApp) runPromcheckExporter() error {
Handler: m,
}

m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
m.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`<html>
<head><title>Promcheck Exporter</title></head>
<body>
Expand All @@ -50,13 +50,14 @@ func (app *promcheckApp) runPromcheckExporter() error {
</html>`))
})
gr.Add(func() error {
// nolint: errcheck
level.Info(httpLogger).Log(
"msg", "running http server",
"addr", s.Addr,
)

return s.ListenAndServe()
}, func(err error) {
}, func(_ error) {
_ = s.Shutdown(context.TODO())
})
}
Expand All @@ -70,6 +71,7 @@ func (app *promcheckApp) runPromcheckExporter() error {
case <-ctx.Done():
return nil
case <-tick.C:
// nolint: errcheck
level.Info(app.logger).Log(
"msg", "executing promcheck routine",
)
Expand All @@ -79,6 +81,7 @@ func (app *promcheckApp) runPromcheckExporter() error {
}
}
}, func(err error) {
// nolint: errcheck
level.Info(app.logger).Log(
"msg", "error while executing promcheck routine",
"err", err,
Expand All @@ -91,7 +94,7 @@ func (app *promcheckApp) runPromcheckExporter() error {
gr.Add(func() error {
<-sig
return nil
}, func(err error) {
}, func(_ error) {
cancel()
close(sig)
})
Expand Down

0 comments on commit 6a80eb4

Please sign in to comment.