mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-07-24 01:31:20 +03:00
### Describe Your Changes Fixed #9900 relax the validation for the labels text area. It now accepts input labels without being enclosed in curly braces. The following input format should be supported now: ``` metric_name metric_name{label1="value1"} {__name__="metric_name", label1="value1"} __name__="metric_name", label1="value1" label1="value1" ``` ### Checklist The following checks are **mandatory**: - [x] My change adheres to [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/victoriametrics/contributing/#pull-request-checklist). - [x] My change adheres to [VictoriaMetrics development goals](https://docs.victoriametrics.com/victoriametrics/goals/). --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Max Kotliar <mkotlyar@victoriametrics.com>
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package promrelabel
|
|
|
|
import (
|
|
"bytes"
|
|
"html"
|
|
"testing"
|
|
|
|
"github.com/valyala/fastjson"
|
|
)
|
|
|
|
// TestWriteRelabelDebugSupportFormats verifies the relabeling debug input, rules and output.
|
|
func TestWriteRelabelDebugSupportFormats(t *testing.T) {
|
|
f := func(input, rule, expect string) {
|
|
// execute
|
|
outputWriter := bytes.NewBuffer(nil)
|
|
writeRelabelDebug(outputWriter, false, "", input, rule, "json", nil)
|
|
|
|
// the response is in JSON with HTML content, extract the `resultingLabels` in JSON and unescape it.
|
|
resultingLabels := fastjson.GetString(outputWriter.Bytes(), `resultingLabels`)
|
|
resultingLabels = html.UnescapeString(resultingLabels)
|
|
|
|
// verify
|
|
if resultingLabels != expect {
|
|
t.Fatalf(`expected "%s", got "%s"`, expect, resultingLabels)
|
|
}
|
|
}
|
|
|
|
// test pure parsing
|
|
// ruleTestParsing rule should NOT drop anything. it should ask `writeRelabelDebug` to respond with whatever the input is (after parsing).
|
|
ruleTestParsing := `
|
|
- action: labeldrop
|
|
regex: "a_not_exist_label"
|
|
`
|
|
f(`metric_name`, ruleTestParsing, `metric_name`)
|
|
f(`metric_name{label1="value1"}`, ruleTestParsing, `metric_name{label1="value1"}`)
|
|
f(`{__name__="metric_name", label1="value1"}`, ruleTestParsing, `metric_name{label1="value1"}`)
|
|
f(`__name__="metric_name", label1="value1"`, ruleTestParsing, `metric_name{label1="value1"}`)
|
|
f(`_name__="metric_name"`, ruleTestParsing, `{_name__="metric_name"}`)
|
|
|
|
// special case: incorrect input format
|
|
f(`{_name__="metric_name"`, ruleTestParsing, ``)
|
|
f(`_name__="metric_name}"`, ruleTestParsing, ``)
|
|
f(`metrics_name}"`, ruleTestParsing, ``)
|
|
}
|