histogram: include counter reset hint in test expression output

Signed-off-by: Charles Korn <charles.korn@grafana.com>
This commit is contained in:
Charles Korn 2024-09-04 15:39:05 +10:00
parent 282fb1632a
commit e67358d203
No known key found for this signature in database
2 changed files with 27 additions and 0 deletions

View file

@ -230,6 +230,17 @@ func (h *FloatHistogram) TestExpression() string {
res = append(res, fmt.Sprintf("custom_values:%g", m.CustomValues))
}
switch m.CounterResetHint {
case UnknownCounterReset:
// Unknown is the default, don't add anything.
case CounterReset:
res = append(res, fmt.Sprintf("counter_reset_hint:reset"))
case NotCounterReset:
res = append(res, fmt.Sprintf("counter_reset_hint:not_reset"))
case GaugeType:
res = append(res, fmt.Sprintf("counter_reset_hint:gauge"))
}
addBuckets := func(kind, bucketsKey, offsetKey string, buckets []float64, spans []Span) []string {
if len(spans) > 1 {
panic(fmt.Sprintf("histogram with multiple %s spans not supported", kind))

View file

@ -4385,6 +4385,22 @@ func TestHistogramTestExpression(t *testing.T) {
},
expected: `{{offset:-3 buckets:[5.1 0 0 0 0 10 7] n_offset:-1 n_buckets:[4.1 5 0 0 7 8 9]}}`,
},
{
name: "known counter reset hint",
input: histogram.FloatHistogram{
Schema: 1,
Sum: -0.3,
Count: 3.1,
ZeroCount: 7.1,
ZeroThreshold: 0.05,
PositiveBuckets: []float64{5.1, 10, 7},
PositiveSpans: []histogram.Span{{Offset: -3, Length: 3}},
NegativeBuckets: []float64{4.1, 5},
NegativeSpans: []histogram.Span{{Offset: -5, Length: 2}},
CounterResetHint: histogram.CounterReset,
},
expected: `{{schema:1 count:3.1 sum:-0.3 z_bucket:7.1 z_bucket_w:0.05 counter_reset_hint:reset offset:-3 buckets:[5.1 10 7] n_offset:-5 n_buckets:[4.1 5]}}`,
},
} {
t.Run(test.name, func(t *testing.T) {
expression := test.input.TestExpression()