SERVER-122617 Exclude getMore and chunk ddl commands from being counted in system.buckets metrics (#50505)

GitOrigin-RevId: 7e7fd369a07816399d039645a14af2b7aeab083a
This commit is contained in:
Meryama 2026-03-27 16:20:04 +01:00 committed by MongoDB Bot
parent adc3127169
commit b1ece78fec
2 changed files with 81 additions and 6 deletions

View File

@ -8,7 +8,10 @@
* ]
*/
import {getTimeseriesBucketsColl} from "jstests/core/timeseries/libs/viewless_timeseries_util.js";
import {
areViewlessTimeseriesEnabled,
getTimeseriesBucketsColl,
} from "jstests/core/timeseries/libs/viewless_timeseries_util.js";
import {ReplSetTest} from "jstests/libs/replsettest.js";
import {ShardingTest} from "jstests/libs/shardingtest.js";
@ -101,6 +104,68 @@ function testDirectBucketTargeting({name, primaryConn, otherConns}) {
);
}
// TODO SERVER-119235: Remove once chunk-related sharding commands support rawData.
function testShardingCommandsNotCounted(st) {
jsTest.log.info(
"Testing that sharding commands and getMore are allowed to target " +
"system.buckets and do not increment the counter",
);
if (areViewlessTimeseriesEnabled(st.s.getDB("admin"))) {
return;
}
const dbName = `${jsTestName()}_sharding_cmds`;
const testDB = st.s.getDB(dbName);
const coll = testDB.getCollection("ts");
const bucketNss = getTimeseriesBucketsColl(coll).getFullName();
assert.commandWorked(st.s.adminCommand({enableSharding: dbName, primaryShard: st.shard0.shardName}));
assert.commandWorked(
st.s.adminCommand({
shardCollection: coll.getFullName(),
key: {[metaField]: 1},
timeseries: {timeField, metaField},
}),
);
const allConns = [st.s, st.rs0.getPrimary(), st.rs1.getPrimary()];
const baselines = allConns.map((conn) => getNumSystemBucketsCommands(conn));
assert.commandWorked(st.s.adminCommand({split: bucketNss, middle: {meta: 0}}));
assert.commandWorked(st.s.adminCommand({clearJumboFlag: bucketNss, find: {meta: -1}}));
assert.commandWorked(
st.s.adminCommand({moveChunk: bucketNss, find: {meta: 0}, to: st.shard1.shardName, _waitForDelete: true}),
);
assert.commandWorked(
st.s.adminCommand({moveRange: bucketNss, min: {meta: 0}, max: {meta: MaxKey}, toShard: st.shard0.shardName}),
);
assert.commandWorked(st.s.adminCommand({mergeChunks: bucketNss, bounds: [{meta: MinKey}, {meta: MaxKey}]}));
assert.commandWorked(st.s.adminCommand({mergeAllChunksOnShard: bucketNss, shard: st.shard0.shardName}));
assert.commandWorked(st.rs0.getPrimary().adminCommand({cleanupOrphaned: bucketNss}));
assert.commandWorked(st.s.adminCommand({balancerCollectionStatus: bucketNss}));
assert.commandWorked(st.s.adminCommand({configureCollectionBalancing: bucketNss}));
// Test that getMore on system.buckets does not increment the counter.
assert.commandWorked(
coll.insertMany([
{[timeField]: ISODate("2030-01-01T00:00:00Z"), [metaField]: {sensorId: 1}},
{[timeField]: ISODate("2030-01-02T00:00:00Z"), [metaField]: {sensorId: 2}},
]),
);
const findRes = assert.commandWorked(testDB.runCommand({find: coll.getName(), batchSize: 1, rawData: true}));
assert.commandWorked(
testDB.runCommand({getMore: findRes.cursor.id, collection: getTimeseriesBucketsColl(coll).getName()}),
);
for (let i = 0; i < allConns.length; i++) {
assert.eq(baselines[i], getNumSystemBucketsCommands(allConns[i]));
}
assert.commandWorked(testDB.dropDatabase());
}
// Standalone mongod.
{
const mongod = MongoRunner.runMongod();
@ -132,6 +197,7 @@ function testDirectBucketTargeting({name, primaryConn, otherConns}) {
primaryConn: st.s,
otherConns: [st.rs0.getPrimary(), st.rs1.getPrimary()],
});
testShardingCommandsNotCounted(st);
} finally {
st.stop();
}

View File

@ -42,11 +42,20 @@
namespace mongo {
// TODO SERVER-119235: Remove this once these commands support rawData.
static const StringDataSet kCommandsAllowedToTargetBuckets = {
"moveChunk"_sd,
"split"_sd,
};
// This is a list of commands that do not support rawData, hence it is allowed to target
// system.buckets.
// getMore command can be called on system.buckets even if the user didn't target
// the buckets directly, hence it should be allowed to target system.buckets.
static const StringDataSet kCommandsAllowedToTargetBuckets = {"moveChunk"_sd,
"split"_sd,
"mergeChunks"_sd,
"moveRange"_sd,
"clearJumboFlag"_sd,
"cleanupOrphaned"_sd,
"mergeAllChunksOnShard"_sd,
"configureCollectionBalancing"_sd,
"balancerCollectionStatus"_sd,
"getMore"_sd};
SystemBucketsMetricsCommandHooks::SystemBucketsMetricsCommandHooks() {
_commandsExecuted = &*MetricBuilder<Counter64>("numCommandsTargetingSystemBuckets");