Skip to content

Commit

Permalink
Merge pull request #1 from dl239/master
Browse files Browse the repository at this point in the history
feat: add builtin service gflag
  • Loading branch information
imotai authored Mar 25, 2021
2 parents 60159fc + 928048d commit 4f69bc0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/brpc/builtin/status_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extern MethodStatus* g_client_msg_status;
extern MethodStatus* g_server_msg_status;
}

DECLARE_bool(enable_vars_service);

// Defined in vars_service.cpp
void PutVarsHeading(std::ostream& os, bool expand_all);

Expand All @@ -47,7 +49,7 @@ void StatusService::default_method(::google::protobuf::RpcController* cntl_base,
ClosureGuard done_guard(done);
Controller *cntl = static_cast<Controller*>(cntl_base);
const Server* server = cntl->server();
const bool use_html = UseHTML(cntl->http_request());
const bool use_html = FLAGS_enable_vars_service ? UseHTML(cntl->http_request()) : false;

// NOTE: the plain output also fits format of public/configure so that user
// can load values more easily.
Expand Down
21 changes: 14 additions & 7 deletions src/brpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ butil::static_atomic<int> g_running_server_count = BUTIL_STATIC_ATOMIC_INIT(0);
// Following services may have security issues and are disabled by default.
DEFINE_bool(enable_dir_service, false, "Enable /dir");
DEFINE_bool(enable_threads_service, false, "Enable /threads");
DEFINE_bool(enable_status_service, false, "Enable /status");
DEFINE_bool(enable_vars_service, false, "Enable /vars");
DEFINE_bool(enable_connections_service, false, "Enable /connections");
DEFINE_bool(enable_flags_service, false, "Enable /flags");
DEFINE_bool(enable_rpcz_service, false, "Enable /rpcz");
DEFINE_bool(enable_hotspots_service, false, "Enable /hotspots/cpu /hotspots/heap /hotspots/growth /hotspots/contention");
DEFINE_bool(enable_index_service, false, "Enable /index?as_more");

DECLARE_int32(usercode_backup_threads);
DECLARE_bool(usercode_in_pthread);
Expand Down Expand Up @@ -441,31 +448,31 @@ Server::~Server() {

int Server::AddBuiltinServices() {
// Firstly add services shown in tabs.
if (AddBuiltinService(new (std::nothrow) StatusService)) {
if (FLAGS_enable_status_service && AddBuiltinService(new (std::nothrow) StatusService)) {
LOG(ERROR) << "Fail to add StatusService";
return -1;
}
if (AddBuiltinService(new (std::nothrow) VarsService)) {
if (FLAGS_enable_vars_service && AddBuiltinService(new (std::nothrow) VarsService)) {
LOG(ERROR) << "Fail to add VarsService";
return -1;
}
if (AddBuiltinService(new (std::nothrow) ConnectionsService)) {
if (FLAGS_enable_connections_service && AddBuiltinService(new (std::nothrow) ConnectionsService)) {
LOG(ERROR) << "Fail to add ConnectionsService";
return -1;
}
if (AddBuiltinService(new (std::nothrow) FlagsService)) {
if (FLAGS_enable_flags_service && AddBuiltinService(new (std::nothrow) FlagsService)) {
LOG(ERROR) << "Fail to add FlagsService";
return -1;
}
if (AddBuiltinService(new (std::nothrow) RpczService)) {
if (FLAGS_enable_rpcz_service && AddBuiltinService(new (std::nothrow) RpczService)) {
LOG(ERROR) << "Fail to add RpczService";
return -1;
}
if (AddBuiltinService(new (std::nothrow) HotspotsService)) {
if (FLAGS_enable_hotspots_service && AddBuiltinService(new (std::nothrow) HotspotsService)) {
LOG(ERROR) << "Fail to add HotspotsService";
return -1;
}
if (AddBuiltinService(new (std::nothrow) IndexService)) {
if (FLAGS_enable_index_service && AddBuiltinService(new (std::nothrow) IndexService)) {
LOG(ERROR) << "Fail to add IndexService";
return -1;
}
Expand Down

0 comments on commit 4f69bc0

Please sign in to comment.