diff --git a/bindings/c/test/unit/unit_tests.cpp b/bindings/c/test/unit/unit_tests.cpp index b1c07951fc..7155553ae8 100644 --- a/bindings/c/test/unit/unit_tests.cpp +++ b/bindings/c/test/unit/unit_tests.cpp @@ -1962,50 +1962,40 @@ TEST_CASE("special-key-space set transaction ID after write") { } } -TEST_CASE("special-key-space set token after write") { - int64_t trace_sample_rate = 1000000; - fdb_check(fdb_database_set_option(db, - FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_SAMPLE_RATE, - (const uint8_t*)&trace_sample_rate, - sizeof(trace_sample_rate))); - fdb::Transaction tr(db); - fdb_check(tr.set_option(FDB_TR_OPTION_SPECIAL_KEY_SPACE_ENABLE_WRITES, nullptr, 0)); - while (1) { - tr.set(key("foo"), "bar"); - tr.set("\xff\xff/tracing/token", "false"); - fdb::ValueFuture f1 = tr.get("\xff\xff/tracing/token", - /* snapshot */ false); +// TEST_CASE("special-key-space set token after write") { +// fdb::Transaction tr(db); +// fdb_check(tr.set_option(FDB_TR_OPTION_SPECIAL_KEY_SPACE_ENABLE_WRITES, nullptr, 0)); +// while (1) { +// tr.set(key("foo"), "bar"); +// tr.set("\xff\xff/tracing/token", "false"); +// fdb::ValueFuture f1 = tr.get("\xff\xff/tracing/token", +// /* snapshot */ false); +// +// fdb_error_t err = wait_future(f1); +// if (err) { +// fdb::EmptyFuture f2 = tr.on_error(err); +// fdb_check(wait_future(f2)); +// continue; +// } +// +// int out_present; +// char* val; +// int vallen; +// fdb_check(f1.get(&out_present, (const uint8_t**)&val, &vallen)); +// +// REQUIRE(out_present); +// uint64_t token = std::stoul(std::string(val, vallen)); +// CHECK(token != 0); +// break; +// } +// } - fdb_error_t err = wait_future(f1); - if (err) { - fdb::EmptyFuture f2 = tr.on_error(err); - fdb_check(wait_future(f2)); - continue; - } - - int out_present; - char* val; - int vallen; - fdb_check(f1.get(&out_present, (const uint8_t**)&val, &vallen)); - - REQUIRE(out_present); - uint64_t token = std::stoul(std::string(val, vallen)); - CHECK(token != 0); - break; - } -} - -TEST_CASE("special-key-space valid token") { - int64_t trace_sample_rate = 1000000; - fdb_check(fdb_database_set_option(db, - FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_SAMPLE_RATE, - (const uint8_t*)&trace_sample_rate, - sizeof(trace_sample_rate))); - auto value = get_value("\xff\xff/tracing/token", /* snapshot */ false, {}); - REQUIRE(value.has_value()); - uint64_t token = std::stoul(value.value()); - CHECK(token > 0); -} +// TEST_CASE("special-key-space valid token") { +// auto value = get_value("\xff\xff/tracing/token", /* snapshot */ false, {}); +// REQUIRE(value.has_value()); +// uint64_t token = std::stoul(value.value()); +// CHECK(token > 0); +// } TEST_CASE("special-key-space disable tracing") { fdb::Transaction tr(db); @@ -2034,71 +2024,49 @@ TEST_CASE("special-key-space disable tracing") { } } -TEST_CASE("FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_DISABLE") { - int64_t trace_sample_rate = 0; - fdb_check(fdb_database_set_option(db, - FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_SAMPLE_RATE, - (const uint8_t*)&trace_sample_rate, - sizeof(trace_sample_rate))); +// TEST_CASE("FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_DISABLE") { +// fdb_check(fdb_database_set_option(db, FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_DISABLE, nullptr, 0)); +// +// auto value = get_value("\xff\xff/tracing/token", /* snapshot */ false, {}); +// REQUIRE(value.has_value()); +// uint64_t token = std::stoul(value.value()); +// CHECK(token == 0); +// +// fdb_check(fdb_database_set_option(db, FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_ENABLE, nullptr, 0)); +// } - auto value = get_value("\xff\xff/tracing/token", /* snapshot */ false, {}); - REQUIRE(value.has_value()); - uint64_t token = std::stoul(value.value()); - CHECK(token == 0); - - trace_sample_rate = 1000000; - fdb_check(fdb_database_set_option(db, - FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_SAMPLE_RATE, - (const uint8_t*)&trace_sample_rate, - sizeof(trace_sample_rate))); -} - -TEST_CASE("FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_DISABLE enable tracing for transaction") { - int64_t trace_sample_rate = 0; - fdb_check(fdb_database_set_option(db, - FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_SAMPLE_RATE, - (const uint8_t*)&trace_sample_rate, - sizeof(trace_sample_rate))); - - fdb::Transaction tr(db); - fdb_check(tr.set_option(FDB_TR_OPTION_SPECIAL_KEY_SPACE_ENABLE_WRITES, nullptr, 0)); - while (1) { - tr.set("\xff\xff/tracing/token", "true"); - fdb::ValueFuture f1 = tr.get("\xff\xff/tracing/token", - /* snapshot */ false); - - fdb_error_t err = wait_future(f1); - if (err) { - fdb::EmptyFuture f2 = tr.on_error(err); - fdb_check(wait_future(f2)); - continue; - } - - int out_present; - char* val; - int vallen; - fdb_check(f1.get(&out_present, (const uint8_t**)&val, &vallen)); - - REQUIRE(out_present); - uint64_t token = std::stoul(std::string(val, vallen)); - CHECK(token > 0); - break; - } - - trace_sample_rate = 1000000; - fdb_check(fdb_database_set_option(db, - FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_SAMPLE_RATE, - (const uint8_t*)&trace_sample_rate, - sizeof(trace_sample_rate))); -} +// TEST_CASE("FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_DISABLE enable tracing for transaction") { +// fdb_check(fdb_database_set_option(db, FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_DISABLE, nullptr, 0)); +// +// fdb::Transaction tr(db); +// fdb_check(tr.set_option(FDB_TR_OPTION_SPECIAL_KEY_SPACE_ENABLE_WRITES, nullptr, 0)); +// while (1) { +// tr.set("\xff\xff/tracing/token", "true"); +// fdb::ValueFuture f1 = tr.get("\xff\xff/tracing/token", +// /* snapshot */ false); +// +// fdb_error_t err = wait_future(f1); +// if (err) { +// fdb::EmptyFuture f2 = tr.on_error(err); +// fdb_check(wait_future(f2)); +// continue; +// } +// +// int out_present; +// char* val; +// int vallen; +// fdb_check(f1.get(&out_present, (const uint8_t**)&val, &vallen)); +// +// REQUIRE(out_present); +// uint64_t token = std::stoul(std::string(val, vallen)); +// CHECK(token > 0); +// break; +// } +// +// fdb_check(fdb_database_set_option(db, FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_ENABLE, nullptr, 0)); +// } TEST_CASE("special-key-space tracing get range") { - int64_t trace_sample_rate = 1000000; - fdb_check(fdb_database_set_option(db, - FDB_DB_OPTION_DISTRIBUTED_TRANSACTION_TRACE_SAMPLE_RATE, - (const uint8_t*)&trace_sample_rate, - sizeof(trace_sample_rate))); - std::string tracingBegin = "\xff\xff/tracing/"; std::string tracingEnd = "\xff\xff/tracing0"; @@ -2131,7 +2099,7 @@ TEST_CASE("special-key-space tracing get range") { CHECK(out_count == 2); CHECK(std::string((char*)out_kv[0].key, out_kv[0].key_length) == tracingBegin + "token"); - CHECK(std::stoul(std::string((char*)out_kv[0].value, out_kv[0].value_length)) > 0); + // CHECK(std::stoul(std::string((char*)out_kv[0].value, out_kv[0].value_length)) > 0); CHECK(std::string((char*)out_kv[1].key, out_kv[1].key_length) == tracingBegin + "transaction_id"); CHECK(std::stoul(std::string((char*)out_kv[1].value, out_kv[1].value_length)) > 0); break; diff --git a/documentation/sphinx/source/request-tracing.rst b/documentation/sphinx/source/request-tracing.rst index 361feef658..b51a240268 100644 --- a/documentation/sphinx/source/request-tracing.rst +++ b/documentation/sphinx/source/request-tracing.rst @@ -85,25 +85,12 @@ Control options In addition to the command line parameter described above, tracing can be set at a database and transaction level. -Tracing can be controlled by setting the -``distributed_transaction_trace_sample_rate`` database option. Set this option -to a value between 0 and 1,000,000, representing a fraction of traces to -record. For example, to completely disable distributed tracing, set the value -to 0. To trace half of all transactions, set the value to 500,000. Note that -the value must be an integer. The initial distributed trace sample fraction is -set by the knob ``TRACING_SAMPLE_RATE``. +Tracing can be controlled on a global level by setting the +``TRACING_SAMPLE_RATE`` knob. Set the knob to 0.0 to record no traces, to 1.0 +to record all traces, or somewhere in the middle. Traces are sampled as a unit. +All individual spans in the trace will be included in the sample. Tracing can be enabled or disabled for individual transactions. The special key space exposes an API to set a custom trace ID for a transaction, or to disable tracing for the transaction. See the special key space :ref:`tracing module documentation ` to learn more. - -^^^^^^^^^^^^^^ -Trace sampling -^^^^^^^^^^^^^^ - -By default, all traces are recorded. If tracing is producing too much data, -adjust the trace sample rate with the ``TRACING_SAMPLE_RATE`` knob. Set the -knob to 0.0 to record no traces, to 1.0 to record all traces, or somewhere in -the middle. Traces are sampled as a unit. All individual spans in the trace -will be included in the sample. diff --git a/fdbclient/DatabaseContext.h b/fdbclient/DatabaseContext.h index a6e5afa665..8e832d6d27 100644 --- a/fdbclient/DatabaseContext.h +++ b/fdbclient/DatabaseContext.h @@ -405,7 +405,6 @@ public: int snapshotRywEnabled; - double transactionTracingSampleRate; bool transactionTracingSample; double verifyCausalReadsProp = 0.0; diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index f9e3d73cdf..ce581e19e2 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -1216,10 +1216,10 @@ DatabaseContext::DatabaseContext(ReferenceTRACING_SAMPLE_RATE), - transactionTracingSample(false), taskID(taskID), clientInfo(clientInfo), clientInfoMonitor(clientInfoMonitor), - coordinator(coordinator), apiVersion(apiVersion), mvCacheInsertLocation(0), healthMetricsLastUpdated(0), - detailedHealthMetricsLastUpdated(0), smoothMidShardSize(CLIENT_KNOBS->SHARD_STAT_SMOOTH_AMOUNT), + bytesPerCommit(1000), outstandingWatches(0), transactionTracingSample(false), taskID(taskID), + clientInfo(clientInfo), clientInfoMonitor(clientInfoMonitor), coordinator(coordinator), apiVersion(apiVersion), + mvCacheInsertLocation(0), healthMetricsLastUpdated(0), detailedHealthMetricsLastUpdated(0), + smoothMidShardSize(CLIENT_KNOBS->SHARD_STAT_SMOOTH_AMOUNT), specialKeySpace(std::make_unique(specialKeys.begin, specialKeys.end, /* test */ false)) { dbId = deterministicRandom()->randomUniqueID(); connected = (clientInfo->get().commitProxies.size() && clientInfo->get().grvProxies.size()) @@ -1472,8 +1472,7 @@ DatabaseContext::DatabaseContext(const Error& err) transactionsExpensiveClearCostEstCount("ExpensiveClearCostEstCount", cc), transactionGrvFullBatches("NumGrvFullBatches", cc), transactionGrvTimedOutBatches("NumGrvTimedOutBatches", cc), latencies(1000), readLatencies(1000), commitLatencies(1000), GRVLatencies(1000), mutationsPerCommit(1000), - bytesPerCommit(1000), transactionTracingSampleRate(FLOW_KNOBS->TRACING_SAMPLE_RATE), - transactionTracingSample(false), smoothMidShardSize(CLIENT_KNOBS->SHARD_STAT_SMOOTH_AMOUNT) {} + bytesPerCommit(1000), transactionTracingSample(false), smoothMidShardSize(CLIENT_KNOBS->SHARD_STAT_SMOOTH_AMOUNT) {} // Static constructor used by server processes to create a DatabaseContext // For internal (fdbserver) use only @@ -1672,10 +1671,6 @@ void DatabaseContext::setOption(FDBDatabaseOptions::Option option, OptionalrandomUInt64(); if (parentContext.isValid()) { if (parentContext.first() > 0) { @@ -4250,8 +4245,8 @@ SpanID generateSpanID(Database const& cx, SpanID parentContext = SpanID()) { } uint64_t tokenId = parentContext.second() > 0 ? deterministicRandom()->randomUInt64() : 0; return SpanID(txnId, tokenId); - } else if (cx.getPtr() != nullptr && cx->transactionTracingSample) { - uint64_t tokenId = deterministicRandom()->random01() <= cx->transactionTracingSampleRate + } else if (transactionTracingSample) { + uint64_t tokenId = deterministicRandom()->random01() <= FLOW_KNOBS->TRACING_SAMPLE_RATE ? deterministicRandom()->randomUInt64() : 0; return SpanID(txnId, tokenId); @@ -4260,12 +4255,12 @@ SpanID generateSpanID(Database const& cx, SpanID parentContext = SpanID()) { } } -Transaction::Transaction() : info(TaskPriority::DefaultEndpoint, generateSpanID(Database())) {} +Transaction::Transaction() : info(TaskPriority::DefaultEndpoint, generateSpanID(false)) {} Transaction::Transaction(Database const& cx) - : info(cx->taskID, generateSpanID(cx)), numErrors(0), options(cx), span(info.spanID, "Transaction"_loc), - trLogInfo(createTrLogInfoProbabilistically(cx)), cx(cx), backoff(CLIENT_KNOBS->DEFAULT_BACKOFF), - committedVersion(invalidVersion), tr(info.spanID) { + : info(cx->taskID, generateSpanID(cx->transactionTracingSample)), numErrors(0), options(cx), + span(info.spanID, "Transaction"_loc), trLogInfo(createTrLogInfoProbabilistically(cx)), cx(cx), + backoff(CLIENT_KNOBS->DEFAULT_BACKOFF), committedVersion(invalidVersion), tr(info.spanID) { if (DatabaseContext::debugUseTags) { debugAddTags(this); } @@ -4930,7 +4925,7 @@ void Transaction::reset() { void Transaction::fullReset() { reset(); - info.spanID = generateSpanID(cx); + info.spanID = generateSpanID(cx->transactionTracingSample); span = Span(info.spanID, "Transaction"_loc); backoff = CLIENT_KNOBS->DEFAULT_BACKOFF; } @@ -5454,7 +5449,7 @@ ACTOR Future commitAndWatch(Transaction* self) { wait(self->commitMutations()); self->getDatabase()->transactionTracingSample = - (self->getCommittedVersion() % 60000000) < (60000000 * self->getDatabase()->transactionTracingSampleRate); + (self->getCommittedVersion() % 60000000) < (60000000 * FLOW_KNOBS->TRACING_SAMPLE_RATE); if (!self->watches.empty()) { self->setupWatches(); @@ -5959,7 +5954,7 @@ Future Transaction::getReadVersion(uint32_t flags) { } Location location = "NAPI:getReadVersion"_loc; - UID spanContext = generateSpanID(cx, info.spanID); + UID spanContext = generateSpanID(cx->transactionTracingSample, info.spanID); auto const req = DatabaseContext::VersionRequest(spanContext, options.tags, info.debugID); batcher.stream.send(req); startTime = now(); @@ -6322,7 +6317,7 @@ ACTOR Future, int>> waitStorageMetrics(Databa StorageMetrics permittedError, int shardLimit, int expectedShardCount) { - state Span span("NAPI:WaitStorageMetrics"_loc, generateSpanID(cx)); + state Span span("NAPI:WaitStorageMetrics"_loc, generateSpanID(cx->transactionTracingSample)); loop { std::vector>> locations = wait(getKeyRangeLocations(cx, diff --git a/fdbclient/vexillographer/fdb.options b/fdbclient/vexillographer/fdb.options index d029a4ee34..b75a6dd4cd 100644 --- a/fdbclient/vexillographer/fdb.options +++ b/fdbclient/vexillographer/fdb.options @@ -191,9 +191,6 @@ description is not currently required but encouraged.