Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine: add annotation if we trigger promql fallback #334

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions engine/annotations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package engine

import (
"context"
"fmt"

"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/util/annotations"
)

var (
//lint:ignore faillint - this format is expected for caching and other consumers
TriggeredPromQLFallback = fmt.Errorf("%w: query triggered fallback in thanos engine", annotations.PromQLInfo)
)

type annotatedQuery struct {
promql.Query

annotations annotations.Annotations
}

func (q annotatedQuery) Exec(ctx context.Context) *promql.Result {
res := q.Query.Exec(ctx)

res.Warnings = res.Warnings.Merge(q.annotations)

return res
}

func fallbackAnnotatedQuery(q promql.Query) promql.Query {
return annotatedQuery{
Query: q,
annotations: annotations.New().Add(TriggeredPromQLFallback),
}
}
6 changes: 4 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ func (e *compatibilityEngine) NewInstantQuery(ctx context.Context, q storage.Que
exec, err := execution.New(lplan.Expr(), q, qOpts)
if e.triggerFallback(err) {
e.metrics.queries.WithLabelValues("true").Inc()
return e.prom.NewInstantQuery(ctx, q, opts, qs, ts)
query, err := e.prom.NewInstantQuery(ctx, q, opts, qs, ts)
return fallbackAnnotatedQuery(query), err
}
e.metrics.queries.WithLabelValues("false").Inc()
if err != nil {
Expand Down Expand Up @@ -362,7 +363,8 @@ func (e *compatibilityEngine) NewRangeQuery(ctx context.Context, q storage.Query
exec, err := execution.New(lplan.Expr(), q, qOpts)
if e.triggerFallback(err) {
e.metrics.queries.WithLabelValues("true").Inc()
return e.prom.NewRangeQuery(ctx, q, opts, qs, start, end, step)
query, err := e.prom.NewRangeQuery(ctx, q, opts, qs, start, end, step)
return fallbackAnnotatedQuery(query), err
}
e.metrics.queries.WithLabelValues("false").Inc()
if err != nil {
Expand Down
Loading