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) {