diff options
-rw-r--r-- | src/mongo/db/commands/find_cmd.cpp | 61 | ||||
-rw-r--r-- | src/mongo/db/commands/run_aggregate.cpp | 29 | ||||
-rw-r--r-- | src/mongo/db/query/telemetry.cpp | 10 |
3 files changed, 64 insertions, 36 deletions
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp index cde3be5c63c..5b623ca7daa 100644 --- a/src/mongo/db/commands/find_cmd.cpp +++ b/src/mongo/db/commands/find_cmd.cpp @@ -81,29 +81,6 @@ MONGO_FAIL_POINT_DEFINE(allowExternalReadsForReverseOplogScanRule); const auto kTermField = "term"_sd; -// Parses the command object to a FindCommandRequest. If the client request did not specify any -// runtime constants, make them available to the query here. -std::unique_ptr<FindCommandRequest> parseCmdObjectToFindCommandRequest(OperationContext* opCtx, - NamespaceString nss, - BSONObj cmdObj) { - auto findCommand = query_request_helper::makeFromFindCommand( - std::move(cmdObj), - std::move(nss), - APIParameters::get(opCtx).getAPIStrict().value_or(false)); - - // Rewrite any FLE find payloads that exist in the query if this is a FLE 2 query. - if (shouldDoFLERewrite(findCommand)) { - invariant(findCommand->getNamespaceOrUUID().nss()); - processFLEFindD(opCtx, findCommand->getNamespaceOrUUID().nss().value(), findCommand.get()); - } - - if (findCommand->getMirrored().value_or(false)) { - const auto& invocation = CommandInvocation::get(opCtx); - invocation->markMirrored(); - } - - return findCommand; -} boost::intrusive_ptr<ExpressionContext> makeExpressionContext( OperationContext* opCtx, @@ -307,7 +284,7 @@ public: InterruptibleLockGuard interruptibleLockAcquisition(opCtx->lockState()); // Parse the command BSON to a FindCommandRequest. - auto findCommand = parseCmdObjectToFindCommandRequest(opCtx, nss, _request.body); + auto findCommand = _parseCmdObjectToFindCommandRequest(opCtx, nss, _request.body); // Finish the parsing step by using the FindCommandRequest to create a CanonicalQuery. const ExtensionsCallbackReal extensionsCallback(opCtx, &nss); @@ -404,7 +381,7 @@ public: const bool isExplain = false; const bool isOplogNss = (parsedNss == NamespaceString::kRsOplogNamespace); auto findCommand = - parseCmdObjectToFindCommandRequest(opCtx, std::move(parsedNss), cmdObj); + _parseCmdObjectToFindCommandRequest(opCtx, std::move(parsedNss), cmdObj); opCtx->beginPlanningTimer(); // Only allow speculative majority for internal commands that specify the correct flag. uassert(ErrorCodes::ReadConcernMajorityNotEnabled, @@ -748,7 +725,10 @@ public: auto telemetryKey = telemetry::shouldCollectTelemetry(originalFC, collection.get()->ns(), opCtx); - if (telemetryKey) { + + // FLE2 queries should not be included in telemetry, so make sure that we did not + // rewrite this query before collecting telemetry. + if (telemetryKey && !_didDoFLERewrite) { opCtx->storeQueryBSON(*telemetryKey); telemetry::collectTelemetry( @@ -783,6 +763,35 @@ public: private: const OpMsgRequest _request; const DatabaseName _dbName; + + // Since we remove encryptionInformation after rewriting a FLE2 query, this boolean keeps + // track of whether the input query did originally have enryption information. + bool _didDoFLERewrite = false; + + // Parses the command object to a FindCommandRequest. If the client request did not specify + // any runtime constants, make them available to the query here. + std::unique_ptr<FindCommandRequest> _parseCmdObjectToFindCommandRequest( + OperationContext* opCtx, NamespaceString nss, BSONObj cmdObj) { + auto findCommand = query_request_helper::makeFromFindCommand( + std::move(cmdObj), + std::move(nss), + APIParameters::get(opCtx).getAPIStrict().value_or(false)); + + // Rewrite any FLE find payloads that exist in the query if this is a FLE 2 query. + if (shouldDoFLERewrite(findCommand)) { + invariant(findCommand->getNamespaceOrUUID().nss()); + processFLEFindD( + opCtx, findCommand->getNamespaceOrUUID().nss().value(), findCommand.get()); + _didDoFLERewrite = true; + } + + if (findCommand->getMirrored().value_or(false)) { + const auto& invocation = CommandInvocation::get(opCtx); + invocation->markMirrored(); + } + + return findCommand; + } }; } findCmd; diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index 159fd47923a..493c9a9544c 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -727,6 +727,10 @@ Status runAggregate(OperationContext* opCtx, auto catalog = CollectionCatalog::get(opCtx); boost::optional<BSONObj> telemetryKey; + // Since we remove encryptionInformation after rewriting a FLE2 query, this boolean keeps track + // of whether the input query did originally have enryption information. + bool didDoFLERewrite = false; + { // If we are in a transaction, check whether the parsed pipeline supports being in // a transaction and if the transaction's read concern is supported. @@ -953,6 +957,7 @@ Status runAggregate(OperationContext* opCtx, pipeline = processFLEPipelineD( opCtx, nss, request.getEncryptionInformation().value(), std::move(pipeline)); request.setEncryptionInformation(boost::none); + didDoFLERewrite = true; } pipeline->optimizePipeline(); @@ -1096,17 +1101,21 @@ Status runAggregate(OperationContext* opCtx, curOp->debug().setPlanSummaryMetrics(stats); curOp->debug().nreturned = stats.nReturned; - telemetryKey = telemetry::shouldCollectTelemetry(request, opCtx); - // Build the telemetry key and store it in the operation context - if (telemetryKey) { - // TODO SERVER-71315: should we store it in the CurOp instead? (or even PlanExplainer) - opCtx->storeQueryBSON(*telemetryKey); - } - + // FLE2 queries should not be included in telemetry, so make sure that we did not + // rewrite this query before collecting telemetry. + if (!didDoFLERewrite) { + telemetryKey = telemetry::shouldCollectTelemetry(request, opCtx); + // Build the telemetry key and store it in the operation context + if (telemetryKey) { + // TODO SERVER-71315: should we store it in the CurOp instead? (or even + // PlanExplainer) + opCtx->storeQueryBSON(*telemetryKey); + } - if (telemetryKey) { - telemetry::collectTelemetry( - opCtx->getServiceContext(), *telemetryKey, curOp->debug(), true); + if (telemetryKey) { + telemetry::collectTelemetry( + opCtx->getServiceContext(), *telemetryKey, curOp->debug(), true); + } } // For an optimized away pipeline, signal the cache that a query operation has completed. diff --git a/src/mongo/db/query/telemetry.cpp b/src/mongo/db/query/telemetry.cpp index e0ed2c4018e..cf5924995c0 100644 --- a/src/mongo/db/query/telemetry.cpp +++ b/src/mongo/db/query/telemetry.cpp @@ -201,6 +201,11 @@ boost::optional<BSONObj> shouldCollectTelemetry(const AggregateCommandRequest& r return {}; } + // Queries against metadata collections should never appear in telemetry data. + if (request.getNamespace().isFLE2StateCollection()) { + return {}; + } + if (!shouldCollect(opCtx->getServiceContext())) { return {}; } @@ -231,6 +236,11 @@ boost::optional<BSONObj> shouldCollectTelemetry(const FindCommandRequest& reques return {}; } + // Queries against metadata collections should never appear in telemetry data. + if (collection.isFLE2StateCollection()) { + return {}; + } + if (!shouldCollect(opCtx->getServiceContext())) { return {}; } |