(ctx context.Context, engine promql.QueryEngine, q storage.Queryable, qs string, t time.Time)
| 194 | } |
| 195 | |
| 196 | func executeQuery(ctx context.Context, engine promql.QueryEngine, q storage.Queryable, qs string, t time.Time) (promql.Vector, error) { |
| 197 | qry, err := engine.NewInstantQuery(ctx, q, nil, qs, t) |
| 198 | if err != nil { |
| 199 | return nil, err |
| 200 | } |
| 201 | defer qry.Close() |
| 202 | |
| 203 | res := qry.Exec(ctx) |
| 204 | if res.Err != nil { |
| 205 | return nil, res.Err |
| 206 | } |
| 207 | |
| 208 | switch v := res.Value.(type) { |
| 209 | case promql.Vector: |
| 210 | return v, nil |
| 211 | case promql.Scalar: |
| 212 | return promql.Vector{promql.Sample{ |
| 213 | T: v.T, |
| 214 | F: v.V, |
| 215 | Metric: labels.Labels{}, |
| 216 | }}, nil |
| 217 | default: |
| 218 | return nil, errors.New("rule result is not a vector or scalar") |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | func wrapWithMiddleware(next QueryExecutor, overrides RulesLimits, userID string, lookbackDelta time.Duration) rules.QueryFunc { |
| 223 | return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) { |
no test coverage detected