mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
feat: multiple changes
- implement changes from pair programming session - use newParse.val() - advance parser p if ct is found Signed-off-by: Manik Rana <manikrana54@gmail.com>
This commit is contained in:
parent
188d4cc927
commit
e841e00eed
|
@ -21,7 +21,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
|
@ -224,44 +223,48 @@ func (p *OpenMetricsParser) Exemplar(e *exemplar.Exemplar) bool {
|
|||
// CreatedTimestamp returns nil as it's not implemented yet.
|
||||
// TODO(bwplotka): https://github.com/prometheus/prometheus/issues/12980
|
||||
func (p *OpenMetricsParser) CreatedTimestamp() *int64 {
|
||||
var lbs labels.Labels
|
||||
p.Metric(&lbs)
|
||||
lbs = lbs.DropMetricName()
|
||||
|
||||
newParser := deepCopyParser(p)
|
||||
loop:
|
||||
for {
|
||||
switch t, _ := newParser.Next(); t {
|
||||
case EntrySeries:
|
||||
// continue instead of return nil until we get new series/labels. can happen for histograms, summaries
|
||||
for {
|
||||
// Check _created suffix
|
||||
var lbs labels.Labels
|
||||
newParser.Metric(&lbs)
|
||||
name := lbs.Get(model.MetricNameLabel)
|
||||
if name[len(name)-8:] != "_created" {
|
||||
return nil
|
||||
var newLbs labels.Labels
|
||||
newParser.Metric(&newLbs)
|
||||
name := newLbs.Get(model.MetricNameLabel)
|
||||
if !strings.HasSuffix(name, "_created") {
|
||||
continue
|
||||
}
|
||||
|
||||
// TODO: potentially broken? Missing type?
|
||||
if newParser.mName != p.mName {
|
||||
return nil
|
||||
}
|
||||
|
||||
// edge case: if guage_created of unknown type -> skip parsing
|
||||
|
||||
// Check if labelsets are the same
|
||||
newLbs = newLbs.DropMetricName()
|
||||
if !labels.Equal(lbs, newLbs) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: for histograms
|
||||
// if t, _ := newParser.Next(); t != EntrySeries {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// return CT value
|
||||
ctBytes := newParser.l.b[newParser.offsets[len(newParser.offsets)-1]+1:newParser.l.start]
|
||||
ct, err := strconv.ParseInt(yoloString(ctBytes), 10, 64)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// guage_created is a metric
|
||||
|
||||
ct := int64(newParser.val)
|
||||
p.Next()
|
||||
return &ct
|
||||
}
|
||||
default:
|
||||
// If not series, we don't care.
|
||||
break loop
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue