-
Notifications
You must be signed in to change notification settings - Fork 557
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
Ensure the services status page renders as HTML #1265
Conversation
What content type gets set instead? Or is the browser just guessing? |
In "https://github.com/grafana/mimir/blob/204a2a316708dba2e7f70736e65bc1241a82fabd/pkg/mimir/status.go#L22"
|
This is the one
The browser is guessing. There is also a chance that JSON is requested and returned. But I think |
Oh wait, we should not let browser guess. I thought we set the content type in |
> Services’ status [seeing status information about more than one service]
3b56223
to
f8588ac
Compare
Looking another time at this: I think the browser never guessed. If nothing is set something in our stack seems to set it to So my proposed change is to remove Looking at the content-types before this PR:
And after:
This seems to fix all of those cases. |
w.Header().Set("Content-Type", "text/plain") | ||
w.Header().Set("Content-Type", "text/html; utf=8") |
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.
util.RenderHTTPResponse
will try to set the content-type to application/json if that was requested, but we've already sent a content-type here. Why do we need this content-type setting at all?
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.
RenderHTTPResponse
only sets JSON content type. I think we should pass "non-JSON" content type to it, so that RenderHTTPResponse
is always responsible for setting it.
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 just checked the response for the /store-gateway/tenants
, for example, which does not explicitly write the header, and the response contains the text/html content-type:
curl -I -XGET localhost:8080/store-gateway/tenants
HTTP/1.1 200 OK
Vary: Accept-Encoding
Date: Tue, 22 Mar 2022 09:22:40 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
So there's some kind of magic happening somewhere, I can recall that Golang detected the content type based on what the output looks like.
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.
Yes, see doc for Write
method of ResponseWriter
: https://pkg.go.dev/net/http#ResponseWriter
If the Header does not contain a Content-Type line, Write adds a Content-Type set to the result of passing the initial 512 bytes of written data to DetectContentType.
I don't think we should rely on it.
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 it's happening here:
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 don't think we should rely on it.
I think it's not critical and we can expect it to work properly when we're sending HTML, but if not, sure, we can always specify it explicitly.
Anyway, my main comment was that we shouldn't set the content type here prematurely.
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.
Anyway, my main comment was that we shouldn't set the content type here prematurely.
Agree.
@@ -396,7 +396,7 @@ func (a *API) RegisterQueryScheduler(f *scheduler.Scheduler) { | |||
// TODO: Refactor this code to be accomplished using the services.ServiceManager | |||
// or a future module manager #2291 | |||
func (a *API) RegisterServiceMapHandler(handler http.Handler) { | |||
a.indexPage.AddLink(SectionAdminEndpoints, "/services", "Service Status") | |||
a.indexPage.AddLink(SectionAdminEndpoints, "/services", "Service's status") |
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.
This needs to be rebased.
As Ursula pointed out, this page is listing the status information about more than one service, so this is the correct spelling. See: #1265 (comment) Signed-off-by: Oleg Zaytsev <[email protected]>
* Fix "Services' status" spelling As Ursula pointed out, this page is listing the status information about more than one service, so this is the correct spelling. See: #1265 (comment) Signed-off-by: Oleg Zaytsev <[email protected]> * Also fix the section header Signed-off-by: Oleg Zaytsev <[email protected]>
What this PR does
This removes the
text/plain
content type header from the services pageWhich issue(s) this PR fixes or relates to
This ensures the services page of Mimir renders as HTML. I have noticed that when testing the v2.0.0-rc.0
Checklist
[ ] Tests updated[ ] Documentation added[ ]CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]