From 25962112f112cdc8df5788f1901fc23d8e0986fc Mon Sep 17 00:00:00 2001 From: matt durham Date: Mon, 13 Jan 2025 09:48:20 -0500 Subject: [PATCH 1/2] Fix issue where alloy_prometheus_relabel_metrics_processed was not being incremented. --- CHANGELOG.md | 4 ++++ internal/component/prometheus/relabel/relabel.go | 2 ++ 2 files changed, 6 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 From 76d21b25159ad67d012e846dcb7452cc18be2d59 Mon Sep 17 00:00:00 2001 From: matt durham Date: Mon, 13 Jan 2025 09:56:08 -0500 Subject: [PATCH 2/2] Add unit tests --- .../component/prometheus/relabel/relabel_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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) {