File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
prometheus/testutil/promlint Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -287,17 +287,15 @@ func lintUnitAbbreviations(mf *dto.MetricFamily) []Problem {
287287func metricUnits (m string ) (unit , base string , ok bool ) {
288288 ss := strings .Split (m , "_" )
289289
290- for unit , base := range units {
291- // Also check for "no prefix".
292- for _ , p := range append (unitPrefixes , "" ) {
293- for _ , s := range ss {
294- // Attempt to explicitly match a known unit with a known prefix,
295- // as some words may look like "units" when matching suffix.
296- //
297- // As an example, "thermometers" should not match "meters", but
298- // "kilometers" should.
299- if s == p + unit {
300- return p + unit , base , true
290+ for _ , s := range ss {
291+ if base , found := units [s ]; found {
292+ return s , base , true
293+ }
294+
295+ for _ , p := range unitPrefixes {
296+ if strings .HasPrefix (s , p ) {
297+ if base , found := units [s [len (p ):]]; found {
298+ return s , base , true
301299 }
302300 }
303301 }
You can’t perform that action at this time.
0 commit comments