Commit 963f7ea1 authored by zhujiashun's avatar zhujiashun

make brpc prometheus metrics path fixed

parent 981310aa
......@@ -32,9 +32,6 @@ DECLARE_int32(bvar_latency_p3);
namespace brpc {
DEFINE_string(prometheus_metrics_path, "/metrics", "The HTTP resource "
"path from which prometheus fetch metrics.");
// This is a class that convert bvar result to prometheus output.
// Currently the output only includes gauge and summary for two
// reasons:
......@@ -177,10 +174,10 @@ bool PrometheusMetricsDumper::DumpLatencyRecorderSuffix(
return true;
}
void PrometheusMetricsService::metrics(::google::protobuf::RpcController* cntl_base,
const ::brpc::MetricsRequest*,
::brpc::MetricsResponse*,
::google::protobuf::Closure* done) {
void PrometheusMetricsService::default_method(::google::protobuf::RpcController* cntl_base,
const ::brpc::MetricsRequest*,
::brpc::MetricsResponse*,
::google::protobuf::Closure* done) {
ClosureGuard done_guard(done);
Controller *cntl = static_cast<Controller*>(cntl_base);
cntl->http_response().set_content_type("text/plain");
......
......@@ -22,15 +22,15 @@
namespace brpc {
class PrometheusMetricsService : public bvars {
class PrometheusMetricsService : public brpc_prometheus_metrics {
public:
PrometheusMetricsService(Server* server)
: _server(server) {}
void metrics(::google::protobuf::RpcController* cntl_base,
const ::brpc::MetricsRequest* request,
::brpc::MetricsResponse* response,
::google::protobuf::Closure* done) override;
void default_method(::google::protobuf::RpcController* cntl_base,
const ::brpc::MetricsRequest* request,
::brpc::MetricsResponse* response,
::google::protobuf::Closure* done) override;
private:
Server* _server;
};
......
......@@ -97,8 +97,8 @@ service sockets {
rpc default_method(SocketsRequest) returns (SocketsResponse);
}
service bvars {
rpc metrics(MetricsRequest) returns (MetricsResponse);
service brpc_prometheus_metrics {
rpc default_method(MetricsRequest) returns (MetricsResponse);
}
service badmethod {
......
......@@ -485,10 +485,7 @@ int Server::AddBuiltinServices() {
LOG(ERROR) << "Fail to add ListService";
return -1;
}
ServiceOptions options;
options.ownership = SERVER_OWNS_SERVICE;
options.restful_mappings = FLAGS_prometheus_metrics_path + " => metrics";
if (AddBuiltinService(new (std::nothrow) PrometheusMetricsService(this), options)) {
if (AddBuiltinService(new (std::nothrow) PrometheusMetricsService(this))) {
LOG(ERROR) << "Fail to add MetricsService";
return -1;
}
......@@ -1351,7 +1348,7 @@ int Server::AddServiceInternal(google::protobuf::Service* service,
}
if (sp == NULL) {
ServiceProperty ss =
{ is_builtin_service, SERVER_DOESNT_OWN_SERVICE, NULL, m };
{ false , SERVER_DOESNT_OWN_SERVICE, NULL, m };
_fullname_service_map[svc_name] = ss;
_service_map[svc_name] = ss;
++_virtual_service_count;
......@@ -1415,11 +1412,6 @@ int Server::AddService(google::protobuf::Service* service,
int Server::AddBuiltinService(google::protobuf::Service* service) {
ServiceOptions options;
options.ownership = SERVER_OWNS_SERVICE;
return AddBuiltinService(service, options);
}
int Server::AddBuiltinService(google::protobuf::Service* service,
const ServiceOptions& options) {
return AddServiceInternal(service, true, options);
}
......
......@@ -530,8 +530,6 @@ friend class Controller;
const ServiceOptions& options);
int AddBuiltinService(google::protobuf::Service* service);
int AddBuiltinService(google::protobuf::Service* service,
const ServiceOptions& options);
// Remove all methods of `service' from internal structures.
void RemoveMethodsOf(google::protobuf::Service* service);
......
......@@ -10,10 +10,6 @@
#include "butil/strings/string_piece.h"
#include "echo.pb.h"
namespace brpc {
DECLARE_string(prometheus_metrics_path);
} // brpc
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
......@@ -49,7 +45,7 @@ TEST(PrometheusMetrics, sanity) {
channel_opts.protocol = "http";
ASSERT_EQ(0, channel.Init("127.0.0.1:8614", &channel_opts));
brpc::Controller cntl;
cntl.http_request().uri() = brpc::FLAGS_prometheus_metrics_path;
cntl.http_request().uri() = "/brpc_prometheus_metrics";
channel.CallMethod(NULL, &cntl, NULL, NULL, NULL);
ASSERT_FALSE(cntl.Failed());
std::string res = cntl.response_attachment().to_string();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment