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

Convert adapter utils to middlewares #1118

Merged
merged 4 commits into from
Oct 23, 2024
Merged

Convert adapter utils to middlewares #1118

merged 4 commits into from
Oct 23, 2024

Conversation

marefr
Copy link
Contributor

@marefr marefr commented Oct 17, 2024

What this PR does / why we need it:
Follow up from #1117 where I decided to put the convert adapter utils to middlewares in a separate PR. This converts common adapter logic to middlewares that can be reused between the SDK and Grafana.

Which issue(s) this PR fixes:
Ref #1101
Ref #1117

Special notes for your reviewer:

@marefr marefr self-assigned this Oct 17, 2024
@marefr marefr force-pushed the adapter_to_middlewares branch from 5261aee to 3570f36 Compare October 21, 2024 16:09
@marefr marefr marked this pull request as ready for review October 21, 2024 16:13
@marefr marefr requested a review from a team as a code owner October 21, 2024 16:13
@marefr marefr requested review from wbrowne, andresmgot and xnyo and removed request for a team October 21, 2024 16:13
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, a little to big to give a more meaningful review. I added some questions


var once = sync.Once{}

func metricWrapper(next handlerWrapperFunc) handlerWrapperFunc {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a bit confusing since the "tracingWrapper" got moved to a middleware in this PR but the rest aren't. I just saw that NewMetricsMiddleware, etc already exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it was added in #1117 as explained in the description. It was added so Grafana could start use it sooner rather than later given this is quite a lot of changes

@marefr marefr requested a review from andresmgot October 22, 2024 16:44
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! It looks like you covered everything. It'd be good to have another pair of eyes here, just in case, @wbrowne ?

Copy link
Member

@wbrowne wbrowne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

backend/serve.go Outdated
newTenantIDMiddleware(),
newContextualLoggerMiddleware(),
NewTracingMiddleware(tracing.DefaultTracer()),
NewMetricsMiddleware(prometheus.DefaultRegisterer, "grafana", false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the switch to use namespace = "grafana" and subsystem = "plugin" is virtually the same as the pre-existing namespace = "grafana_plugin"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly, but let me double check that 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used external plugin in local grafana with these changes and browsed the http://localhost:3000/metrics/plugins/<plugin id> and seems to work as expected 🎉

# HELP grafana_plugin_request_total The total amount of plugin requests
# TYPE grafana_plugin_request_total counter
grafana_plugin_request_total{endpoint="queryData",status="ok",status_source="plugin"} 2

Comment on lines +350 to +361
if opts.HandlerMiddlewares == nil {
opts.HandlerMiddlewares = make([]HandlerMiddleware, 0)
}

middlewares := defaultHandlerMiddlewares()
opts.HandlerMiddlewares = append(middlewares, opts.HandlerMiddlewares...)

pluginOpts, err := GRPCServeOpts(opts)
if err != nil {
return nil, err
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wbrowne since used in experimental/datasourcetest and by some external plugins, e.g. https://github.com/grafana/google-sheets-datasource/blob/fe8de66f07a9920dbec0ed07836d56850e7ed8bc/pkg/googlesheets/datasource_test.go#L11, adding the default middlewares here. Does this make sense? Tests passes now at least.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense to me!

@marefr marefr merged commit 850229a into main Oct 23, 2024
2 of 3 checks passed
@marefr marefr deleted the adapter_to_middlewares branch October 23, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants