Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remote_app string into ServerProxy_t and into logging events #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/frpclogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ union LogEventData_t {
const char *methodName;
const Array_t *params;
const URL_t *url;
const char *remoteApp = nullptr;
};

struct CallStart_t: CallBasics_t {
Expand Down
37 changes: 31 additions & 6 deletions src/frpcserverproxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ namespace FRPC {
class ServerProxyImpl_t {
public:
ServerProxyImpl_t(URL_t url,
const ServerProxy_t::Config_t &config)
const ServerProxy_t::Config_t &config,
const std::string &remoteApp)
: url(std::move(url)),
io(-1, config.readTimeout, config.writeTimeout, -1 ,-1),
rpcTransferMode(config.useBinary),
useHTTP10(config.useHTTP10),
serverSupportedProtocols(HTTPClient_t::XML_RPC),
protocolVersion(config.protocolVersion),
connector(makeConnector(this->url, config.connectTimeout,
config.keepAlive))
config.keepAlive)),
remoteApp(remoteApp)
{}

/** Set new read timeout */
Expand Down Expand Up @@ -161,6 +163,11 @@ class ServerProxyImpl_t {
return url;
}

const char *getRemoteApp() {
if (remoteApp.empty()) return nullptr;
return remoteApp.c_str();
}

/** Create marshaller.
*/
Marshaller_t* createMarshaller(HTTPClient_t &client);
Expand Down Expand Up @@ -197,6 +204,7 @@ class ServerProxyImpl_t {
std::unique_ptr<Connector_t> connector;
HTTPClient_t::HeaderVector_t requestHttpHeadersForCall;
HTTPClient_t::HeaderVector_t requestHttpHeaders;
std::string remoteApp;
};

Marshaller_t* ServerProxyImpl_t::createMarshaller(HTTPClient_t &client) {
Expand Down Expand Up @@ -453,7 +461,9 @@ class ProxyCache_t {
TimeoutListHead timeouts[TIMEOUT_QUEUES];
};

static ServerProxyImpl_t* createImpl(const std::string &server, const ServerProxy_t::Config_t &config) {
static ServerProxyImpl_t* createImpl(const std::string &server,
const ServerProxy_t::Config_t &config,
const std::string &remoteApp) {
URL_t url(server, config.proxyUrl);
if (config.keepAlive) {
auto *cache = ProxyCache_t::instance();
Expand All @@ -463,15 +473,25 @@ static ServerProxyImpl_t* createImpl(const std::string &server, const ServerProx
}
}

return new ServerProxyImpl_t(std::move(url), config);
return new ServerProxyImpl_t(std::move(url), config, remoteApp);
}

ServerProxy_t::ServerProxy_t(const std::string &server, const Config_t &config)
: sp(createImpl(server, config))
: ServerProxy_t(server, config, "")
{}

ServerProxy_t::ServerProxy_t(const std::string &server, const Config_t &config,
const std::string &remoteApp)
: sp(createImpl(server, config, remoteApp))
{}

ServerProxy_t::ServerProxy_t(const std::string &server, const Struct_t &config)
: sp(createImpl(server, configFromStruct(config)))
: ServerProxy_t(server, config, "")
{}

ServerProxy_t::ServerProxy_t(const std::string &server, const Struct_t &config,
const std::string &remoteApp)
: sp(createImpl(server, configFromStruct(config), remoteApp))
{}

ServerProxy_t::~ServerProxy_t() {
Expand Down Expand Up @@ -589,6 +609,7 @@ namespace {
Value_t *with_logger(
const char *methodName,
const URL_t *url,
const char *remoteApp,
const Array_t *params,
const HTTPHeader_t &responseHeaders,
CallT &&call
Expand All @@ -598,6 +619,7 @@ namespace {
event.callStart.methodName = methodName;
event.callStart.params = params;
event.callStart.url = url;
event.callStart.remoteApp = remoteApp;
callLoggerCallback(LogEvent_t::CALL_START, event);

Value_t *val = nullptr;
Expand Down Expand Up @@ -649,6 +671,7 @@ Value_t& ServerProxy_t::call(Pool_t &pool, const char *methodName, ...) {
return *with_logger(
methodName,
&sp->getURL(),
sp->getRemoteApp(),
paramptr,
responseHeaders,
[&] {return &sp->call(pool, methodName, args, responseHeaders);}
Expand All @@ -662,6 +685,7 @@ Value_t& ServerProxy_t::call(Pool_t &pool, const std::string &methodName,
return *with_logger(
methodName.c_str(),
&sp->getURL(),
sp->getRemoteApp(),
&params,
responseHeaders,
[&] {
Expand All @@ -679,6 +703,7 @@ void ServerProxy_t::call(DataBuilder_t &builder,
with_logger(
methodName.c_str(),
&sp->getURL(),
sp->getRemoteApp(),
&params,
responseHeaders,
[&] {
Expand Down
6 changes: 6 additions & 0 deletions src/frpcserverproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ class FRPC_DLLEXPORT ServerProxy_t {
*/
ServerProxy_t(const std::string &server, const Config_t &config);

ServerProxy_t(const std::string &server, const Config_t &config,
const std::string &remoteApp);

/**
@brief Constructor
@param server string containing address of FarstRpc server
Expand All @@ -183,6 +186,9 @@ class FRPC_DLLEXPORT ServerProxy_t {
*/
ServerProxy_t(const std::string &server, const Struct_t &config);

ServerProxy_t(const std::string &server, const Struct_t &config,
const std::string &remoteApp);

/**
@brief Default destructor
*/
Expand Down