Skip to content

fix(native): Change content type of endpoint /v1/info/metrics based on accept header#26639

Merged
nmahadevuni merged 1 commit intoprestodb:masterfrom
nmahadevuni:native_fix_metrics_content_type
Dec 11, 2025
Merged

fix(native): Change content type of endpoint /v1/info/metrics based on accept header#26639
nmahadevuni merged 1 commit intoprestodb:masterfrom
nmahadevuni:native_fix_metrics_content_type

Conversation

@nmahadevuni
Copy link
Copy Markdown
Member

@nmahadevuni nmahadevuni commented Nov 17, 2025

Description

Modifies the Content-Type of endpoint /v1/info/metrics to application/json or text/plain based 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 is text/plain

Impact

Changes the Content-Type of endpoint /v1/info/metrics from application/json to text/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.

  1. Failing case
Screenshot 2025-11-17 at 3 43 10 PM
  1. Passing case
Screenshot 2025-11-17 at 3 49 58 PM
== RELEASE NOTES ==

General Changes
*  Fix to modify the Content-Type of endpoint /v1/info/metrics to application/json or text/plain based on the request's ACCEPT header

@nmahadevuni nmahadevuni requested review from a team as code owners November 17, 2025 10:21
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Nov 17, 2025
@prestodb-ci prestodb-ci requested review from a team, Dilli-Babu-Godari and Joe-Abraham and removed request for a team November 17, 2025 10:21
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Nov 17, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Endpoint /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-Type

sequenceDiagram
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)
Loading

Class diagram for updated HTTP constants

classDiagram
class HttpConstants {
  +kMimeTypeApplicationJson : const char[]
  +kMimeTypeApplicationThrift : const char[]
  +kMimeTypeTextPlain : const char[]
  +kShuttingDown : const char[]
  +kPrestoInternalBearer : const char[]
}
Loading

File-Level Changes

Change Details Files
Refactor metrics endpoint response to set text/plain content type
  • Replaced http::sendOkResponse with proxygen::ResponseBuilder
  • Set HTTP status to OK explicitly
  • Added Content-Type header with text/plain
  • Sent response body via sendWithEOM()
presto-native-execution/presto_cpp/main/PrestoServer.cpp
Introduce text/plain MIME type constant
  • Declared kMimeTypeTextPlain in HTTP constants
presto-native-execution/presto_cpp/main/http/HttpConstants.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@nmahadevuni nmahadevuni changed the title [native] Change content type of endpoint /v1/info/metrics to text/plain fix(native): Change content type of endpoint /v1/info/metrics to text/plain Nov 17, 2025
@nmahadevuni nmahadevuni force-pushed the native_fix_metrics_content_type branch from 512a2e0 to 701ae84 Compare November 17, 2025 10:27
@nmahadevuni
Copy link
Copy Markdown
Member Author

hi @yingsu00 @czentgr , Please review this.

downstream,
folly::Singleton<velox::BaseStatsReporter>::try_get()
->fetchMetrics());
proxygen::ResponseBuilder(downstream)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could add a new helper function along with the other sendOk functions.
sendOkTextResponse. PrestoC++ doesn't have too many possible content types.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@czentgr Thanks for the review. I have added the helper function.

@nmahadevuni nmahadevuni force-pushed the native_fix_metrics_content_type branch from 701ae84 to db517e8 Compare November 20, 2025 08:06
Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

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

@nmahadevuni nmahadevuni requested review from a team and majetideepak November 25, 2025 06:28
@nmahadevuni nmahadevuni force-pushed the native_fix_metrics_content_type branch from db517e8 to 6051d88 Compare December 2, 2025 13:28
@nmahadevuni
Copy link
Copy Markdown
Member Author

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 filePrestoServerAPITests.cpp which can be used to add any other server level API tests.

@nmahadevuni nmahadevuni force-pushed the native_fix_metrics_content_type branch 2 times, most recently from 33a7b84 to c73f578 Compare December 3, 2025 09:25
@nmahadevuni nmahadevuni changed the title fix(native): Change content type of endpoint /v1/info/metrics to text/plain fix(native): Change content type of endpoint /v1/info/metrics based on accept header Dec 3, 2025
Copy link
Copy Markdown
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

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.

@nmahadevuni
Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @nmahadevuni.

I'm more comfortable with this code change. Have a comment about the test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@nmahadevuni nmahadevuni force-pushed the native_fix_metrics_content_type branch 2 times, most recently from 0b5bb2c to d6719eb Compare December 10, 2025 07:18
aditi-pandit
aditi-pandit previously approved these changes Dec 10, 2025
Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @nmahadevuni

@nmahadevuni
Copy link
Copy Markdown
Member Author

Thanks @nmahadevuni

Thanks for the review @aditi-pandit

Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @nmahadevuni

@nmahadevuni nmahadevuni merged commit 9ebd1f2 into prestodb:master Dec 11, 2025
174 of 180 checks passed
@nmahadevuni nmahadevuni deleted the native_fix_metrics_content_type branch December 11, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants