Skip to content

Commit

Permalink
Fix relabel processed bug (#2394)
Browse files Browse the repository at this point in the history
* Fix issue where alloy_prometheus_relabel_metrics_processed was not being incremented.

* Add unit tests
  • Loading branch information
mattdurham authored Jan 13, 2025
1 parent 5f5c09e commit 3270530
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------

Expand Down
2 changes: 2 additions & 0 deletions internal/component/prometheus/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions internal/component/prometheus/relabel/relabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package relabel

import (
"fmt"
dto "github.com/prometheus/client_model/go"
"math"
"strconv"
"testing"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3270530

Please sign in to comment.