mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
test(golang): add test to function addRowToTimeseries (#3282)
Co-authored-by: jplanckeel-externe <jplanckeel.externe@bedrockstreaming.com>
This commit is contained in:
parent
b8839df32c
commit
16fdd2af8a
1 changed files with 322 additions and 0 deletions
|
@ -465,6 +465,328 @@ func TestScrapeWorkScrapeInternalSuccess(t *testing.T) {
|
|||
`)
|
||||
}
|
||||
|
||||
func TestAddRowToTimeseries(t *testing.T) {
|
||||
f := func(r *parser.Row, cfg *ScrapeWork, needRelabel bool, dataExpected string) {
|
||||
t.Helper()
|
||||
|
||||
wc := &writeRequestCtx{}
|
||||
|
||||
timeseriesExpected := parseData(dataExpected)
|
||||
timestamp := int64(123000)
|
||||
|
||||
var sw scrapeWork
|
||||
sw.Config = cfg
|
||||
sw.addRowToTimeseries(wc, r, timestamp, needRelabel)
|
||||
|
||||
wr := wc.writeRequest
|
||||
|
||||
var expectEqualError error
|
||||
tsExpected := timeseriesExpected[:len(wr.Timeseries)]
|
||||
if err := expectEqualTimeseries(wr.Timeseries, tsExpected); err != nil {
|
||||
expectEqualError = fmt.Errorf("%w\ngot\n%v\nwant\n%v", err, wr.Timeseries, tsExpected)
|
||||
}
|
||||
if expectEqualError != nil {
|
||||
t.Fatalf("unexpected error: %s", expectEqualError)
|
||||
}
|
||||
}
|
||||
|
||||
//With HonorLabels=false
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{
|
||||
{
|
||||
Key: "a",
|
||||
Value: "f",
|
||||
},
|
||||
},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{},
|
||||
ExternalLabels: []prompbmarshal.Label{},
|
||||
HonorLabels: false,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="f"} 0 123
|
||||
`)
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "f",
|
||||
},
|
||||
},
|
||||
ExternalLabels: []prompbmarshal.Label{},
|
||||
HonorLabels: false,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="f"} 0 123
|
||||
`)
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{},
|
||||
ExternalLabels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "f",
|
||||
},
|
||||
},
|
||||
HonorLabels: false,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="f"} 0 123
|
||||
`)
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{
|
||||
{
|
||||
Key: "a",
|
||||
Value: "b",
|
||||
},
|
||||
},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "f",
|
||||
},
|
||||
},
|
||||
ExternalLabels: []prompbmarshal.Label{},
|
||||
HonorLabels: false,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="f",exported_a="b"} 0 123
|
||||
`)
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{
|
||||
{
|
||||
Key: "a",
|
||||
Value: "b",
|
||||
},
|
||||
},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{},
|
||||
ExternalLabels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "f",
|
||||
},
|
||||
},
|
||||
HonorLabels: false,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="f",exported_a="b"} 0 123
|
||||
`)
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "e",
|
||||
},
|
||||
},
|
||||
ExternalLabels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "f",
|
||||
},
|
||||
},
|
||||
HonorLabels: false,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="f",exported_a="e"} 0 123
|
||||
`)
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{
|
||||
{
|
||||
Key: "a",
|
||||
Value: "b",
|
||||
},
|
||||
},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "c",
|
||||
},
|
||||
},
|
||||
ExternalLabels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "d",
|
||||
},
|
||||
},
|
||||
HonorLabels: false,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="d",exported_a="c"} 0 123
|
||||
`)
|
||||
// With HonorLabels=true
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{
|
||||
{
|
||||
Key: "a",
|
||||
Value: "b",
|
||||
},
|
||||
},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "f",
|
||||
},
|
||||
},
|
||||
ExternalLabels: []prompbmarshal.Label{},
|
||||
HonorLabels: true,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="b"} 0 123
|
||||
`)
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{
|
||||
{
|
||||
Key: "a",
|
||||
Value: "b",
|
||||
},
|
||||
},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{},
|
||||
ExternalLabels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "f",
|
||||
},
|
||||
},
|
||||
HonorLabels: true,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="b"} 0 123
|
||||
`)
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "e",
|
||||
},
|
||||
},
|
||||
ExternalLabels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "f",
|
||||
},
|
||||
},
|
||||
HonorLabels: true,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="e"} 0 123
|
||||
`)
|
||||
f(
|
||||
&parser.Row{
|
||||
Metric: "metric",
|
||||
Tags: []parser.Tag{
|
||||
{
|
||||
Key: "a",
|
||||
Value: "b",
|
||||
},
|
||||
},
|
||||
Value: 0,
|
||||
Timestamp: int64(123000),
|
||||
},
|
||||
&ScrapeWork{
|
||||
ScrapeTimeout: time.Second * 42,
|
||||
Labels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "c",
|
||||
},
|
||||
},
|
||||
ExternalLabels: []prompbmarshal.Label{
|
||||
{
|
||||
Name: "a",
|
||||
Value: "d",
|
||||
},
|
||||
},
|
||||
HonorLabels: true,
|
||||
},
|
||||
false,
|
||||
`
|
||||
metric{a="b"} 0 123
|
||||
`)
|
||||
|
||||
}
|
||||
|
||||
func parseData(data string) []prompbmarshal.TimeSeries {
|
||||
var rows parser.Rows
|
||||
errLogger := func(s string) {
|
||||
|
|
Loading…
Reference in a new issue