startLabelName represents the state where the next byte read from p.buf is the start of a label name (or whitespace leading up to it).
()
| 335 | // startLabelName represents the state where the next byte read from p.buf is |
| 336 | // the start of a label name (or whitespace leading up to it). |
| 337 | func (p *TextParser) startLabelName() stateFn { |
| 338 | if p.skipBlankTab(); p.err != nil { |
| 339 | return nil // Unexpected end of input. |
| 340 | } |
| 341 | if p.currentByte == '}' { |
| 342 | if p.currentMF == nil { |
| 343 | // The closing brace was reached before any metric name was read, |
| 344 | // e.g. for the input "{}". There is no metric to attach labels to, |
| 345 | // so this is a malformed exposition. This mirrors the guard in |
| 346 | // startLabelValue. currentMF (not currentMetric) is checked because |
| 347 | // reset only clears currentMF between parses. |
| 348 | p.parseError("invalid metric name") |
| 349 | p.currentLabelPairs = nil |
| 350 | return nil |
| 351 | } |
| 352 | p.currentMetric.Label = append(p.currentMetric.Label, p.currentLabelPairs...) |
| 353 | p.currentLabelPairs = nil |
| 354 | if p.skipBlankTab(); p.err != nil { |
| 355 | return nil // Unexpected end of input. |
| 356 | } |
| 357 | return p.readingValue |
| 358 | } |
| 359 | if p.readTokenAsLabelName(); p.err != nil { |
| 360 | return nil // Unexpected end of input. |
| 361 | } |
| 362 | if p.currentToken.Len() == 0 { |
| 363 | p.parseError(fmt.Sprintf("invalid label name for metric %q", p.currentMF.GetName())) |
| 364 | return nil |
| 365 | } |
| 366 | if p.skipBlankTabIfCurrentBlankTab(); p.err != nil { |
| 367 | return nil // Unexpected end of input. |
| 368 | } |
| 369 | if p.currentByte != '=' { |
| 370 | if p.currentMetricIsInsideBraces { |
| 371 | if p.currentMetricInsideBracesIsPresent { |
| 372 | p.parseError(fmt.Sprintf("multiple metric names for metric %q", p.currentMF.GetName())) |
| 373 | return nil |
| 374 | } |
| 375 | switch p.currentByte { |
| 376 | case ',': |
| 377 | p.setOrCreateCurrentMF() |
| 378 | if p.err != nil { |
| 379 | return nil |
| 380 | } |
| 381 | if p.currentMF.Type == nil { |
| 382 | p.currentMF.Type = dto.MetricType_UNTYPED.Enum() |
| 383 | } |
| 384 | p.currentMetric = &dto.Metric{} |
| 385 | p.currentMetricInsideBracesIsPresent = true |
| 386 | return p.startLabelName |
| 387 | case '}': |
| 388 | p.setOrCreateCurrentMF() |
| 389 | if p.err != nil { |
| 390 | p.currentLabelPairs = nil |
| 391 | return nil |
| 392 | } |
| 393 | if p.currentMF.Type == nil { |
| 394 | p.currentMF.Type = dto.MetricType_UNTYPED.Enum() |
nothing calls this directly
no test coverage detected