app/vmalert: fix flaky ut TestRecordingRule_Exec

The order of stale metrics can't be controlled in recording rule, only
use two time series then.
This commit is contained in:
Hui Wang 2024-11-14 22:30:39 +08:00 committed by f41gh7
parent fdd00b8268
commit db6b612b68
No known key found for this signature in database
GPG key ID: 4558311CF775EC72

View file

@ -30,10 +30,10 @@ func TestRecordingRule_Exec(t *testing.T) {
} }
tss, err := rule.exec(context.TODO(), ts, 0) tss, err := rule.exec(context.TODO(), ts, 0)
if err != nil { if err != nil {
t.Fatalf("unexpected RecordingRule.exec error: %s", err) t.Fatalf("fail to test rule %s: unexpected error: %s", rule.Name, err)
} }
if err := compareTimeSeries(t, tssExpected[i], tss); err != nil { if err := compareTimeSeries(t, tssExpected[i], tss); err != nil {
t.Fatalf("time series mismatch: %s", err) t.Fatalf("fail to test rule %s: time series mismatch on step %d: %s", rule.Name, i, err)
} }
ts = ts.Add(defaultStep) ts = ts.Add(defaultStep)
@ -59,7 +59,6 @@ func TestRecordingRule_Exec(t *testing.T) {
{ {
metricWithValueAndLabels(t, 1, "__name__", "foo", "job", "foo"), metricWithValueAndLabels(t, 1, "__name__", "foo", "job", "foo"),
metricWithValueAndLabels(t, 2, "__name__", "bar", "job", "bar"), metricWithValueAndLabels(t, 2, "__name__", "bar", "job", "bar"),
metricWithValueAndLabels(t, 3, "__name__", "baz", "job", "baz"),
}, },
{ {
metricWithValueAndLabels(t, 10, "__name__", "foo", "job", "foo"), metricWithValueAndLabels(t, 10, "__name__", "foo", "job", "foo"),
@ -67,7 +66,8 @@ func TestRecordingRule_Exec(t *testing.T) {
{ {
metricWithValueAndLabels(t, 10, "__name__", "foo", "job", "bar"), metricWithValueAndLabels(t, 10, "__name__", "foo", "job", "bar"),
}, },
}, [][]prompbmarshal.TimeSeries{{ }, [][]prompbmarshal.TimeSeries{
{
newTimeSeries([]float64{1}, []int64{ts.UnixNano()}, []prompbmarshal.Label{ newTimeSeries([]float64{1}, []int64{ts.UnixNano()}, []prompbmarshal.Label{
{ {
Name: "__name__", Name: "__name__",
@ -88,16 +88,6 @@ func TestRecordingRule_Exec(t *testing.T) {
Value: "bar", Value: "bar",
}, },
}), }),
newTimeSeries([]float64{3}, []int64{ts.UnixNano()}, []prompbmarshal.Label{
{
Name: "__name__",
Value: "foobarbaz",
},
{
Name: "job",
Value: "baz",
},
}),
}, },
{ {
newTimeSeries([]float64{10}, []int64{ts.Add(defaultStep).UnixNano()}, []prompbmarshal.Label{ newTimeSeries([]float64{10}, []int64{ts.Add(defaultStep).UnixNano()}, []prompbmarshal.Label{
@ -110,7 +100,7 @@ func TestRecordingRule_Exec(t *testing.T) {
Value: "foo", Value: "foo",
}, },
}), }),
// other series are with NaN values // stale time series
newTimeSeries([]float64{decimal.StaleNaN}, []int64{ts.Add(defaultStep).UnixNano()}, []prompbmarshal.Label{ newTimeSeries([]float64{decimal.StaleNaN}, []int64{ts.Add(defaultStep).UnixNano()}, []prompbmarshal.Label{
{ {
Name: "__name__", Name: "__name__",
@ -121,16 +111,6 @@ func TestRecordingRule_Exec(t *testing.T) {
Value: "bar", Value: "bar",
}, },
}), }),
newTimeSeries([]float64{decimal.StaleNaN}, []int64{ts.Add(defaultStep).UnixNano()}, []prompbmarshal.Label{
{
Name: "__name__",
Value: "foobarbaz",
},
{
Name: "job",
Value: "baz",
},
}),
}, },
{ {
newTimeSeries([]float64{10}, []int64{ts.Add(2 * defaultStep).UnixNano()}, []prompbmarshal.Label{ newTimeSeries([]float64{10}, []int64{ts.Add(2 * defaultStep).UnixNano()}, []prompbmarshal.Label{