summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etc/backports_required_for_multiversion_tests.yml2
-rw-r--r--jstests/noPassthrough/aggregate_metrics.js68
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp8
3 files changed, 78 insertions, 0 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index fdd3987f44d..aab70423f76 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -48,6 +48,8 @@ all:
test_file: jstests/replsets/step_down_on_secondary.js
- ticket: SERVER-45010
test_file: jstests/replsets/rollback_dup_ids_clean_shutdown_during_rollback.js
+ - ticket: SERVER-64184
+ test_file: jstests/noPassthrough/aggregate_metrics.js
- ticket: SERVER-45906
test_file: jstests/replsets/trigger_initial_stable_checkpoint.js
- ticket: SERVER-45178
diff --git a/jstests/noPassthrough/aggregate_metrics.js b/jstests/noPassthrough/aggregate_metrics.js
new file mode 100644
index 00000000000..7a0f0ccc44e
--- /dev/null
+++ b/jstests/noPassthrough/aggregate_metrics.js
@@ -0,0 +1,68 @@
+/**
+ * Tests "metrics.commands.aggregate" counters.
+ */
+
+(function() {
+"use strict";
+
+const mongod = MongoRunner.runMongod();
+const db = mongod.getDB(jsTest.name());
+
+const kAllowDiskUseTrue = "allowDiskUseTrue";
+
+function getAggregateMetrics() {
+ return db.serverStatus().metrics.commands.aggregate;
+}
+
+function getAllowDiskUseAggregateCounter() {
+ return getAggregateMetrics()[kAllowDiskUseTrue];
+}
+
+function testAllowDistUseTrueCounter(coll) {
+ let allowDiskUseTrueValue = getAllowDiskUseAggregateCounter();
+
+ // Make sure that allowDiskUseTrue counter increments by 1 is an aggregate command with
+ // {allowDiskUse: true} is called.
+ assert.eq(0, coll.aggregate([], {allowDiskUse: true}).itcount());
+ allowDiskUseTrueValue += 1;
+ assert.eq(allowDiskUseTrueValue, getAllowDiskUseAggregateCounter());
+
+ // Make sure that allowDiskUseTrue counter stays the same if aggregate command with
+ // {allowDiskUse: false} is called.
+ assert.eq(0, coll.aggregate([], {allowDiskUse: false}).itcount());
+ assert.eq(allowDiskUseTrueValue, getAllowDiskUseAggregateCounter());
+
+ // Make sure that allowDiskUseTrue counter stays the same if aggregate command without
+ // allowDiskUse parameter is called.
+ coll.aggregate([]).itcount();
+ assert.eq(allowDiskUseTrueValue, getAllowDiskUseAggregateCounter());
+
+ // Make sure that allowDiskUseTrue counter increments by 1 is an aggregate command with
+ // {allowDiskUse: true} is called a second time.
+ assert.eq(0, coll.aggregate([], {allowDiskUse: true}).itcount());
+ allowDiskUseTrueValue += 1;
+ assert.eq(allowDiskUseTrueValue, getAllowDiskUseAggregateCounter());
+}
+
+// Execute aggregate command to ensure that the metrics.
+assert.eq(0, db.coll.aggregate([]).itcount());
+
+// Check if the metrics.commands.aggregate.allowDiskUse exists and by default equals to 0.
+assert(getAggregateMetrics().hasOwnProperty(kAllowDiskUseTrue));
+assert.eq(0, getAllowDiskUseAggregateCounter());
+
+// Test on a collection.
+const simpleTableName = "aggregateMetricsTest";
+const simpleColl = db[simpleTableName];
+simpleColl.drop();
+testAllowDistUseTrueCounter(simpleColl);
+
+// Test on a view.
+const simpleViewName = "viewOnAggregateMetricsTest";
+const simpleView = db[simpleViewName];
+simpleView.drop();
+assert.commandWorked(db.createView(simpleViewName, simpleTableName, [{$match: {a: 1}}]));
+testAllowDistUseTrueCounter(simpleView);
+
+MongoRunner.stopMongod(mongod);
+})();
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index 775b3047158..b93d81708bf 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -86,6 +86,10 @@ using std::unique_ptr;
using stdx::make_unique;
namespace {
+Counter64 allowDiskUseCounter;
+ServerStatusMetricField<Counter64> allowDiskUseMetric{"commands.aggregate.allowDiskUseTrue",
+ &allowDiskUseCounter};
+
/**
* Returns true if this PlanExecutor is for a Pipeline.
*/
@@ -655,6 +659,10 @@ Status runAggregate(OperationContext* opCtx,
auto pipeline = uassertStatusOK(Pipeline::parse(request.getPipeline(), expCtx));
expCtx->stopExpressionCounters();
+ if (request.shouldAllowDiskUse()) {
+ allowDiskUseCounter.increment();
+ }
+
// Check that the view's collation matches the collation of any views involved in the
// pipeline.
if (!pipelineInvolvedNamespaces.empty()) {