-
Notifications
You must be signed in to change notification settings - Fork 550
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
Mimir query engine: add HTTP header to force use of Prometheus' engine #8454
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7c97c10
Add support for falling back to Prometheus' engine by setting a HTTP …
charleskorn ffecb62
Propagate header from query-frontend to querier
charleskorn 4b239de
Send a Prometheus API-style JSON-encoded response when an invalid hea…
charleskorn d5d5fad
Add changelog entry
charleskorn 0356324
Rename type to make linter happy
charleskorn ef55390
Address PR feedback: make name clearer
charleskorn 28c4bc2
Address PR feedback: don't awkwardly use NotSupportedError
charleskorn 4f4b1c7
Merge branch 'main' into charleskorn/fallback-with-http-header
charleskorn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
package compat | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
apierror "github.com/grafana/mimir/pkg/api/error" | ||
) | ||
|
||
type engineFallbackContextKey int | ||
|
||
const forceFallbackEnabledContextKey = engineFallbackContextKey(0) | ||
const ForceFallbackHeaderName = "X-Mimir-Force-Prometheus-Engine" | ||
|
||
type EngineFallbackInjector struct{} | ||
|
||
func (i EngineFallbackInjector) Wrap(handler http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if value := r.Header.Get(ForceFallbackHeaderName); value != "" { | ||
if value != "true" { | ||
// Send a Prometheus API-style JSON error response. | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusBadRequest) | ||
e := apierror.Newf(apierror.TypeBadData, "invalid value '%s' for '%s' header, must be exactly 'true' or not set", value, ForceFallbackHeaderName) | ||
|
||
if body, err := e.EncodeJSON(); err == nil { | ||
_, _ = w.Write(body) | ||
} | ||
|
||
return | ||
} | ||
|
||
r = r.WithContext(withForceFallbackEnabled(r.Context())) | ||
} | ||
|
||
handler.ServeHTTP(w, r) | ||
}) | ||
} | ||
|
||
func withForceFallbackEnabled(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, forceFallbackEnabledContextKey, true) | ||
} | ||
|
||
func isForceFallbackEnabled(ctx context.Context) bool { | ||
return ctx.Value(forceFallbackEnabledContextKey) != nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit)
I don't know if I like using
NotSupportedError
here. It's not that the query is necessarily unsupported, but that we aren't going to use the query engine. Maybe we need an error class "MQEError" or something that NotSupportError and Fallback use?Similarly renaming
e.unsupportedQueries
to FallbackQueries or similar.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've dropped the awkward use of
NotSupportedError
in 28c4bc2.I've kept
unsupportedQueries
as-is for now - if it annoys us in the future, we can change it.