Allow the user to provide a custome trace log file identifier that will be used as the prefix of all trace log files created at the client side.

This commit is contained in:
Xin Dong 2020-03-26 11:24:53 -07:00
parent 0547cf2b4c
commit a0177a9335
5 changed files with 22 additions and 5 deletions

View File

@ -792,7 +792,9 @@ Database Database::createDatabase( Reference<ClusterConnectionFile> connFile, in
auto publicIP = determinePublicIPAutomatically( connFile->getConnectionString() );
selectTraceFormatter(networkOptions.traceFormat);
selectTraceClockSource(networkOptions.traceClockSource);
openTraceFile(NetworkAddress(publicIP, ::getpid()), networkOptions.traceRollSize, networkOptions.traceMaxLogsSize, networkOptions.traceDirectory.get(), "trace", networkOptions.traceLogGroup);
openTraceFile(NetworkAddress(publicIP, ::getpid()), networkOptions.traceRollSize,
networkOptions.traceMaxLogsSize, networkOptions.traceDirectory.get(), "trace",
networkOptions.traceLogGroup, networkOptions.traceFileIdentifier);
TraceEvent("ClientStart")
.detail("SourceVersion", getSourceVersion())
@ -874,7 +876,11 @@ void setNetworkOption(FDBNetworkOptions::Option option, Optional<StringRef> valu
throw invalid_option_value();
}
break;
case FDBNetworkOptions::KNOB: {
case FDBNetworkOptions::TRACE_FILE_IDENTIFIER:
validateOptionValue(value, true);
networkOptions.traceFileIdentifier = value.get().toString();
break;
case FDBNetworkOptions::KNOB: {
validateOptionValue(value, true);
std::string optionValue = value.get().toString();

View File

@ -58,6 +58,7 @@ struct NetworkOptions {
std::string traceLogGroup;
std::string traceFormat;
std::string traceClockSource;
std::string traceFileIdentifier;
Optional<bool> logClientInfo;
Reference<ReferencedObject<Standalone<VectorRef<ClientVersionRef>>>> supportedVersions;
bool slowTaskProfilingEnabled;

View File

@ -54,6 +54,9 @@ description is not currently required but encouraged.
<Option name="trace_clock_source" code="35"
paramType="String" paramDescription="Trace clock source"
description="Select clock source for trace files. now (the default) or realtime are supported." />
<Option name="trace_file_identifier" code="36"
paramType="String" paramDescription="The identifier that will be part of all trace file names"
description="Once provided, all trace log file names will use this string as the prefix." />
<Option name="knob" code="40"
paramType="String" paramDescription="knob_name=knob_value"
description="Set internal tuning or debugging knobs"/>

View File

@ -711,7 +711,8 @@ void flushTraceFileVoid() {
}
}
void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogsSize, std::string directory, std::string baseOfBase, std::string logGroup) {
void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogsSize, std::string directory,
std::string baseOfBase, std::string logGroup, std::string identifier) {
if(g_traceLog.isOpen())
return;
@ -723,7 +724,12 @@ void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogs
std::string ip = na.ip.toString();
std::replace(ip.begin(), ip.end(), ':', '_'); // For IPv6, Windows doesn't accept ':' in filenames.
std::string baseName = format("%s.%s.%d", baseOfBase.c_str(), ip.c_str(), na.port);
std::string baseName;
if (identifier.size() > 0) {
baseName = format("%s.%s.%s.%d", identifier, baseOfBase.c_str(), ip.c_str(), na.port);
} else {
baseName = format("%s.%s.%d", baseOfBase.c_str(), ip.c_str(), na.port);
}
g_traceLog.open( directory, baseName, logGroup, format("%lld", time(NULL)), rollsize, maxLogsSize, !g_network->isSimulated() ? na : Optional<NetworkAddress>());
uncancellable(recurring(&flushTraceFile, FLOW_KNOBS->TRACE_FLUSH_INTERVAL, TaskPriority::FlushTrace));

View File

@ -587,7 +587,8 @@ struct EventCacheHolder : public ReferenceCounted<EventCacheHolder> {
#endif
struct NetworkAddress;
void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogsSize, std::string directory = ".", std::string baseOfBase = "trace", std::string logGroup = "default");
void openTraceFile(const NetworkAddress& na, uint64_t rollsize, uint64_t maxLogsSize, std::string directory = ".",
std::string baseOfBase = "trace", std::string logGroup = "default", std::string identifier = "");
void initTraceEventMetrics();
void closeTraceFile();
bool traceFileIsOpen();