@@ -1374,7 +1374,7 @@ func (p *parser) parseLabelFilterExpr() (*labelFilterExpr, error) {
1374
1374
// - {lf,other="filter"}
1375
1375
// - {lf or other="filter"}
1376
1376
//
1377
- // It which must be substituted by complete label filter during WITH template expand.
1377
+ // It must be substituted by complete label filter during WITH template expand.
1378
1378
return & lfe , nil
1379
1379
default :
1380
1380
return nil , fmt .Errorf (`labelFilterExpr: unexpected token %q; want "=", "!=", "=~", "!~", ",", "or", "}"` , p .lex .Token )
@@ -2257,28 +2257,31 @@ func isOnlyMetricNameInLabelFilterss(lfss [][]*labelFilterExpr) bool {
2257
2257
}
2258
2258
2259
2259
func getMetricNameFromLabelFilterss (lfss [][]* labelFilterExpr ) string {
2260
- if len (lfss ) == 0 || len (lfss [0 ]) == 0 {
2260
+ if len (lfss ) == 0 {
2261
+ return ""
2262
+ }
2263
+ metricName := mustGetMetricName (lfss [0 ])
2264
+ if metricName == "" {
2261
2265
return ""
2262
2266
}
2263
- metricName := lfss [0 ][0 ].mustGetMetricName ()
2264
2267
for _ , lfs := range lfss [1 :] {
2265
- if len (lfs ) == 0 {
2266
- return ""
2267
- }
2268
- metricNameLocal := lfs [0 ].mustGetMetricName ()
2268
+ metricNameLocal := mustGetMetricName (lfs )
2269
2269
if metricNameLocal != metricName {
2270
2270
return ""
2271
2271
}
2272
2272
}
2273
2273
return metricName
2274
2274
}
2275
2275
2276
- func (lfe * labelFilterExpr ) mustGetMetricName () string {
2277
- if lfe .Label != "__name__" || lfe .Value == nil || len (lfe .Value .tokens ) != 1 {
2276
+ func mustGetMetricName (lfss []* labelFilterExpr ) string {
2277
+ if len (lfss ) == 0 {
2278
+ return ""
2279
+ }
2280
+ lfs := lfss [0 ]
2281
+ if lfs .Label != "__name__" || lfs .Value == nil || len (lfs .Value .tokens ) != 1 {
2278
2282
return ""
2279
2283
}
2280
- token := lfe .Value .tokens [0 ]
2281
- metricName , err := extractStringValue (token )
2284
+ metricName , err := extractStringValue (lfs .Value .tokens [0 ])
2282
2285
if err != nil {
2283
2286
panic (fmt .Errorf ("BUG: cannot obtain metric name: %w" , err ))
2284
2287
}
0 commit comments