Skip to content

Commit 694854a

Browse files
authored
Merge pull request #1455 from foehammer127/fix/1453
feat(prometheus/testutil/promlint/validations): refine lintMetricType…
2 parents 14259fa + cead7c3 commit 694854a

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

prometheus/testutil/promlint/promlint_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ func TestLintMetricTypeInName(t *testing.T) {
668668
twoProbTest,
669669
genTest("instance_memory_limit_bytes_gauge", "gauge", "gauge"),
670670
genTest("request_duration_seconds_summary", "summary", "summary"),
671-
genTest("request_duration_seconds_summary", "histogram", "summary"),
672671
genTest("request_duration_seconds_histogram", "histogram", "histogram"),
673672
genTest("request_duration_seconds_HISTOGRAM", "histogram", "histogram"),
674673

prometheus/testutil/promlint/validations/generic_name_validations.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ func LintMetricUnits(mf *dto.MetricFamily) []error {
4444
return problems
4545
}
4646

47-
// LintMetricTypeInName detects when metric types are included in the metric name.
47+
// LintMetricTypeInName detects when the metric type is included in the metric name.
4848
func LintMetricTypeInName(mf *dto.MetricFamily) []error {
49+
if mf.GetType() == dto.MetricType_UNTYPED {
50+
return nil
51+
}
52+
4953
var problems []error
50-
n := strings.ToLower(mf.GetName())
5154

52-
for i, t := range dto.MetricType_name {
53-
if i == int32(dto.MetricType_UNTYPED) {
54-
continue
55-
}
55+
n := strings.ToLower(mf.GetName())
56+
typename := strings.ToLower(mf.GetType().String())
5657

57-
typename := strings.ToLower(t)
58-
if strings.Contains(n, "_"+typename+"_") || strings.HasSuffix(n, "_"+typename) {
59-
problems = append(problems, fmt.Errorf(`metric name should not include type '%s'`, typename))
60-
}
58+
if strings.Contains(n, "_"+typename+"_") || strings.HasSuffix(n, "_"+typename) {
59+
problems = append(problems, fmt.Errorf(`metric name should not include type '%s'`, typename))
6160
}
61+
6262
return problems
6363
}
6464

0 commit comments

Comments
 (0)