From 57942244fd7da70723a279eaedeba5b3de3290fa Mon Sep 17 00:00:00 2001 From: George Krajcsovits Date: Tue, 17 Oct 2023 21:01:06 +0200 Subject: [PATCH] prometheus.remote_write: fix missing series ref mapping for native histogram (#5517) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: György Krajcsovits Co-authored-by: Paschalis Tsilias --- CHANGELOG.md | 4 +++- component/prometheus/remotewrite/remote_write.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79c6971b7ab9..74570c5389f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,7 +50,9 @@ Main (unreleased) permanently fail to load with `id already exists` error. (@mattdurham) - Allow the usage of encodings other than UTF8 to be used with environment variable expansion. (@mattdurham) - + +- Fixed an issue where native histogram time series were being dropped silently. (@krajorama) + ### Enhancements - The `loki.write` WAL now has snappy compression enabled by default. (@thepalbi) diff --git a/component/prometheus/remotewrite/remote_write.go b/component/prometheus/remotewrite/remote_write.go index f56f236dd3fb..40bcc20f495e 100644 --- a/component/prometheus/remotewrite/remote_write.go +++ b/component/prometheus/remotewrite/remote_write.go @@ -12,6 +12,7 @@ import ( "go.uber.org/atomic" "github.com/prometheus/prometheus/model/exemplar" + "github.com/prometheus/prometheus/model/histogram" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/metadata" @@ -109,6 +110,18 @@ func New(o component.Options, c Arguments) (*Component, error) { } return globalRef, nextErr }), + prometheus.WithHistogramHook(func(globalRef storage.SeriesRef, l labels.Labels, t int64, h *histogram.Histogram, fh *histogram.FloatHistogram, next storage.Appender) (storage.SeriesRef, error) { + if res.exited.Load() { + return 0, fmt.Errorf("%s has exited", o.ID) + } + + localID := prometheus.GlobalRefMapping.GetLocalRefID(res.opts.ID, uint64(globalRef)) + newRef, nextErr := next.AppendHistogram(storage.SeriesRef(localID), l, t, h, fh) + if localID == 0 { + prometheus.GlobalRefMapping.GetOrAddLink(res.opts.ID, uint64(newRef), l) + } + return globalRef, nextErr + }), prometheus.WithMetadataHook(func(globalRef storage.SeriesRef, l labels.Labels, m metadata.Metadata, next storage.Appender) (storage.SeriesRef, error) { if res.exited.Load() { return 0, fmt.Errorf("%s has exited", o.ID)