Files
mongo/jstests/multiVersion/genericBinVersion/query_stats_key_hash_version_consistency.js
AlexVasilOne f855c0d0ac SERVER-93805 Use getQueryStatsServerParameters in jsTests (#29484)
GitOrigin-RevId: e0fddf4d2f1ddff8ddf1e7a1d0e803d21b4a0568
2024-11-25 16:52:27 +00:00

59 lines
2.1 KiB
JavaScript

/**
* Tests that query stats key hashes are consistent across versions.
* TODO SERVER-93204 Add queryShapeHash to this test.
*/
import "jstests/multiVersion/libs/multi_rs.js";
import {
getQueryStatsFindCmd,
getQueryStatsKeyHashes,
getQueryStatsServerParameters
} from "jstests/libs/query/query_stats_utils.js";
import {ReplSetTest} from "jstests/libs/replsettest.js";
const rst = new ReplSetTest({
nodes:
{n1: {binVersion: "last-lts"}, n2: {binVersion: "last-lts"}, n3: {binVersion: "last-lts"}}
});
// Turn on the collecting of query stats metrics.
rst.startSet(getQueryStatsServerParameters());
rst.initiate(null, null, {initiateWithDefaultElectionTimeout: true});
let conn = rst.getPrimary();
const collName = jsTestName();
let coll = conn.getDB("test")[collName];
coll.drop();
coll.insert({x: 5});
// Run a few unique queries so that they generate different query stats entries.
function runQueries() {
coll.find({x: 5}).toArray();
coll.find({y: 5}).toArray();
coll.find({y: 5}).sort({x: -1}).toArray();
coll.find({y: 5}).maxTimeMS(123).toArray();
}
// First, collect and save query stats entries on the older version.
runQueries();
const preUpgradeEntries = getQueryStatsFindCmd(conn, {collName, transformIdentifiers: false});
assert.eq(preUpgradeEntries.length, 4, tojson(preUpgradeEntries));
const preUpgradeKeyHashes = getQueryStatsKeyHashes(preUpgradeEntries);
// Upgrade to the latest.
rst.upgradeSet({binVersion: 'latest'});
conn = rst.getPrimary();
coll = conn.getDB("test")[collName];
// Run the same queries again and check that we got the same query stats key hash values as we did
// on the old version.
runQueries();
const postUpgradeEntries = getQueryStatsFindCmd(conn, {collName, transformIdentifiers: false});
assert.eq(postUpgradeEntries.length, 4, tojson(postUpgradeEntries));
const postUpgradeKeyHashes = getQueryStatsKeyHashes(postUpgradeEntries);
assert.sameMembers(postUpgradeKeyHashes,
preUpgradeKeyHashes,
`preUpgradeEntries = ${tojson(preUpgradeEntries)}, postUpgradeEntries = ${
tojson(postUpgradeEntries)}`);
rst.stopSet();