Merge pull request #1092 from atn34/trace-format-network-option

Add trace_format network option
This commit is contained in:
A.J. Beamon 2019-02-08 10:52:50 -08:00 committed by GitHub
commit 685242fbfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 66 additions and 19 deletions

View File

@ -92,6 +92,13 @@ func (o NetworkOptions) SetTraceLogGroup(param string) error {
return o.setOpt(33, []byte(param))
}
// Selects trace output format for this client. xml (the default) and json are supported.
//
// Parameter: trace format
func (o NetworkOptions) SetTraceFormat(param string) error {
return o.setOpt(34, []byte(param))
}
// Set internal tuning or debugging knobs
//
// Parameter: knob_name=knob_value

View File

@ -232,6 +232,9 @@
.. |option-trace-roll-size-blurb| replace::
Sets the maximum size in bytes of a single trace output file for this FoundationDB client.
.. |option-trace-format-blurb| replace::
Select the format of the trace files for this FoundationDB client. xml (the default) and json are supported.
.. |network-options-warning| replace::
It is an error to set these options after the first call to |open-func| anywhere in your application.

View File

@ -117,6 +117,10 @@ After importing the ``fdb`` module and selecting an API version, you probably wa
|option-trace-roll-size-blurb|
.. method :: fdb.options.set_trace_format(format)
|option-trace-format-blurb|
.. method :: fdb.options.set_disable_multi_version_client_api()
|option-disable-multi-version-client-api|

View File

@ -104,6 +104,10 @@ After requiring the ``FDB`` gem and selecting an API version, you probably want
|option-trace-roll-size-blurb|
.. method:: FDB.options.set_trace_format(format) -> nil
|option-trace-format-blurb|
|option-disable-multi-version-client-api|
.. method :: FDB.options.set_callbacks_on_external_threads() -> nil

View File

@ -743,6 +743,7 @@ void Cluster::init( Reference<ClusterConnectionFile> connFile, bool startClientI
initTraceEventMetrics();
auto publicIP = determinePublicIPAutomatically( connFile->getConnectionString() );
selectTraceFormatter(networkOptions.traceFormat);
openTraceFile(NetworkAddress(publicIP, ::getpid()), networkOptions.traceRollSize, networkOptions.traceMaxLogsSize, networkOptions.traceDirectory.get(), "trace", networkOptions.traceLogGroup);
TraceEvent("ClientStart")
@ -795,6 +796,14 @@ void setNetworkOption(FDBNetworkOptions::Option option, Optional<StringRef> valu
if(value.present())
networkOptions.traceLogGroup = value.get().toString();
break;
case FDBNetworkOptions::TRACE_FORMAT:
validateOptionValue(value, true);
networkOptions.traceFormat = value.get().toString();
if (!validateTraceFormat(networkOptions.traceFormat)) {
fprintf(stderr, "Unrecognized trace format: `%s'\n", networkOptions.traceFormat.c_str());
throw invalid_option_value();
}
break;
case FDBNetworkOptions::KNOB: {
validateOptionValue(value, true);

View File

@ -47,14 +47,16 @@ struct NetworkOptions {
uint64_t traceRollSize;
uint64_t traceMaxLogsSize;
std::string traceLogGroup;
std::string traceFormat;
Optional<bool> logClientInfo;
Standalone<VectorRef<ClientVersionRef>> supportedVersions;
bool slowTaskProfilingEnabled;
// The default values, TRACE_DEFAULT_ROLL_SIZE and TRACE_DEFAULT_MAX_LOGS_SIZE are located in Trace.h.
NetworkOptions() : localAddress(""), clusterFile(""), traceDirectory(Optional<std::string>()), traceRollSize(TRACE_DEFAULT_ROLL_SIZE), traceMaxLogsSize(TRACE_DEFAULT_MAX_LOGS_SIZE), traceLogGroup("default"),
slowTaskProfilingEnabled(false)
{ }
NetworkOptions()
: localAddress(""), clusterFile(""), traceDirectory(Optional<std::string>()),
traceRollSize(TRACE_DEFAULT_ROLL_SIZE), traceMaxLogsSize(TRACE_DEFAULT_MAX_LOGS_SIZE), traceLogGroup("default"),
traceFormat("xml"), slowTaskProfilingEnabled(false) {}
};
class Database {

View File

@ -48,6 +48,9 @@ description is not currently required but encouraged.
<Option name="trace_log_group" code="33"
paramType="String" paramDescription="value of the LogGroup attribute"
description="Sets the 'LogGroup' attribute with the specified value for all events in the trace output files. The default log group is 'default'."/>
<Option name="trace_format" code="34"
paramType="String" paramDescription="Format of trace files"
description="Select the format of the log files. xml (the default) and json are supported."/>
<Option name="knob" code="40"
paramType="String" paramDescription="knob_name=knob_value"
description="Set internal tuning or debugging knobs"/>

View File

@ -43,18 +43,6 @@
#undef min
#endif
namespace {
Reference<ITraceLogFormatter> createLogFormatter(const std::string& f) {
if (f == "json") {
return Reference<ITraceLogFormatter>(new JsonTraceLogFormatter());
} else if (f == "xml") {
return Reference<ITraceLogFormatter>(new XmlTraceLogFormatter());
} else {
UNREACHABLE();
}
}
} // namespace
class DummyThreadPool : public IThreadPool, ReferenceCounted<DummyThreadPool> {
public:
~DummyThreadPool() {}
@ -576,16 +564,41 @@ TraceEventFields LatestEventCache::getLatestError() {
static TraceLog g_traceLog;
bool selectTraceFormatter(std::string format) {
ASSERT(!g_traceLog.isOpen());
namespace {
template <bool validate>
bool traceFormatImpl(std::string& format) {
std::transform(format.begin(), format.end(), format.begin(), ::tolower);
if (format == "xml" || format == "json") {
g_traceLog.formatter = createLogFormatter(format);
if (format == "xml") {
if (!validate) {
g_traceLog.formatter = Reference<ITraceLogFormatter>(new XmlTraceLogFormatter());
}
return true;
} else if (format == "json") {
if (!validate) {
g_traceLog.formatter = Reference<ITraceLogFormatter>(new JsonTraceLogFormatter());
}
return true;
} else {
if (!validate) {
g_traceLog.formatter = Reference<ITraceLogFormatter>(new XmlTraceLogFormatter());
}
return false;
}
}
} // namespace
bool selectTraceFormatter(std::string format) {
ASSERT(!g_traceLog.isOpen());
bool recognized = traceFormatImpl</*validate*/ false>(format);
if (!recognized) {
TraceEvent(SevWarnAlways, "UnrecognizedTraceFormat").detail("format", format);
}
return recognized;
}
bool validateTraceFormat(std::string format) {
return traceFormatImpl</*validate*/ true>(format);
}
ThreadFuture<Void> flushTraceFile() {
if (!g_traceLog.isOpen())

View File

@ -265,6 +265,8 @@ bool traceFileIsOpen();
// Changes the format of trace files. Returns false if the format is unrecognized. No longer safe to call after a call
// to openTraceFile.
bool selectTraceFormatter(std::string format);
// Returns true iff format is recognized.
bool validateTraceFormat(std::string format);
void addTraceRole(std::string role);
void removeTraceRole(std::string role);