|
|
@ -14,6 +14,7 @@
|
|
|
|
package relabel
|
|
|
|
package relabel
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/prometheus/common/model"
|
|
|
|
"github.com/prometheus/common/model"
|
|
|
@ -575,6 +576,77 @@ func TestRelabel(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestRelabelValidate(t *testing.T) {
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
|
|
|
config Config
|
|
|
|
|
|
|
|
expected string
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
config: Config{},
|
|
|
|
|
|
|
|
expected: `relabel action cannot be empty`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
config: Config{
|
|
|
|
|
|
|
|
Action: Replace,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: `requires 'target_label' value`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
config: Config{
|
|
|
|
|
|
|
|
Action: Lowercase,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: `requires 'target_label' value`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
config: Config{
|
|
|
|
|
|
|
|
Action: Lowercase,
|
|
|
|
|
|
|
|
Replacement: DefaultRelabelConfig.Replacement,
|
|
|
|
|
|
|
|
TargetLabel: "${3}",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: `"${3}" is invalid 'target_label'`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
config: Config{
|
|
|
|
|
|
|
|
SourceLabels: model.LabelNames{"a"},
|
|
|
|
|
|
|
|
Regex: MustNewRegexp("some-([^-]+)-([^,]+)"),
|
|
|
|
|
|
|
|
Action: Replace,
|
|
|
|
|
|
|
|
Replacement: "${1}",
|
|
|
|
|
|
|
|
TargetLabel: "${3}",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
config: Config{
|
|
|
|
|
|
|
|
SourceLabels: model.LabelNames{"a"},
|
|
|
|
|
|
|
|
Regex: MustNewRegexp("some-([^-]+)-([^,]+)"),
|
|
|
|
|
|
|
|
Action: Replace,
|
|
|
|
|
|
|
|
Replacement: "${1}",
|
|
|
|
|
|
|
|
TargetLabel: "0${3}",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: `"0${3}" is invalid 'target_label'`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
config: Config{
|
|
|
|
|
|
|
|
SourceLabels: model.LabelNames{"a"},
|
|
|
|
|
|
|
|
Regex: MustNewRegexp("some-([^-]+)-([^,]+)"),
|
|
|
|
|
|
|
|
Action: Replace,
|
|
|
|
|
|
|
|
Replacement: "${1}",
|
|
|
|
|
|
|
|
TargetLabel: "-${3}",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: `"-${3}" is invalid 'target_label' for replace action`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
|
|
|
|
t.Run(fmt.Sprint(i), func(t *testing.T) {
|
|
|
|
|
|
|
|
err := test.config.Validate()
|
|
|
|
|
|
|
|
if test.expected == "" {
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
require.ErrorContains(t, err, test.expected)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestTargetLabelValidity(t *testing.T) {
|
|
|
|
func TestTargetLabelValidity(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
tests := []struct {
|
|
|
|
str string
|
|
|
|
str string
|
|
|
|