mirror of
https://github.com/prometheus/prometheus
synced 2024-12-23 15:04:13 +00:00
Add hashmod relabeling test with hasmod and a newline
Currently hashmod hashes all the labels, even if there is a newline. To ensure it still works in the future, let's add a test. Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
42a0e0acad
commit
22cfa10685
@ -233,6 +233,24 @@ func TestRelabel(t *testing.T) {
|
|||||||
"d": "976",
|
"d": "976",
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: labels.FromMap(map[string]string{
|
||||||
|
"a": "foo\nbar",
|
||||||
|
}),
|
||||||
|
relabel: []*Config{
|
||||||
|
{
|
||||||
|
SourceLabels: model.LabelNames{"a"},
|
||||||
|
TargetLabel: "b",
|
||||||
|
Separator: ";",
|
||||||
|
Action: HashMod,
|
||||||
|
Modulus: 1000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
output: labels.FromMap(map[string]string{
|
||||||
|
"a": "foo\nbar",
|
||||||
|
"b": "734",
|
||||||
|
}),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: labels.FromMap(map[string]string{
|
input: labels.FromMap(map[string]string{
|
||||||
"a": "foo",
|
"a": "foo",
|
||||||
@ -413,6 +431,22 @@ func TestRelabel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
// Setting default fields, mimicking the behaviour in Prometheus.
|
||||||
|
for _, cfg := range test.relabel {
|
||||||
|
if cfg.Action == "" {
|
||||||
|
cfg.Action = DefaultRelabelConfig.Action
|
||||||
|
}
|
||||||
|
if cfg.Separator == "" {
|
||||||
|
cfg.Separator = DefaultRelabelConfig.Separator
|
||||||
|
}
|
||||||
|
if cfg.Regex.original == "" {
|
||||||
|
cfg.Regex = DefaultRelabelConfig.Regex
|
||||||
|
}
|
||||||
|
if cfg.Replacement == "" {
|
||||||
|
cfg.Replacement = DefaultRelabelConfig.Replacement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res := Process(test.input, test.relabel...)
|
res := Process(test.input, test.relabel...)
|
||||||
require.Equal(t, test.output, res)
|
require.Equal(t, test.output, res)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user