Skip to content

Commit

Permalink
feat(prometheus/testutil/promlint/validations): refine lintMetricType…
Browse files Browse the repository at this point in the history
…InName

Change the lintMetricTypeInName linter inside promlint to only trigger an error when the metric name matches the type of the metric.

Signed-off-by: Lorenzo Good <[email protected]>
  • Loading branch information
lorenzogood committed Feb 28, 2024
1 parent 14259fa commit 3627a07
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ func LintMetricUnits(mf *dto.MetricFamily) []error {
return problems
}

// LintMetricTypeInName detects when metric types are included in the metric name.
// LintMetricTypeInName detects when the metric type is included in the metric name.
func LintMetricTypeInName(mf *dto.MetricFamily) []error {
if *mf.Type == dto.MetricType_UNTYPED {
return nil
}

var problems []error
n := strings.ToLower(mf.GetName())

for i, t := range dto.MetricType_name {
if i == int32(dto.MetricType_UNTYPED) {
continue
}
n := strings.ToLower(mf.GetName())
typename := strings.ToLower(mf.Type.String())

typename := strings.ToLower(t)
if strings.Contains(n, "_"+typename+"_") || strings.HasSuffix(n, "_"+typename) {
problems = append(problems, fmt.Errorf(`metric name should not include type '%s'`, typename))
}
if strings.Contains(n, "_"+typename+"_") || strings.HasSuffix(n, "_"+typename) {
problems = append(problems, fmt.Errorf(`metric name should not include type '%s'`, typename))
}

return problems
}

Expand Down

0 comments on commit 3627a07

Please sign in to comment.