[v9.5.x] Alerting: Tiny refactor on the eval and schedule packages (#66133)

Alerting: Tiny refactor on the eval and schedule packages (#66130)

* Alerting: Tiny refactor on the eval and schedule packages

two very small things:

- We had a constructor on something called a `Context` which is not a `context.Context` so let's just name that constructor `NewContext`
- The user that we use to run query evaluations is the same (with some variation) abstract it to a function so that it can be re-used when necessary.

* Update pkg/services/ngalert/schedule/schedule.go

Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>

* Update pkg/services/ngalert/schedule/schedule.go

Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>

---------

Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>
(cherry picked from commit 1c3ce0735f)

Co-authored-by: gotjosh <josue.abreu@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2023-04-06 18:56:53 +03:00
committed by GitHub
co-authored by gotjosh
parent c9eff57efe
commit e47e901618
7 changed files with 32 additions and 24 deletions
+2 -2
View File
@@ -52,7 +52,7 @@ func (srv TestingApiSrv) RouteTestGrafanaRuleConfig(c *contextmodel.ReqContext,
Condition: body.GrafanaManagedCondition.Condition,
Data: queries,
}
ctx := eval.Context(c.Req.Context(), c.SignedInUser)
ctx := eval.NewContext(c.Req.Context(), c.SignedInUser)
conditionEval, err := srv.evaluator.Create(ctx, evalCond)
if err != nil {
@@ -128,7 +128,7 @@ func (srv TestingApiSrv) RouteEvalQueries(c *contextmodel.ReqContext, cmd apimod
if len(cmd.Data) > 0 {
cond.Condition = cmd.Data[0].RefID
}
evaluator, err := srv.evaluator.Create(eval.Context(c.Req.Context(), c.SignedInUser), cond)
evaluator, err := srv.evaluator.Create(eval.NewContext(c.Req.Context(), c.SignedInUser), cond)
if err != nil {
return ErrResp(http.StatusBadRequest, err, "Failed to build evaluator for queries and expressions")