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