Skip to content

Commit

Permalink
Fix new lints
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Feb 7, 2024
1 parent 38b1e26 commit e0f2e58
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions controllers/alert_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func (mex *metricNameExtractor) Visit(node parser.Node, path []parser.Node) (par
if err != nil {
// We do not return on error here so that any subsequent
// VectorSelector(s) get a chance to be processed.
mex.logger.Error(err, fmt.Sprintf("could not compile regex: %s", v.Value),
"expr", mex.expr)
mex.logger.Error(err, "could not compile regex: "+v.Value, "expr", mex.expr)
continue
}
if rx.MatchString(v.Value) {
Expand All @@ -88,13 +87,13 @@ func (mex *metricNameExtractor) Visit(node parser.Node, path []parser.Node) (par
}
if name == "" {
mex.logger.Error(errors.New("error while parsing PromQL query"),
fmt.Sprintf("could not find metric name for VectorSelector: %s", vs.String()),
"could not find metric name for VectorSelector: "+vs.String(),
"expr", mex.expr)
return mex, nil
}

switch {
case strings.Contains(mex.expr, fmt.Sprintf("absent(%s", name)) ||
case strings.Contains(mex.expr, "absent("+name) ||
strings.Contains(mex.expr, fmt.Sprintf("absent({__name__=\"%s\"", name)):
// Skip this metric if the there is already an absent function for it in the
// original expression.
Expand Down Expand Up @@ -200,7 +199,7 @@ func parseAlertRule(logger logr.Logger, in monitoringv1.Rule, opts LabelOpts) ([
if err != nil {
// TODO: remove newline characters from expression.
// The returned error has the expression at the end because
// it could contain newline chracters.
// it could contain newline characters.
return nil, fmt.Errorf("could not parse rule expression: %s: %s", err.Error(), exprStr)
}
if len(mex.found) == 0 {
Expand Down Expand Up @@ -269,7 +268,7 @@ func parseAlertRule(logger logr.Logger, in monitoringv1.Rule, opts LabelOpts) ([
// when our upstream solution gets the ability to process hardcoded
// links in the 'playbook' label.
ann := map[string]string{
"summary": fmt.Sprintf("missing %s", m),
"summary": "missing " + m,
"description": fmt.Sprintf(
"The metric '%s' is missing. '%s' alert using it may not fire as intended. "+
"See <https://github.com/sapcc/absent-metrics-operator/blob/master/docs/playbook.md|the operator playbook>.",
Expand Down
2 changes: 1 addition & 1 deletion test/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func createMockRule(metric string) monitoringv1.Rule {
duration := monitoringv1.Duration("5m")
return monitoringv1.Rule{
Alert: cases.Title(language.English).String(metric),
Expr: intstr.FromString(fmt.Sprintf("%s > 0", metric)),
Expr: intstr.FromString(metric + " > 0"),
For: &duration,
Labels: map[string]string{
"tier": "tier",
Expand Down

0 comments on commit e0f2e58

Please sign in to comment.