Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relabel processed bug #2394

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading