Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Main (unreleased)

- Allow configuration of `force_attempt_http2` and default it to `true` for otelcol exporters with HTTP client configurations. (@dehaansa)

- Fix default values for relabel rules, this caused issues in e.g. `prometheus.operator.servicemonitors` when using labeldrop. (@kalleep)

v1.12.0
-----------------

Expand Down
9 changes: 6 additions & 3 deletions internal/component/common/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,12 @@ func doRelabel(cfg *Config, lb LabelBuilder) (keep bool) {
func ComponentToPromRelabelConfigs(rcs []*Config) []*relabel.Config {
res := make([]*relabel.Config, len(rcs))
for i, rc := range rcs {
sourceLabels := make([]model.LabelName, len(rc.SourceLabels))
for i, sl := range rc.SourceLabels {
sourceLabels[i] = model.LabelName(sl)
var sourceLabels []model.LabelName
if len(rc.SourceLabels) > 0 {
sourceLabels = make([]model.LabelName, len(rc.SourceLabels))
for i, sl := range rc.SourceLabels {
sourceLabels[i] = model.LabelName(sl)
}
}

res[i] = &relabel.Config{
Expand Down
17 changes: 17 additions & 0 deletions internal/component/common/relabel/relabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
"fmt"
"testing"

"github.com/grafana/alloy/syntax"
"github.com/grafana/regexp"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/util/testutil"
)
Expand Down Expand Up @@ -857,6 +859,21 @@ func BenchmarkRelabel(b *testing.B) {
}
}

func TestComponentToPromRelabelConfigs(t *testing.T) {
rule := `
action = "labeldrop"
regex = "helm_sh_chart"
`

var cfg Config
require.NoError(t, syntax.Unmarshal([]byte(rule), &cfg))

converted := ComponentToPromRelabelConfigs([]*Config{&cfg})
for _, r := range converted {
require.NoError(t, r.Validate(model.LegacyValidation))
}
}

// MustNewRegexp works like NewRegexp, but panics if the regular expression does not compile.
func MustNewRegexp(s string) Regexp {
re, err := NewRegexp(s)
Expand Down
Loading