From 12646ec5380bcc0dc10c66069a6583c653683922 Mon Sep 17 00:00:00 2001 From: Louis Williams Date: Mon, 2 Nov 2020 16:36:20 -0500 Subject: SERVER-50865 Collect resource consumption metrics for index builds --- src/mongo/db/index_builds_coordinator_mongod.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/mongo/db/index_builds_coordinator_mongod.cpp') diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index eef382c66de..e73cbc97c1c 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -45,6 +45,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/service_context.h" +#include "mongo/db/stats/resource_consumption_metrics.h" #include "mongo/db/storage/two_phase_index_build_knobs_gen.h" #include "mongo/executor/task_executor.h" #include "mongo/logv2/log.h" @@ -319,6 +320,14 @@ IndexBuildsCoordinatorMongod::_startIndexBuild(OperationContext* opCtx, sleepmillis(100); } + // Start collecting metrics for the index build. The metrics for this operation will only be + // aggregated globally if the node commits or aborts while it is primary. + auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx.get()); + if (ResourceConsumption::shouldCollectMetricsForDatabase(dbName) && + ResourceConsumption::isMetricsCollectionEnabled()) { + metricsCollector.beginScopedCollecting(dbName); + } + // Index builds should never take the PBWM lock, even on a primary. This allows the // index build to continue running after the node steps down to a secondary. ShouldNotConflictWithSecondaryBatchApplicationBlock shouldNotConflictBlock( -- cgit v1.2.1