readingValue represents the state where the last byte read (now in p.currentByte) is the first byte of the sample value (i.e. a float).
()
| 384 | // readingValue represents the state where the last byte read (now in |
| 385 | // p.currentByte) is the first byte of the sample value (i.e. a float). |
| 386 | func (p *TextParser) readingValue() stateFn { |
| 387 | // When we are here, we have read all the labels, so for the |
| 388 | // special case of a summary/histogram, we can finally find out |
| 389 | // if the metric already exists. |
| 390 | if p.currentMF.GetType() == dto.MetricType_SUMMARY { |
| 391 | signature := model.LabelsToSignature(p.currentLabels) |
| 392 | if summary := p.summaries[signature]; summary != nil { |
| 393 | p.currentMetric = summary |
| 394 | } else { |
| 395 | p.summaries[signature] = p.currentMetric |
| 396 | p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric) |
| 397 | } |
| 398 | } else if p.currentMF.GetType() == dto.MetricType_HISTOGRAM { |
| 399 | signature := model.LabelsToSignature(p.currentLabels) |
| 400 | if histogram := p.histograms[signature]; histogram != nil { |
| 401 | p.currentMetric = histogram |
| 402 | } else { |
| 403 | p.histograms[signature] = p.currentMetric |
| 404 | p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric) |
| 405 | } |
| 406 | } else { |
| 407 | p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric) |
| 408 | } |
| 409 | if p.readTokenUntilWhitespace(); p.err != nil { |
| 410 | return nil // Unexpected end of input. |
| 411 | } |
| 412 | value, err := parseFloat(p.currentToken.String()) |
| 413 | if err != nil { |
| 414 | // Create a more helpful error message. |
| 415 | p.parseError(fmt.Sprintf("expected float as value, got %q", p.currentToken.String())) |
| 416 | return nil |
| 417 | } |
| 418 | switch p.currentMF.GetType() { |
| 419 | case dto.MetricType_COUNTER: |
| 420 | p.currentMetric.Counter = &dto.Counter{Value: proto.Float64(value)} |
| 421 | case dto.MetricType_GAUGE: |
| 422 | p.currentMetric.Gauge = &dto.Gauge{Value: proto.Float64(value)} |
| 423 | case dto.MetricType_UNTYPED: |
| 424 | p.currentMetric.Untyped = &dto.Untyped{Value: proto.Float64(value)} |
| 425 | case dto.MetricType_SUMMARY: |
| 426 | // *sigh* |
| 427 | if p.currentMetric.Summary == nil { |
| 428 | p.currentMetric.Summary = &dto.Summary{} |
| 429 | } |
| 430 | switch { |
| 431 | case p.currentIsSummaryCount: |
| 432 | p.currentMetric.Summary.SampleCount = proto.Uint64(uint64(value)) |
| 433 | case p.currentIsSummarySum: |
| 434 | p.currentMetric.Summary.SampleSum = proto.Float64(value) |
| 435 | case !math.IsNaN(p.currentQuantile): |
| 436 | p.currentMetric.Summary.Quantile = append( |
| 437 | p.currentMetric.Summary.Quantile, |
| 438 | &dto.Quantile{ |
| 439 | Quantile: proto.Float64(p.currentQuantile), |
| 440 | Value: proto.Float64(value), |
| 441 | }, |
| 442 | ) |
| 443 | } |
nothing calls this directly
no test coverage detected