Remove distributed trace database option

This commit is contained in:
Lukas Joswiak 2021-11-09 17:05:20 -08:00
parent 8bc0c3e8a2
commit 1da288822f
7 changed files with 97 additions and 158 deletions

View File

@ -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;

View File

@ -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 <special-key-space-tracing-module>` 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.

View File

@ -405,7 +405,6 @@ public:
int snapshotRywEnabled;
double transactionTracingSampleRate;
bool transactionTracingSample;
double verifyCausalReadsProp = 0.0;

View File

@ -1216,10 +1216,10 @@ DatabaseContext::DatabaseContext(Reference<AsyncVar<Reference<IClusterConnection
transactionsExpensiveClearCostEstCount("ExpensiveClearCostEstCount", cc),
transactionGrvFullBatches("NumGrvFullBatches", cc), transactionGrvTimedOutBatches("NumGrvTimedOutBatches", cc),
latencies(1000), readLatencies(1000), commitLatencies(1000), GRVLatencies(1000), mutationsPerCommit(1000),
bytesPerCommit(1000), outstandingWatches(0), transactionTracingSampleRate(FLOW_KNOBS->TRACING_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<SpecialKeySpace>(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, Optional<Stri
validateOptionValueNotPresent(value);
snapshotRywEnabled--;
break;
case FDBDatabaseOptions::DISTRIBUTED_TRANSACTION_TRACE_SAMPLE_RATE:
transactionTracingSampleRate = double(extractIntOption(value, 0, 1000000)) / 1000000.0;
setDistributedTraceSampleRate(transactionTracingSampleRate);
break;
case FDBDatabaseOptions::USE_CONFIG_DATABASE:
validateOptionValueNotPresent(value);
useConfigDatabase = true;
@ -4242,7 +4237,7 @@ void debugAddTags(Transaction* tr) {
}
}
SpanID generateSpanID(Database const& cx, SpanID parentContext = SpanID()) {
SpanID generateSpanID(bool transactionTracingSample, SpanID parentContext = SpanID()) {
uint64_t txnId = deterministicRandom()->randomUInt64();
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<Void> 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<Version> 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<std::pair<Optional<StorageMetrics>, 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<std::pair<KeyRange, Reference<LocationInfo>>> locations =
wait(getKeyRangeLocations(cx,

View File

@ -191,9 +191,6 @@ description is not currently required but encouraged.
<Option name="transaction_include_port_in_address" code="505"
description="Addresses returned by get_addresses_for_key include the port when enabled. As of api version 630, this option is enabled by default and setting this has no effect."
defaultFor="23"/>
<Option name="distributed_transaction_trace_sample_rate" code="600"
paramType="Int" paramDescription="value representing the fraction of distributed traces to record"
description="An integer between 0 and 1,000,000 (default is 0) expressing the fraction of distributed traces to record." />
<Option name="transaction_bypass_unreadable" code="700"
description="Allows ``get`` operations to read from sections of keyspace that have become unreadable because of versionstamp operations. This sets the ``bypass_unreadable`` option of each transaction created by this database. See the transaction option description for more information."
defaultFor="1100"/>

View File

@ -349,12 +349,6 @@ ITracer* g_tracer = new NoopTracer();
} // namespace
#endif
double distributedTraceSampleRate = 0;
void setDistributedTraceSampleRate(double rate) {
distributedTraceSampleRate = rate;
}
void openTracer(TracerType type) {
if (g_tracer->type() == type) {
return;

View File

@ -25,8 +25,6 @@
#include <unordered_set>
#include <atomic>
extern double distributedTraceSampleRate;
struct Location {
StringRef name;
};
@ -51,8 +49,9 @@ struct Span {
}
Span(Location location, std::initializer_list<SpanID> const& parents = {})
: Span(UID(deterministicRandom()->randomUInt64(),
deterministicRandom()->random01() < distributedTraceSampleRate ? deterministicRandom()->randomUInt64()
: 0),
deterministicRandom()->random01() < FLOW_KNOBS->TRACING_SAMPLE_RATE
? deterministicRandom()->randomUInt64()
: 0),
location,
parents) {}
Span(Location location, SpanID context) : Span(location, { context }) {}