[SERVER-86287] Investigate whether differences in query stats keys between mongod and mongos are expected Created: 06/Feb/24  Updated: 06/Feb/24

Status: Needs Scheduling
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ryan Berryhill Assignee: Backlog - Query Integration
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Integration
Operating System: ALL
Participants:

 Description   

When using the $queryStats aggregation stage, the keys sometimes differ slightly between mongod and mongos, even when using the exact same query. Specifically, mongos adds a readConcern field and mongod adds a collectionType field. To illustrate, consider the following js:

import { getQueryStats } from "jstests/libs/query_stats_utils.js";
 
function queryAndGetStats(conn) {
    const db = conn.getDB("test");
    const coll = db.getCollection("example_query_shape_key");
    coll.insert([{x: 1}, {x: 2}]);
    coll.find({x: 1}).sort({v: 1}).batchSize(100).toArray();
    return getQueryStats(db, {collName: coll.getName()})[0];
}
 
const options = {
    setParameter: {internalQueryStatsRateLimit: -1}
};
 
const conn = MongoRunner.runMongod(options);
const statsMongod = queryAndGetStats(conn);
MongoRunner.stopMongod(conn);
 
let st = new ShardingTest(Object.assign({shards: 2, other: {mongosOptions: options}}));
const statsMongos = queryAndGetStats(st.s);
st.stop();
 
print("mongod readConcern\n\t" + tojson(statsMongod.key.readConcern));
print("mongos readConcern\n\t" + tojson(statsMongos.key.readConcern));
 
print("mongod collectionType\n\t" + tojson(statsMongod.key.collectionType));
print("mongos collectionType\n\t" + tojson(statsMongos.key.collectionType));

Run via ./buildscripts/resmoke.py run --suites=no_passthrough ./example.js. Note the differences in the output:

[js_test:example] mongod readConcern
[js_test:example]       undefined
[js_test:example] mongos readConcern
[js_test:example]       { "level" : "local", "provenance" : "implicitDefault" }
[js_test:example] mongod collectionType
[js_test:example]       "collection"
[js_test:example] mongos collectionType
[js_test:example]       undefined

It's unclear to me if this is a bug or expected behavior.


Generated at Thu Feb 08 06:59:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.