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
Prometheus: Restore FromAlert header #55255
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package middleware | ||
|
||
import ( | ||
"net/http" | ||
|
||
sdkHTTPClient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient" | ||
) | ||
|
||
// ReqHeadersMiddleware is used so that we can pass req headers through the prometheus go client as it does not allow | ||
// access to the request directly. Should be used together with WithContextualMiddleware so that it is attached to | ||
// the context of each request with its unique headers. | ||
func ReqHeadersMiddleware(headers map[string]string) sdkHTTPClient.Middleware { | ||
return sdkHTTPClient.NamedMiddlewareFunc("prometheus-req-headers-middleware", func(opts sdkHTTPClient.Options, next http.RoundTripper) http.RoundTripper { | ||
return sdkHTTPClient.RoundTripperFunc(func(req *http.Request) (*http.Response, error) { | ||
for k, v := range headers { | ||
// As custom headers middleware is before contextual we may overwrite custom headers here with those | ||
// that came with the request which probably makes sense. | ||
req.Header[k] = []string{v} | ||
} | ||
|
||
return next.RoundTrip(req) | ||
}) | ||
}) | ||
} |
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.
Is this only for the
FromAlert
info? Out of curiosity why is it needed to send to prometheus? Could it be moved to infra code so that it is always sent downstream?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.
Only for the header. Since it was being sent, people have used it to load balance on. So they point their datasource at their LB and use the header to route differently.
Not sure I follow with moving to the infra code? This doesn't seem like the right way to fix it to me, but trying to undo the experienced regression for the user.
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.
Yep got it, this works so no issue in merging.
We are already handling headers in grafana backend in general by providing a HTTP client to datasource, so it does not have to be handled custom, which is why this code was removed. We may somehow move this to the HTTP client that is provided so that
FromAlert
header would be passed upstream for all datasources automatically if it is valuable in general.