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

Add Content-Type header on query-frontend paths #1306

Merged
merged 3 commits into from
Feb 24, 2022

Conversation

wperron
Copy link
Contributor

@wperron wperron commented Feb 23, 2022

This commit adds the Content-Type header on the read paths of the Query Frontend.

Fixes #1185

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Copy link
Member

@joe-elliott joe-elliott left a comment

Choose a reason for hiding this comment

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

Thanks for taking a swing at this. "Content Negotation" is pretty rough in Tempo and I'm impressed with all the things you were able to find and correct.

I think the part that most concerns me is the way the the trace by id path works.

  • frontend.go - force sets Accepts to protobuf
  • tracebyidsharding.go - assumes that whatever it gets is protobuf b/c of something that happened in frontend.go

I know you didn't create this problem, but perhaps we could iron it out just a little bit? Thoughts on how we could clean this up?

Header: http.Header{},
StatusCode: http.StatusOK,
Header: http.Header{
api.HeaderContentType: {api.HeaderAcceptProtobuf},
Copy link
Member

Choose a reason for hiding this comment

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

it's weird that we assume protobuf here b/c of a header that was set in frontend.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not, the Trace Sharder only ever sends a protobuf message, it's then unmarshalled and re-marshalled back into either protobuf or json in the frontend.go in the newTraceByIDMiddleware function here

Copy link
Member

Choose a reason for hiding this comment

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

My bad, I meant it's weird we assume that the data received in the trace by id sharder (from the querier) is proto, but the only reason it is proto is because a header that's set in frontend.go.

I think we should set the Accept for proto in tracebyidsharding.go since that code also assumes that the returned data is proto. But these gross corners have been around for long before you made this improvement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see! I assumed this was intentional after reading the comment on that same line you linked, I guess it kinda make sense to keep content negotiation as close the edge as possible? Then again if internal communication is expected to be only protobuf, then setting the Accept header might just be superfluous 🤷

@@ -193,6 +193,7 @@ func (q *Querier) SearchHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set(api.HeaderContentType, api.HeaderAcceptJSON)
Copy link
Member

Choose a reason for hiding this comment

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

set content type in TraceByIDHandler as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mhm, that's a good point 🤔 The TraceByID path is a bit odd because eventually it all reaches the newTraceByIdMiddleware in frontend.go where the payload is serialized according to the Accept header. I had to modify the tracebyidsharding.go because the tests weren't passing, but as it is, the tests are all passing. So while it would make sense to also add it to the TraceByIDHandler I also don't know if it'll make any practical difference.

Copy link
Member

@joe-elliott joe-elliott Feb 24, 2022

Choose a reason for hiding this comment

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

where the payload is serialized according to the Accept header

Sadly I think tracebyidsharding.go makes no checks and always assumes that the returned payload is proto. I don't expect a fix for that in this PR. It then uses the Accept header in frontend.go to determine how to marshal the response for the caller.

Since we are adding the Content-Type header to other responses here I would like to just slap it in the TraceByIDHandler as well, but don't feel obligated to adjust the frontend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

@joe-elliott
Copy link
Member

CI seems to be stuck? If you can resolve the changelog diff and push it will trigger it again.

Copy link
Member

@joe-elliott joe-elliott left a comment

Choose a reason for hiding this comment

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

This looks good. We've been having trouble with Github Actions CI lately. So once that passes we will merge.

Thanks!

@joe-elliott joe-elliott merged commit 3daf917 into grafana:main Feb 24, 2022
@wperron wperron deleted the query-frontend-content-type branch February 24, 2022 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Endpoints are missing a content-type header
2 participants