diff --git a/presto-native-execution/presto_cpp/main/PrestoServer.cpp b/presto-native-execution/presto_cpp/main/PrestoServer.cpp index 8445b45f217e3..621acc75bb6d2 100644 --- a/presto-native-execution/presto_cpp/main/PrestoServer.cpp +++ b/presto-native-execution/presto_cpp/main/PrestoServer.cpp @@ -474,13 +474,23 @@ void PrestoServer::run() { if (folly::Singleton::try_get()) { httpServer_->registerGet( "/v1/info/metrics", - [](proxygen::HTTPMessage* /*message*/, + [](proxygen::HTTPMessage* message, const std::vector>& /*body*/, proxygen::ResponseHandler* downstream) { - http::sendOkResponse( - downstream, - folly::Singleton::try_get() - ->fetchMetrics()); + auto acceptHeader = message->getHeaders().getSingleOrEmpty( + proxygen::HTTPHeaderCode::HTTP_HEADER_ACCEPT); + if (acceptHeader.find(http::kMimeTypeTextPlain) != + std::string::npos) { + http::sendOkTextResponse( + downstream, + folly::Singleton::try_get() + ->fetchMetrics()); + } else { + http::sendOkResponse( + downstream, + folly::Singleton::try_get() + ->fetchMetrics()); + } }); } } diff --git a/presto-native-execution/presto_cpp/main/http/HttpConstants.h b/presto-native-execution/presto_cpp/main/http/HttpConstants.h index ce6fa4b5f4b2c..f193369d085e1 100644 --- a/presto-native-execution/presto_cpp/main/http/HttpConstants.h +++ b/presto-native-execution/presto_cpp/main/http/HttpConstants.h @@ -30,6 +30,7 @@ constexpr uint16_t kHttpInternalServerError = 500; constexpr char kMimeTypeApplicationJson[] = "application/json"; constexpr char kMimeTypeApplicationThrift[] = "application/x-thrift+binary"; +constexpr char kMimeTypeTextPlain[] = "text/plain"; constexpr char kShuttingDown[] = "\"SHUTTING_DOWN\""; constexpr char kPrestoInternalBearer[] = "X-Presto-Internal-Bearer"; diff --git a/presto-native-execution/presto_cpp/main/http/HttpServer.cpp b/presto-native-execution/presto_cpp/main/http/HttpServer.cpp index e6b7428df7e9e..dbdaa7d6961db 100644 --- a/presto-native-execution/presto_cpp/main/http/HttpServer.cpp +++ b/presto-native-execution/presto_cpp/main/http/HttpServer.cpp @@ -39,6 +39,16 @@ void sendOkResponse( .sendWithEOM(); } +void sendOkTextResponse( + proxygen::ResponseHandler* downstream, + const std::string& body) { + proxygen::ResponseBuilder(downstream) + .status(http::kHttpOk, "") + .header(proxygen::HTTP_HEADER_CONTENT_TYPE, http::kMimeTypeTextPlain) + .body(body) + .sendWithEOM(); +} + void sendOkThriftResponse( proxygen::ResponseHandler* downstream, const std::string& body) { diff --git a/presto-native-execution/presto_cpp/main/http/HttpServer.h b/presto-native-execution/presto_cpp/main/http/HttpServer.h index 02fce78026a14..b5c89129cf6b5 100644 --- a/presto-native-execution/presto_cpp/main/http/HttpServer.h +++ b/presto-native-execution/presto_cpp/main/http/HttpServer.h @@ -33,6 +33,10 @@ void sendOkResponse( proxygen::ResponseHandler* downstream, const std::string& body); +void sendOkTextResponse( + proxygen::ResponseHandler* downstream, + const std::string& body); + void sendOkThriftResponse( proxygen::ResponseHandler* downstream, const std::string& body);