summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/libs/query_stats_utils.js29
-rw-r--r--src/mongo/db/query/query_stats/query_stats.cpp18
-rw-r--r--src/mongo/db/query/query_stats/query_stats.h7
-rw-r--r--src/mongo/s/query/cluster_cursor_manager.cpp2
4 files changed, 53 insertions, 3 deletions
diff --git a/jstests/libs/query_stats_utils.js b/jstests/libs/query_stats_utils.js
index 32b5e47c9bf..fb7d1324333 100644
--- a/jstests/libs/query_stats_utils.js
+++ b/jstests/libs/query_stats_utils.js
@@ -200,8 +200,11 @@ export function confirmAllExpectedFieldsPresent(expectedKey, resultingKey) {
assert(expectedKey.hasOwnProperty(field), field);
assert.eq(expectedKey[field], resultingKey[field]);
}
+
// Make sure the resulting key isn't missing any fields.
- assert.eq(fieldsCounter, Object.keys(expectedKey).length, resultingKey);
+ assert.eq(fieldsCounter,
+ Object.keys(expectedKey).length,
+ "Query Shape Key is missing or has extra fields: " + tojson(resultingKey));
}
export function assertExpectedResults(results,
@@ -260,6 +263,30 @@ export function assertExpectedResults(results,
}
}
+export function assertAggregatedMetric(results, metricName, {sum, min, max, sumOfSq}) {
+ const {key, metrics, asOf} = results;
+
+ assert.docEq({
+ sum: NumberLong(sum),
+ max: NumberLong(max),
+ min: NumberLong(min),
+ sumOfSquares: NumberLong(sumOfSq)
+ },
+ metrics[metricName],
+ `Metric: ${metricName}`);
+}
+
+export function assertAggregatedBoolean(results, metricName, {trueCount, falseCount}) {
+ const {key, metrics, asOf} = results;
+
+ assert.docEq({
+ "true": NumberLong(trueCount),
+ "false": NumberLong(falseCount),
+ },
+ metrics[metricName],
+ `Metric: ${metricName}`);
+}
+
export function asFieldPath(str) {
return "$" + str;
}
diff --git a/src/mongo/db/query/query_stats/query_stats.cpp b/src/mongo/db/query/query_stats/query_stats.cpp
index bf1b983554b..e783f633841 100644
--- a/src/mongo/db/query/query_stats/query_stats.cpp
+++ b/src/mongo/db/query/query_stats/query_stats.cpp
@@ -217,6 +217,14 @@ void updateStatistics(const QueryStatsStore::Partition& proofOfLock,
toUpdate.totalExecMicros.aggregate(snapshot.queryExecMicros);
toUpdate.firstResponseExecMicros.aggregate(snapshot.firstResponseExecMicros);
toUpdate.docsReturned.aggregate(snapshot.docsReturned);
+
+ toUpdate.keysExamined.aggregate(snapshot.keysExamined);
+ toUpdate.docsExamined.aggregate(snapshot.docsExamined);
+ toUpdate.hasSortStage.aggregate(snapshot.hasSortStage);
+ toUpdate.usedDisk.aggregate(snapshot.usedDisk);
+ toUpdate.fromMultiPlanner.aggregate(snapshot.fromMultiPlanner);
+ toUpdate.fromPlanCache.aggregate(snapshot.fromPlanCache);
+
toUpdate.addSupplementalStats(std::move(supplementalStatsEntry));
}
@@ -291,10 +299,18 @@ QueryStatsStore& getQueryStatsStore(OperationContext* opCtx) {
QueryStatsSnapshot captureMetrics(const OperationContext* opCtx,
int64_t firstResponseExecutionTime,
const OpDebug::AdditiveMetrics& metrics) {
+ auto& opDebug = CurOp::get(opCtx)->debug();
+
QueryStatsSnapshot snapshot{
- static_cast<uint64_t>(metrics.executionTime.value_or(Microseconds{0}).count()),
+ microsecondsToUint64(metrics.executionTime),
static_cast<uint64_t>(firstResponseExecutionTime),
static_cast<uint64_t>(metrics.nreturned.value_or(0)),
+ static_cast<uint64_t>(metrics.keysExamined.value_or(0)),
+ static_cast<uint64_t>(metrics.docsExamined.value_or(0)),
+ opDebug.hasSortStage,
+ opDebug.usedDisk,
+ opDebug.fromMultiPlanner,
+ opDebug.fromPlanCache,
};
return snapshot;
diff --git a/src/mongo/db/query/query_stats/query_stats.h b/src/mongo/db/query/query_stats/query_stats.h
index d6f1f0e4633..7c84ea1a0dd 100644
--- a/src/mongo/db/query/query_stats/query_stats.h
+++ b/src/mongo/db/query/query_stats/query_stats.h
@@ -206,6 +206,13 @@ struct QueryStatsSnapshot {
uint64_t queryExecMicros;
uint64_t firstResponseExecMicros;
uint64_t docsReturned;
+
+ uint64_t keysExamined;
+ uint64_t docsExamined;
+ bool hasSortStage;
+ bool usedDisk;
+ bool fromMultiPlanner;
+ bool fromPlanCache;
};
/**
diff --git a/src/mongo/s/query/cluster_cursor_manager.cpp b/src/mongo/s/query/cluster_cursor_manager.cpp
index b66780e3ac8..8f13233e8b4 100644
--- a/src/mongo/s/query/cluster_cursor_manager.cpp
+++ b/src/mongo/s/query/cluster_cursor_manager.cpp
@@ -612,7 +612,7 @@ void collectQueryStatsMongos(OperationContext* opCtx, std::unique_ptr<query_stat
auto snapshot = query_stats::captureMetrics(
opCtx,
- opDebug.additiveMetrics.executionTime.value_or(Microseconds{0}).count(),
+ query_stats::microsecondsToUint64(opDebug.additiveMetrics.executionTime),
opDebug.additiveMetrics);
query_stats::writeQueryStats(opCtx, opDebug.queryStatsInfo.keyHash, std::move(key), snapshot);