2024-03-04 23:45:22 +01:00
|
|
|
package streamaggr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeduplicator(t *testing.T) {
|
|
|
|
var tssResult []prompbmarshal.TimeSeries
|
|
|
|
var tssResultLock sync.Mutex
|
|
|
|
pushFunc := func(tss []prompbmarshal.TimeSeries) {
|
|
|
|
tssResultLock.Lock()
|
|
|
|
tssResult = appendClonedTimeseries(tssResult, tss)
|
|
|
|
tssResultLock.Unlock()
|
|
|
|
}
|
|
|
|
|
2024-07-03 15:10:09 +02:00
|
|
|
offsetMsecs := time.Now().UnixMilli()
|
|
|
|
tss := prompbmarshal.MustParsePromMetrics(`
|
2024-03-04 23:45:22 +01:00
|
|
|
foo{instance="x",job="aaa",pod="sdfd-dfdfdfs",node="aosijjewrerfd",namespace="asdff",container="ohohffd"} 123
|
|
|
|
bar{instance="x",job="aaa",pod="sdfd-dfdfdfs",node="aosijjewrerfd",namespace="asdff",container="ohohffd"} 34.54
|
2024-03-17 20:37:14 +01:00
|
|
|
x 8943 1000
|
2024-03-04 23:45:22 +01:00
|
|
|
baz_aaa_aaa_fdd{instance="x",job="aaa",pod="sdfd-dfdfdfs",node="aosijjewrerfd",namespace="asdff",container="ohohffd"} -34.34
|
2024-03-17 20:37:14 +01:00
|
|
|
x 90984 900
|
|
|
|
x 433 1000
|
2024-03-04 23:45:22 +01:00
|
|
|
asfjkldsf{instance="x",job="aaa",pod="sdfd-dfdfdfs",node="aosijjewrerfd",namespace="asdff",container="ohohffd"} 12322
|
|
|
|
foo{instance="x",job="aaa",pod="sdfd-dfdfdfs",node="aosijjewrerfd",namespace="asdff",container="ohohffd"} 894
|
|
|
|
baz_aaa_aaa_fdd{instance="x",job="aaa",pod="sdfd-dfdfdfs",node="aosijjewrerfd",namespace="asdff",container="ohohffd"} -2.3
|
2024-07-03 15:10:09 +02:00
|
|
|
`, offsetMsecs)
|
2024-03-04 23:45:22 +01:00
|
|
|
|
2024-07-01 14:56:17 +02:00
|
|
|
d := NewDeduplicator(pushFunc, time.Hour, []string{"node", "instance"}, "global")
|
2024-03-04 23:45:22 +01:00
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
d.Push(tss)
|
|
|
|
}
|
2024-03-05 01:13:21 +01:00
|
|
|
d.flush(pushFunc, time.Hour)
|
2024-03-04 23:45:22 +01:00
|
|
|
d.MustStop()
|
|
|
|
|
|
|
|
result := timeSeriessToString(tssResult)
|
2024-03-05 01:13:21 +01:00
|
|
|
resultExpected := `asfjkldsf{container="ohohffd",job="aaa",namespace="asdff",pod="sdfd-dfdfdfs"} 12322
|
|
|
|
bar{container="ohohffd",job="aaa",namespace="asdff",pod="sdfd-dfdfdfs"} 34.54
|
|
|
|
baz_aaa_aaa_fdd{container="ohohffd",job="aaa",namespace="asdff",pod="sdfd-dfdfdfs"} -2.3
|
|
|
|
foo{container="ohohffd",job="aaa",namespace="asdff",pod="sdfd-dfdfdfs"} 894
|
2024-03-17 20:37:14 +01:00
|
|
|
x 8943
|
2024-03-04 23:45:22 +01:00
|
|
|
`
|
|
|
|
if result != resultExpected {
|
|
|
|
t.Fatalf("unexpected result; got\n%s\nwant\n%s", result, resultExpected)
|
|
|
|
}
|
|
|
|
}
|