Skip to content

Commit

Permalink
support customized server bvar prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jenrryyou committed Jul 24, 2022
1 parent e4a860e commit 1df96d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/brpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ static bvar::Vector<unsigned, 2> GetSessionLocalDataCount(void* arg) {
}

std::string Server::ServerPrefix() const {
return butil::string_printf("%s_%d", g_server_info_prefix, listen_address().port);
if(_options.name.empty()) {
return butil::string_printf("%s_%d", g_server_info_prefix, listen_address().port);
} else {
return std::string(g_server_info_prefix) + "_" + _options.name;
}
}

void* Server::UpdateDerivedVars(void* arg) {
Expand Down
4 changes: 4 additions & 0 deletions src/brpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ struct ServerOptions {
// Default: NULL (disabled)
RedisService* redis_service;

// Optional name for composing server bvar prefix. Read ServerPrefix() method for details;
// Default: ""
std::string name;

private:
// SSLOptions is large and not often used, allocate it on heap to
// prevent ServerOptions from being bloated in most cases.
Expand Down

0 comments on commit 1df96d7

Please sign in to comment.