summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Tuckman <ted.tuckman@mongodb.com>2023-02-13 15:06:27 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-13 18:32:48 +0000
commita020219183884dbc5c3188053ad3c31af835e6aa (patch)
treefa9bc26d6e566c21c4f4e1f675d5577671a573cb
parent55cb4e708fbc364f7b3d9079240f987e81c37b61 (diff)
downloadmongo-a020219183884dbc5c3188053ad3c31af835e6aa.tar.gz
SERVER-73878 Don't append hashedTemetryKey to commands if telemetry is disabled
-rw-r--r--src/mongo/db/pipeline/sharded_agg_helpers.cpp3
-rw-r--r--src/mongo/db/query/telemetry.cpp19
-rw-r--r--src/mongo/db/query/telemetry.h3
3 files changed, 23 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/sharded_agg_helpers.cpp b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
index f6c7bb7e6fb..f0d7923322c 100644
--- a/src/mongo/db/pipeline/sharded_agg_helpers.cpp
+++ b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
@@ -741,6 +741,9 @@ void abandonCacheIfSentToShards(Pipeline* shardsPipeline) {
}
void setTelemetryKeyOnAggRequest(AggregateCommandRequest& request, ExpressionContext* expCtx) {
+ if (!telemetry::isTelemetryEnabled()) {
+ return;
+ }
request.setHashedTelemetryKey(telemetry::telemetryKeyToShardedStoreId(
telemetry::getTelemetryKeyFromOpCtx(expCtx->opCtx), getHostNameCachedAndPort()));
}
diff --git a/src/mongo/db/query/telemetry.cpp b/src/mongo/db/query/telemetry.cpp
index 32cca0821c1..33fab1b5fc2 100644
--- a/src/mongo/db/query/telemetry.cpp
+++ b/src/mongo/db/query/telemetry.cpp
@@ -60,7 +60,11 @@ namespace telemetry {
static const std::string kTelemetryKeyInShardedCommand = "hashedTelemetryKey";
bool isTelemetryEnabled() {
- return feature_flags::gFeatureFlagTelemetry.isEnabledAndIgnoreFCV();
+ // During initialization FCV may not yet be setup but queries could be run. We can't
+ // check whether telemetry should be enabled without FCV, so default to not recording
+ // those queries.
+ return serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+ feature_flags::gFeatureFlagTelemetry.isEnabled(serverGlobalParams.featureCompatibility);
}
ShardedTelemetryStoreKey telemetryKeyToShardedStoreId(const BSONObj& key, std::string hostAndPort) {
@@ -78,6 +82,9 @@ BSONObj getTelemetryKeyFromOpCtx(OperationContext* opCtx) {
void appendShardedTelemetryKeyIfApplicable(MutableDocument& objToModify,
std::string hostAndPort,
OperationContext* opCtx) {
+ if (!isTelemetryEnabled()) {
+ return;
+ }
auto telemetryKey = getTelemetryKeyFromOpCtx(opCtx);
if (telemetryKey.isEmpty()) {
return;
@@ -90,6 +97,9 @@ void appendShardedTelemetryKeyIfApplicable(MutableDocument& objToModify,
void appendShardedTelemetryKeyIfApplicable(BSONObjBuilder& objToModify,
std::string hostAndPort,
OperationContext* opCtx) {
+ if (!isTelemetryEnabled()) {
+ return;
+ }
auto telemetryKey = getTelemetryKeyFromOpCtx(opCtx);
if (telemetryKey.isEmpty()) {
return;
@@ -179,7 +189,12 @@ public:
ServiceContext::ConstructorActionRegisterer telemetryStoreManagerRegisterer{
"TelemetryStoreManagerRegisterer", [](ServiceContext* serviceCtx) {
- if (!isTelemetryEnabled()) {
+ // It is possible that this is called before FCV is properly set up. Setting up the store if
+ // the flag is enabled but FCV is incorrect is safe, and guards against the FCV being
+ // changed to a supported version later.
+ // TODO SERVER-73907. Move this to run after FCV is initialized. It could be we'd have to
+ // re-run this function if FCV changes later during the life of the process.
+ if (!feature_flags::gFeatureFlagTelemetry.isEnabledAndIgnoreFCV()) {
// featureFlags are not allowed to be changed at runtime. Therefore it's not an issue
// to not create a telemetry store in ConstructorActionRegisterer at start up with the
// flag off - because the flag can not be turned on at any point afterwards.
diff --git a/src/mongo/db/query/telemetry.h b/src/mongo/db/query/telemetry.h
index 3f29f9ecc77..258324290e5 100644
--- a/src/mongo/db/query/telemetry.h
+++ b/src/mongo/db/query/telemetry.h
@@ -53,6 +53,9 @@ using BSONNumeric = long long;
} // namespace
namespace telemetry {
+
+bool isTelemetryEnabled();
+
/**
* Generate a Telemetry Store key to be used on a shard from a Telemetry Store key that is being
* used on mongos.