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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

marefr
Copy link
Member

@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 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
Member 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


func setupAdapterContext(ctx context.Context, endpoint Endpoint) context.Context {
ctx = WithEndpoint(ctx, endpoint)
ctx = propagateTenantIDIfPresent(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason for not doing this propagateTenantIDIfPresent as a middleware too?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is running before protobuf request converted to SDK request. @wbrowne you see any risk changing this to middleware?

Copy link
Member

Choose a reason for hiding this comment

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

Nothing should be depending on this other than the instance providers (and it looks like the tracer), so it should be fine I think

ctx = WithPluginContext(ctx, pluginCtx)
ctx = WithUser(ctx, pluginCtx.User)
ctx = withContextualLogAttributes(ctx, pluginCtx)
ctx = WithUserAgent(ctx, pluginCtx.UserAgent)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there anything setting this now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this

func (h *MiddlewareHandler) setupContext(ctx context.Context, pluginCtx PluginContext, endpoint Endpoint) context.Context {
ctx = initErrorSource(ctx)
ctx = WithEndpoint(ctx, endpoint)
ctx = WithPluginContext(ctx, pluginCtx)
ctx = WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)
ctx = WithUser(ctx, pluginCtx.User)
ctx = WithUserAgent(ctx, pluginCtx.UserAgent)
return ctx
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔬 In review
Development

Successfully merging this pull request may close these issues.

3 participants