rules/manager.go
func EngineQueryFunc(engine *promql.Engine, q storage.Queryable) QueryFunc {
	return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) {
		q, err := engine.NewInstantQuery(q, qs, t)
		if err != nil {
			return nil, err
		}
		res := q.Exec(ctx)
		if res.Err != nil {
			return nil, res.Err
		}
		switch v := res.Value.(type) {
		case promql.Vector:
			return v, nil
		case promql.Scalar:
			return promql.Vector{promql.Sample{
				Point:  promql.Point(v),
				Metric: labels.Labels{},
			}}, nil
		default:
			return nil, errors.New("rule result is not a vector or scalar")
		}
	}
}
func EngineQueryFunc(engine *promql.Engine, q storage.Queryable) QueryFunc {
	return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) {
		q, err := engine.NewInstantQuery(q, qs, t)
		if err != nil {
			return nil, err
		}
		res := q.Exec(ctx)
		if res.Err != nil {
			return nil, res.Err
		}
		switch v := res.Value.(type) {
		case promql.Vector:
			return v, nil
		case promql.Scalar:
			return promql.Vector{promql.Sample{
				Point:  promql.Point(v),
				Metric: labels.Labels{},
			}}, nil
		default:
			return nil, errors.New("rule result is not a vector or scalar")
		}
	}
}
func EngineQueryFunc ( engine * promql . Engine , q storage . Queryable ) QueryFunc { return func ( ctx context . Context , qs string , t time . Time ) ( promql . Vector , error ) { q , err := engine . NewInstantQuery ( q , qs , t ) if err != nil { return nil , err } res := q . Exec ( ctx ) if res . Err != nil { return nil , res . Err } switch v := res . Value . ( type ) { case promql . Vector : return v , nil case promql . Scalar : return promql . Vector { promql . Sample { Point : promql . Point ( v ) , Metric : labels . Labels { } , } } , nil default : return nil , errors . New ( " " ) } } }
// EngineQueryFunc returns a new query function that executes instant queries against
// the given engine.
// It converts scalar into vector results.
EngineQueryFunc returns a new query function that executes instant queries against the given engine . It converts scalar into vector results .