Fix CT handling
Some checks failed
CI / Go tests (push) Has been cancelled
CI / More Go tests (push) Has been cancelled
CI / Go tests with previous Go version (push) Has been cancelled
CI / UI tests (push) Has been cancelled
CI / Go tests on Windows (push) Has been cancelled
CI / Mixins tests (push) Has been cancelled
CI / Build Prometheus for common architectures (0) (push) Has been cancelled
CI / Build Prometheus for common architectures (1) (push) Has been cancelled
CI / Build Prometheus for common architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (0) (push) Has been cancelled
CI / Build Prometheus for all architectures (1) (push) Has been cancelled
CI / Build Prometheus for all architectures (10) (push) Has been cancelled
CI / Build Prometheus for all architectures (11) (push) Has been cancelled
CI / Build Prometheus for all architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (3) (push) Has been cancelled
CI / Build Prometheus for all architectures (4) (push) Has been cancelled
CI / Build Prometheus for all architectures (5) (push) Has been cancelled
CI / Build Prometheus for all architectures (6) (push) Has been cancelled
CI / Build Prometheus for all architectures (7) (push) Has been cancelled
CI / Build Prometheus for all architectures (8) (push) Has been cancelled
CI / Build Prometheus for all architectures (9) (push) Has been cancelled
CI / Check generated parser (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / fuzzing (push) Has been cancelled
CI / codeql (push) Has been cancelled
CI / Report status of build Prometheus for all architectures (push) Has been cancelled
CI / Publish main branch artifacts (push) Has been cancelled
CI / Publish release artefacts (push) Has been cancelled
CI / Publish UI on npm Registry (push) Has been cancelled

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
György Krajcsovits 2024-10-07 16:59:07 +02:00
parent 6bebeaf41b
commit 16f28be713
2 changed files with 39 additions and 25 deletions

View file

@ -38,6 +38,7 @@ type NHCBParser struct {
// For Series and Histogram. // For Series and Histogram.
bytes []byte bytes []byte
ts *int64 ts *int64
ct *int64
value float64 value float64
h *histogram.Histogram h *histogram.Histogram
fh *histogram.FloatHistogram fh *histogram.FloatHistogram
@ -57,12 +58,15 @@ type NHCBParser struct {
bytesNHCB []byte bytesNHCB []byte
hNHCB *histogram.Histogram hNHCB *histogram.Histogram
fhNHCB *histogram.FloatHistogram fhNHCB *histogram.FloatHistogram
ctNHCB *int64
lsetNHCB labels.Labels lsetNHCB labels.Labels
metricStringNHCB string metricStringNHCB string
// Collates values from the classic histogram series to build // Collates values from the classic histogram series to build
// the converted histogram later. // the converted histogram later.
tempLsetNHCB labels.Labels tempLsetNHCB labels.Labels
tempCtNHCB *int64
tempCtNHCBbacking int64
tempNHCB convertnhcb.TempHistogram tempNHCB convertnhcb.TempHistogram
isCollationInProgress bool isCollationInProgress bool
@ -124,8 +128,10 @@ func (p *NHCBParser) Exemplar(ex *exemplar.Exemplar) bool {
} }
func (p *NHCBParser) CreatedTimestamp() *int64 { func (p *NHCBParser) CreatedTimestamp() *int64 {
// TODO(krajorama) fix: return p.parser.CreatedTimestamp() if p.justInsertedNHCB {
return nil return p.ctNHCB
}
return p.ct
} }
func (p *NHCBParser) Next() (Entry, error) { func (p *NHCBParser) Next() (Entry, error) {
@ -151,6 +157,7 @@ func (p *NHCBParser) Next() (Entry, error) {
case EntrySeries: case EntrySeries:
p.bytes, p.ts, p.value = p.parser.Series() p.bytes, p.ts, p.value = p.parser.Series()
p.metricString = p.parser.Metric(&p.lset) p.metricString = p.parser.Metric(&p.lset)
p.ct = p.parser.CreatedTimestamp()
// Check the label set to see if we can continue or need to emit the NHCB. // Check the label set to see if we can continue or need to emit the NHCB.
shouldInsertNHCB := false shouldInsertNHCB := false
if len(p.lastBaseHistLabels) > 0 { if len(p.lastBaseHistLabels) > 0 {
@ -183,13 +190,14 @@ func (p *NHCBParser) Next() (Entry, error) {
p.entry = et p.entry = et
return EntryHistogram, nil return EntryHistogram, nil
} }
if isNHCB := p.handleClassicHistogramSeries(p.lset); isNHCB && !p.keepClassicHistograms { if !p.keepClassicHistograms && p.handleClassicHistogramSeries(p.lset) {
return p.Next() return p.Next()
} }
return et, err return et, err
case EntryHistogram: case EntryHistogram:
p.bytes, p.ts, p.h, p.fh = p.parser.Histogram() p.bytes, p.ts, p.h, p.fh = p.parser.Histogram()
p.metricString = p.parser.Metric(&p.lset) p.metricString = p.parser.Metric(&p.lset)
p.ct = p.parser.CreatedTimestamp()
p.lastNativeHistLabels.CopyFrom(p.lset) p.lastNativeHistLabels.CopyFrom(p.lset)
case EntryType: case EntryType:
p.bName, p.typ = p.parser.Type() p.bName, p.typ = p.parser.Type()
@ -231,6 +239,10 @@ func (p *NHCBParser) handleClassicHistogramSeries(lset labels.Labels) bool {
if convertnhcb.GetHistogramMetricBaseName(mName) != string(p.bName) { if convertnhcb.GetHistogramMetricBaseName(mName) != string(p.bName) {
return false return false
} }
if p.ct != nil {
p.tempCtNHCBbacking = *p.ct
p.tempCtNHCB = &p.tempCtNHCBbacking
}
switch { switch {
case strings.HasSuffix(mName, "_bucket") && lset.Has(labels.BucketLabel): case strings.HasSuffix(mName, "_bucket") && lset.Has(labels.BucketLabel):
le, err := strconv.ParseFloat(lset.Get(labels.BucketLabel), 64) le, err := strconv.ParseFloat(lset.Get(labels.BucketLabel), 64)
@ -286,10 +298,12 @@ func (p *NHCBParser) processNHCB() bool {
p.hNHCB = nil p.hNHCB = nil
p.fhNHCB = fh p.fhNHCB = fh
} }
p.ctNHCB = p.tempCtNHCB
p.metricStringNHCB = p.tempLsetNHCB.Get(labels.MetricName) + strings.ReplaceAll(p.tempLsetNHCB.DropMetricName().String(), ", ", ",") p.metricStringNHCB = p.tempLsetNHCB.Get(labels.MetricName) + strings.ReplaceAll(p.tempLsetNHCB.DropMetricName().String(), ", ", ",")
p.bytesNHCB = []byte(p.metricStringNHCB) p.bytesNHCB = []byte(p.metricStringNHCB)
p.lsetNHCB = p.tempLsetNHCB p.lsetNHCB = p.tempLsetNHCB
p.tempNHCB = convertnhcb.NewTempHistogram() p.tempNHCB = convertnhcb.NewTempHistogram()
p.tempCtNHCB = nil
p.isCollationInProgress = false p.isCollationInProgress = false
p.justInsertedNHCB = true p.justInsertedNHCB = true
return true return true

View file

@ -228,7 +228,7 @@ foobar{quantile="0.99"} 150.1`
m: `smr_seconds_count`, m: `smr_seconds_count`,
v: 2, v: 2,
lset: labels.FromStrings("__name__", "smr_seconds_count"), lset: labels.FromStrings("__name__", "smr_seconds_count"),
es: []exemplar.Exemplar{{Labels: labels.FromStrings("id", "summary-count-test"), Value: 1, HasTs: true, Ts: 123321}}, // TODO(krajorama) e:es: []exemplar.Exemplar{{Labels: labels.FromStrings("id", "summary-count-test"), Value: 1, HasTs: true, Ts: 123321}},
}, { }, {
m: `smr_seconds_sum`, m: `smr_seconds_sum`,
v: 42, v: 42,
@ -282,15 +282,15 @@ foobar{quantile="0.99"} 150.1`
v: 17, v: 17,
lset: labels.FromStrings("__name__", "foo_total"), lset: labels.FromStrings("__name__", "foo_total"),
t: int64p(1520879607789), t: int64p(1520879607789),
es: []exemplar.Exemplar{{Labels: labels.FromStrings("id", "counter-test"), Value: 5}}, // TODO(krajorama) e:es: []exemplar.Exemplar{{Labels: labels.FromStrings("id", "counter-test"), Value: 5}},
// TODO ct: int64p(1520872607123), ct: int64p(1520872607123),
}, { }, {
m: `foo_total{a="b"}`, m: `foo_total{a="b"}`,
v: 17.0, v: 17.0,
lset: labels.FromStrings("__name__", "foo_total", "a", "b"), lset: labels.FromStrings("__name__", "foo_total", "a", "b"),
t: int64p(1520879607789), t: int64p(1520879607789),
es: []exemplar.Exemplar{{Labels: labels.FromStrings("id", "counter-test"), Value: 5}}, // TODO(krajorama) e:es: []exemplar.Exemplar{{Labels: labels.FromStrings("id", "counter-test"), Value: 5}},
// TODO(krajorama): ct: int64p(1520872607123), ct: int64p(1520872607123),
}, { }, {
m: "bar", m: "bar",
help: "Summary with CT at the end, making sure we find CT even if it's multiple lines a far", help: "Summary with CT at the end, making sure we find CT even if it's multiple lines a far",
@ -301,22 +301,22 @@ foobar{quantile="0.99"} 150.1`
m: "bar_count", m: "bar_count",
v: 17.0, v: 17.0,
lset: labels.FromStrings("__name__", "bar_count"), lset: labels.FromStrings("__name__", "bar_count"),
// TODO(krajorama): ct: int64p(1520872608124), ct: int64p(1520872608124),
}, { }, {
m: "bar_sum", m: "bar_sum",
v: 324789.3, v: 324789.3,
lset: labels.FromStrings("__name__", "bar_sum"), lset: labels.FromStrings("__name__", "bar_sum"),
// TODO(krajorama): ct: int64p(1520872608124), ct: int64p(1520872608124),
}, { }, {
m: `bar{quantile="0.95"}`, m: `bar{quantile="0.95"}`,
v: 123.7, v: 123.7,
lset: labels.FromStrings("__name__", "bar", "quantile", "0.95"), lset: labels.FromStrings("__name__", "bar", "quantile", "0.95"),
// TODO(krajorama): ct: int64p(1520872608124), ct: int64p(1520872608124),
}, { }, {
m: `bar{quantile="0.99"}`, m: `bar{quantile="0.99"}`,
v: 150.0, v: 150.0,
lset: labels.FromStrings("__name__", "bar", "quantile", "0.99"), lset: labels.FromStrings("__name__", "bar", "quantile", "0.99"),
// TODO(krajorama): ct: int64p(1520872608124), ct: int64p(1520872608124),
}, { }, {
m: "baz", m: "baz",
help: "Histogram with the same objective as above's summary", help: "Histogram with the same objective as above's summary",
@ -334,7 +334,7 @@ foobar{quantile="0.99"} 150.1`
CustomValues: []float64{0.0}, // We do not store the +Inf boundary. CustomValues: []float64{0.0}, // We do not store the +Inf boundary.
}, },
lset: labels.FromStrings("__name__", "baz"), lset: labels.FromStrings("__name__", "baz"),
//ct: int64p(1520872609125), ct: int64p(1520872609125),
}, { }, {
m: "fizz_created", m: "fizz_created",
help: "Gauge which shouldn't be parsed as CT", help: "Gauge which shouldn't be parsed as CT",
@ -362,7 +362,7 @@ foobar{quantile="0.99"} 150.1`
CustomValues: []float64{0.0}, // We do not store the +Inf boundary. CustomValues: []float64{0.0}, // We do not store the +Inf boundary.
}, },
lset: labels.FromStrings("__name__", "something"), lset: labels.FromStrings("__name__", "something"),
// TODO(krajorama): ct: int64p(1520430001000), ct: int64p(1520430001000),
}, { }, {
m: `something{a="b"}`, m: `something{a="b"}`,
shs: &histogram.Histogram{ shs: &histogram.Histogram{
@ -374,7 +374,7 @@ foobar{quantile="0.99"} 150.1`
CustomValues: []float64{0.0}, // We do not store the +Inf boundary. CustomValues: []float64{0.0}, // We do not store the +Inf boundary.
}, },
lset: labels.FromStrings("__name__", "something", "a", "b"), lset: labels.FromStrings("__name__", "something", "a", "b"),
// TODO(krajorama): ct: int64p(1520430001000), ct: int64p(1520430002000),
}, { }, {
m: "yum", m: "yum",
help: "Summary with _created between sum and quantiles", help: "Summary with _created between sum and quantiles",
@ -385,22 +385,22 @@ foobar{quantile="0.99"} 150.1`
m: `yum_count`, m: `yum_count`,
v: 20, v: 20,
lset: labels.FromStrings("__name__", "yum_count"), lset: labels.FromStrings("__name__", "yum_count"),
// TODO(krajorama): ct: int64p(1520430003000), ct: int64p(1520430003000),
}, { }, {
m: `yum_sum`, m: `yum_sum`,
v: 324789.5, v: 324789.5,
lset: labels.FromStrings("__name__", "yum_sum"), lset: labels.FromStrings("__name__", "yum_sum"),
// TODO(krajorama): ct: int64p(1520430003000), ct: int64p(1520430003000),
}, { }, {
m: `yum{quantile="0.95"}`, m: `yum{quantile="0.95"}`,
v: 123.7, v: 123.7,
lset: labels.FromStrings("__name__", "yum", "quantile", "0.95"), lset: labels.FromStrings("__name__", "yum", "quantile", "0.95"),
// TODO(krajorama): ct: int64p(1520430003000), ct: int64p(1520430003000),
}, { }, {
m: `yum{quantile="0.99"}`, m: `yum{quantile="0.99"}`,
v: 150.0, v: 150.0,
lset: labels.FromStrings("__name__", "yum", "quantile", "0.99"), lset: labels.FromStrings("__name__", "yum", "quantile", "0.99"),
// TODO(krajorama): ct: int64p(1520430003000), ct: int64p(1520430003000),
}, { }, {
m: "foobar", m: "foobar",
help: "Summary with _created as the first line", help: "Summary with _created as the first line",
@ -411,22 +411,22 @@ foobar{quantile="0.99"} 150.1`
m: `foobar_count`, m: `foobar_count`,
v: 21, v: 21,
lset: labels.FromStrings("__name__", "foobar_count"), lset: labels.FromStrings("__name__", "foobar_count"),
// TODO(krajorama): ct: int64p(1520430004000), ct: int64p(1520430004000),
}, { }, {
m: `foobar_sum`, m: `foobar_sum`,
v: 324789.6, v: 324789.6,
lset: labels.FromStrings("__name__", "foobar_sum"), lset: labels.FromStrings("__name__", "foobar_sum"),
// TODO(krajorama): ct: int64p(1520430004000), ct: int64p(1520430004000),
}, { }, {
m: `foobar{quantile="0.95"}`, m: `foobar{quantile="0.95"}`,
v: 123.8, v: 123.8,
lset: labels.FromStrings("__name__", "foobar", "quantile", "0.95"), lset: labels.FromStrings("__name__", "foobar", "quantile", "0.95"),
// TODO(krajorama): ct: int64p(1520430004000), ct: int64p(1520430004000),
}, { }, {
m: `foobar{quantile="0.99"}`, m: `foobar{quantile="0.99"}`,
v: 150.1, v: 150.1,
lset: labels.FromStrings("__name__", "foobar", "quantile", "0.99"), lset: labels.FromStrings("__name__", "foobar", "quantile", "0.99"),
// TODO(krajorama): ct: int64p(1520430004000), ct: int64p(1520430004000),
}, { }, {
m: "metric", m: "metric",
help: "foo\x00bar", help: "foo\x00bar",
@ -479,7 +479,7 @@ something_created{a="b"} 1520430002
CustomValues: []float64{0.0}, // We do not store the +Inf boundary. CustomValues: []float64{0.0}, // We do not store the +Inf boundary.
}, },
lset: labels.FromStrings("__name__", "something"), lset: labels.FromStrings("__name__", "something"),
// TODO(krajorama): ct: int64p(1520430001000), ct: int64p(1520430001000),
}, { }, {
m: `something{a="b"}`, m: `something{a="b"}`,
shs: &histogram.Histogram{ shs: &histogram.Histogram{
@ -491,7 +491,7 @@ something_created{a="b"} 1520430002
CustomValues: []float64{0.0}, // We do not store the +Inf boundary. CustomValues: []float64{0.0}, // We do not store the +Inf boundary.
}, },
lset: labels.FromStrings("__name__", "something", "a", "b"), lset: labels.FromStrings("__name__", "something", "a", "b"),
// TODO(krajorama): ct: int64p(1520430001000), ct: int64p(1520430002000),
}, },
} }