From 3270530d85207d36c29417b7f1b38af65f82b265 Mon Sep 17 00:00:00 2001 From: mattdurham Date: Mon, 13 Jan 2025 10:16:23 -0500 Subject: [PATCH] Fix relabel processed bug (#2394) * Fix issue where alloy_prometheus_relabel_metrics_processed was not being incremented. * Add unit tests --- CHANGELOG.md | 4 ++++ internal/component/prometheus/relabel/relabel.go | 2 ++ .../component/prometheus/relabel/relabel_test.go | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4f1a41b49..1169b4c247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ Main (unreleased) - Add support for TLS to `prometheus.write.queue`. (@mattdurham) +### Bugfixes + +- Fix issue where `alloy_prometheus_relabel_metrics_processed` was not being incremented. (@mattdurham) + v1.6.0-rc.0 ----------------- diff --git a/internal/component/prometheus/relabel/relabel.go b/internal/component/prometheus/relabel/relabel.go index 69c579190a..425440845b 100644 --- a/internal/component/prometheus/relabel/relabel.go +++ b/internal/component/prometheus/relabel/relabel.go @@ -243,6 +243,8 @@ func (c *Component) relabel(val float64, lbls labels.Labels) labels.Labels { c.mut.RLock() defer c.mut.RUnlock() + c.metricsProcessed.Inc() + globalRef := c.ls.GetOrAddGlobalRefID(lbls) var ( relabelled labels.Labels diff --git a/internal/component/prometheus/relabel/relabel_test.go b/internal/component/prometheus/relabel/relabel_test.go index 190a881542..cfa7962cb3 100644 --- a/internal/component/prometheus/relabel/relabel_test.go +++ b/internal/component/prometheus/relabel/relabel_test.go @@ -2,6 +2,7 @@ package relabel import ( "fmt" + dto "github.com/prometheus/client_model/go" "math" "strconv" "testing" @@ -111,6 +112,17 @@ func TestLRUNaN(t *testing.T) { require.True(t, relabeller.cache.Len() == 0) } +func TestMetrics(t *testing.T) { + relabeller := generateRelabel(t) + lbls := labels.FromStrings("__address__", "localhost") + + relabeller.relabel(0, lbls) + m := &dto.Metric{} + err := relabeller.metricsProcessed.Write(m) + require.NoError(t, err) + require.True(t, *(m.Counter.Value) == 1) +} + func BenchmarkCache(b *testing.B) { ls := labelstore.New(nil, prom.DefaultRegisterer) fanout := prometheus.NewInterceptor(nil, ls, prometheus.WithAppendHook(func(ref storage.SeriesRef, l labels.Labels, _ int64, _ float64, _ storage.Appender) (storage.SeriesRef, error) {