-
Notifications
You must be signed in to change notification settings - Fork 66
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
automatically debug-log upstream http-response-sizes #1054
Conversation
b4f83e8
to
dbedd92
Compare
@wbrowne @marefr could you please take a look at this draft? it's based on our discussion about logging "upstream" response-sizes... this is not polished yet, i'd just like to know if i'm going in the right direction.. notes:
in general, WDYT? thanks! |
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.
I think this make sense with some minor changes.
After reviewing the code I just realized that we already have something like this in core grafana, see https://github.com/grafana/grafana/blob/main/pkg/infra/httpclient/count_bytes_reader.go and https://github.com/grafana/grafana/blob/ddee95cb6d737ba845380c89456ede9998e12f48/pkg/infra/httpclient/httpclientprovider/datasource_metrics_middleware.go#L115-L119. So I think it would make sense to move the count_bytes_reader.go to the SDK instead replacing your ReportSizeReader
if hasDatasourceTypeLabel { | ||
rt = newReportSizeRoundtripper(rt) | ||
} |
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.
You could put this logic in the middleware as well, see this example to get a hold of the options
return NamedMiddlewareFunc(BasicAuthenticationMiddlewareName, func(opts Options, next http.RoundTripper) http.RoundTripper { |
providerOpts.Middlewares = DefaultMiddlewares() |
One important thing is that this middleware should probably/maybe execute after the https://github.com/grafana/grafana-plugin-sdk-go/blob/main/backend/httpclient/max_bytes_reader.go so if a limit is in place your middleware isn't continuing to read the response to the end 🤷
One thing to consider might be to somehow share the response size reader between limit and reporting middlewares, but maybe something for the future.
dbedd92
to
750bca5
Compare
this was achieved by #1130 |
work in progress.