fix(native): Change content type of endpoint /v1/info/metrics based on accept header#26639
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEndpoint /v1/info/metrics now returns metrics with a text/plain Content-Type using ResponseBuilder, and a new MIME type constant has been introduced. Sequence diagram for /v1/info/metrics response handling with updated Content-TypesequenceDiagram
participant Client
participant PrestoServer
participant "BaseStatsReporter"
participant ResponseHandler
Client->>PrestoServer: GET /v1/info/metrics
PrestoServer->>"BaseStatsReporter": fetchMetrics()
"BaseStatsReporter"-->>PrestoServer: metrics (text format)
PrestoServer->>ResponseHandler: Build response
Note right of PrestoServer: Sets Content-Type: text/plain
ResponseHandler-->>Client: 200 OK, metrics (text/plain)
Class diagram for updated HTTP constantsclassDiagram
class HttpConstants {
+kMimeTypeApplicationJson : const char[]
+kMimeTypeApplicationThrift : const char[]
+kMimeTypeTextPlain : const char[]
+kShuttingDown : const char[]
+kPrestoInternalBearer : const char[]
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
512a2e0 to
701ae84
Compare
| downstream, | ||
| folly::Singleton<velox::BaseStatsReporter>::try_get() | ||
| ->fetchMetrics()); | ||
| proxygen::ResponseBuilder(downstream) |
There was a problem hiding this comment.
You could add a new helper function along with the other sendOk functions.
sendOkTextResponse. PrestoC++ doesn't have too many possible content types.
There was a problem hiding this comment.
@czentgr Thanks for the review. I have added the helper function.
701ae84 to
db517e8
Compare
aditi-pandit
left a comment
There was a problem hiding this comment.
@nmahadevuni : Thanks for this code.
Is it possible to add some test logic in PrometheusReporterTest ?
I'm trying to assess the impact of this solution. While its definitely okay to return text/plain content type, application/json would likely be the more suited format for the metrics. Though I also read that Prometheus prefers text/plain. Is there a way to customize this based on the specific StatsReporter ? I'm concerned that Meta/Uber prefer tools that prefer as application/json over text/plain.
@amitkdutta : Please can you tell us if this change is okay for Meta production.
db517e8 to
6051d88
Compare
|
Thanks @aditi-pandit for the review. I have modified the response content type based on the request's ACCEPT header value. Also added test in new file |
33a7b84 to
c73f578
Compare
czentgr
left a comment
There was a problem hiding this comment.
How does this differ to the Java Prometheus endpoint?
Can we update the description that the mime type returned is dependent on the ACCEPT request header? I assume this is what's being sent by the prometheus server in when it complains about the response mime type?
Either way, the body will be the "text format" from the Prometheus library.
I don't see the same endpoint implemented in Java. Yes, prometheus sends ACCEPT header. And the response body will be text format in any case. |
aditi-pandit
left a comment
There was a problem hiding this comment.
Thanks @nmahadevuni.
I'm more comfortable with this code change. Have a comment about the test.
There was a problem hiding this comment.
On second thoughts this test doesn't really exercise any actual server code-path as such so its not worth it. We can remove it.
0b5bb2c to
d6719eb
Compare
aditi-pandit
left a comment
There was a problem hiding this comment.
Thanks @nmahadevuni
d6719eb to
696df6e
Compare
Thanks for the review @aditi-pandit |
aditi-pandit
left a comment
There was a problem hiding this comment.
Thanks @nmahadevuni
Description
Modifies the Content-Type of endpoint
/v1/info/metricstoapplication/jsonortext/plainbased on the request's ACCEPT header.Motivation and Context
Earlier Prometheus versions were not strict about Content-Type header in the response for this endpoint which is currently
application/json. Latest version requires it to be set correctly to what's expected by Prometheus while scraping the metrics which istext/plainImpact
Changes the Content-Type of endpoint
/v1/info/metricsfromapplication/jsontotext/plain.Test Plan
Tested manually running Prometheus in Docker and reproduced the error when Content-Type was set to json. Issue is fixed as shown in 2nd image below.