MCPcopy Index your code
hub / github.com/prometheus/prometheus / EngineQueryFunc

Function EngineQueryFunc

rules/manager.go:50–75  ·  view source on GitHub ↗

EngineQueryFunc returns a new query function that executes instant queries against the given engine. It converts scalar into vector results.

(engine promql.QueryEngine, q storage.Queryable)

Source from the content-addressed store, hash-verified

48// the given engine.
49// It converts scalar into vector results.
50func EngineQueryFunc(engine promql.QueryEngine, q storage.Queryable) QueryFunc {
51 return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) {
52 q, err := engine.NewInstantQuery(ctx, q, nil, qs, t)
53 if err != nil {
54 return nil, err
55 }
56 defer q.Close()
57
58 res := q.Exec(ctx)
59 if res.Err != nil {
60 return nil, res.Err
61 }
62 switch v := res.Value.(type) {
63 case promql.Vector:
64 return v, nil
65 case promql.Scalar:
66 return promql.Vector{promql.Sample{
67 T: v.T,
68 F: v.V,
69 Metric: labels.Labels{},
70 }}, nil
71 default:
72 return nil, errors.New("rule result is not a vector or scalar")
73 }
74 }
75}
76
77// DefaultEvalIterationFunc is the default implementation of
78// GroupEvalIterationFunc that is periodically invoked to evaluate the rules

Callers 15

mainFunction · 0.92
testMethod · 0.92
consolesMethod · 0.92
CreateRuleGroupsMethod · 0.92
TestAlertingRuleLimitFunction · 0.85
TestKeepFiringForFunction · 0.85

Calls 3

NewInstantQueryMethod · 0.65
CloseMethod · 0.65
ExecMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…