From 53a5071a72ebf492ed9133f4d0f49fb7b4bbd17c Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar Date: Tue, 10 Jan 2023 19:07:24 +0530 Subject: [PATCH] rules: Support native histograms Signed-off-by: Ganesh Vernekar --- rules/manager.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rules/manager.go b/rules/manager.go index 4b9c8150a..1b7ef7494 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" + "github.com/prometheus/prometheus/model/histogram" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/rulefmt" "github.com/prometheus/prometheus/model/timestamp" @@ -668,7 +669,16 @@ func (g *Group) Eval(ctx context.Context, ts time.Time) { }() for _, s := range vector { - if _, err := app.Append(0, s.Metric, s.T, s.V); err != nil { + if s.H != nil { + // We assume that all native histogram results are gauge histograms. + // TODO(codesome): once PromQL can give the counter reset info, remove this assumption. + s.H.CounterResetHint = histogram.GaugeType + _, err = app.AppendHistogram(0, s.Metric, s.T, nil, s.H) + } else { + _, err = app.Append(0, s.Metric, s.T, s.V) + } + + if err != nil { rule.SetHealth(HealthBad) rule.SetLastError(err) sp.SetStatus(codes.Error, err.Error())