Merge pull request #1455 from foehammer127/fix/1453
feat(prometheus/testutil/promlint/validations): refine lintMetricType…
This commit is contained in:
commit
694854aa24
|
@ -668,7 +668,6 @@ func TestLintMetricTypeInName(t *testing.T) {
|
||||||
twoProbTest,
|
twoProbTest,
|
||||||
genTest("instance_memory_limit_bytes_gauge", "gauge", "gauge"),
|
genTest("instance_memory_limit_bytes_gauge", "gauge", "gauge"),
|
||||||
genTest("request_duration_seconds_summary", "summary", "summary"),
|
genTest("request_duration_seconds_summary", "summary", "summary"),
|
||||||
genTest("request_duration_seconds_summary", "histogram", "summary"),
|
|
||||||
genTest("request_duration_seconds_histogram", "histogram", "histogram"),
|
genTest("request_duration_seconds_histogram", "histogram", "histogram"),
|
||||||
genTest("request_duration_seconds_HISTOGRAM", "histogram", "histogram"),
|
genTest("request_duration_seconds_HISTOGRAM", "histogram", "histogram"),
|
||||||
|
|
||||||
|
|
|
@ -44,21 +44,21 @@ func LintMetricUnits(mf *dto.MetricFamily) []error {
|
||||||
return problems
|
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 {
|
func LintMetricTypeInName(mf *dto.MetricFamily) []error {
|
||||||
var problems []error
|
if mf.GetType() == dto.MetricType_UNTYPED {
|
||||||
n := strings.ToLower(mf.GetName())
|
return nil
|
||||||
|
|
||||||
for i, t := range dto.MetricType_name {
|
|
||||||
if i == int32(dto.MetricType_UNTYPED) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var problems []error
|
||||||
|
|
||||||
|
n := strings.ToLower(mf.GetName())
|
||||||
|
typename := strings.ToLower(mf.GetType().String())
|
||||||
|
|
||||||
|
if strings.Contains(n, "_"+typename+"_") || strings.HasSuffix(n, "_"+typename) {
|
||||||
|
problems = append(problems, fmt.Errorf(`metric name should not include type '%s'`, typename))
|
||||||
|
}
|
||||||
|
|
||||||
return problems
|
return problems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue