|
|
|
@ -157,24 +157,30 @@ func TestRecordingRuleLimit(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestRecordingEvalWithOrigin checks that the recording rule details are passed through the context.
|
|
|
|
|
func TestRecordingEvalWithOrigin(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
|
|
const name = "my-recording-rule"
|
|
|
|
|
const query = `count(metric{foo="bar"})`
|
|
|
|
|
const (
|
|
|
|
|
name = "my-recording-rule"
|
|
|
|
|
query = `count(metric{foo="bar"})`
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var detail RuleDetail
|
|
|
|
|
var (
|
|
|
|
|
detail RuleDetail
|
|
|
|
|
lbs = labels.FromStrings("foo", "bar")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
expr, err := parser.ParseExpr(query)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
rule := NewRecordingRule(name, expr, []labels.Label{})
|
|
|
|
|
rule := NewRecordingRule(name, expr, lbs)
|
|
|
|
|
_, err = rule.Eval(ctx, now, func(ctx context.Context, qs string, _ time.Time) (promql.Vector, error) {
|
|
|
|
|
detail = FromOriginContext(ctx)
|
|
|
|
|
return nil, nil
|
|
|
|
|
}, nil, 0)
|
|
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Equal(t, detail, NewRuleDetail(name, query, KindRecording))
|
|
|
|
|
require.Equal(t, detail, NewRuleDetail(rule))
|
|
|
|
|
}
|
|
|
|
|