diff options
author | Maddie Zechar <maddie.zechar@mongodb.com> | 2023-05-11 14:41:01 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-05-11 15:59:23 +0000 |
commit | 2f667bface2924113e5812be0972874bb95e6436 (patch) | |
tree | eb4aab8b07f4840d0ffa81aa6d3134bff15dc087 /jstests | |
parent | dcd8c050fb807cd6a30f1c3f833f4be23c22fdcf (diff) | |
download | mongo-2f667bface2924113e5812be0972874bb95e6436.tar.gz |
SERVER-76143 Add missing find command fields to queryStats key
Diffstat (limited to 'jstests')
6 files changed, 126 insertions, 50 deletions
diff --git a/jstests/libs/telemetry_utils.js b/jstests/libs/telemetry_utils.js index 5b7b1d32e5b..11e2d236827 100644 --- a/jstests/libs/telemetry_utils.js +++ b/jstests/libs/telemetry_utils.js @@ -61,14 +61,11 @@ function getTelemetryRedacted( applyHmacToIdentifiers = true, hmacKey = BinData(0, "MjM0NTY3ODkxMDExMTIxMzE0MTUxNjE3MTgxOTIwMjE=")) { // Hashed application name is generated using the default hmacKey argument. - const kApplicationName = "T1iwlAqhXYroi7HTycmBJvWZSETwKXnaNa5akM4q0H4="; + const kApplicationName = "MongoDB Shell"; // Filter out agg queries, including $telemetry. const match = { - $match: {"key.queryShape.find": {$exists: true}, "key.applicationName": kApplicationName} + $match: {"key.queryShape.command": "find", "key.applicationName": kApplicationName} }; - if (!applyHmacToIdentifiers) { - match.$match["key.applicationName"] = "MongoDB Shell"; - } const result = conn.adminCommand({ aggregate: 1, diff --git a/jstests/noPassthrough/telemetry/application_name_find.js b/jstests/noPassthrough/telemetry/application_name_find.js index 11a073522f0..35b86a95f53 100644 --- a/jstests/noPassthrough/telemetry/application_name_find.js +++ b/jstests/noPassthrough/telemetry/application_name_find.js @@ -2,26 +2,13 @@ * Test that applicationName and namespace appear in telemetry for the find command. * @tags: [featureFlagTelemetry] */ +load("jstests/libs/telemetry_utils.js"); (function() { "use strict"; const kApplicationName = "MongoDB Shell"; -const kHashedApplicationName = "piOJ84Zjy9dJP6snMI5X6NQ42VGim3vofK5awkuY5q8="; - -const getTelemetry = (conn, applyHmacToIdentifiers = false) => { - const result = assert.commandWorked(conn.adminCommand({ - aggregate: 1, - pipeline: [ - {$telemetry: {applyHmacToIdentifiers}}, - // Sort on telemetry key so entries are in a deterministic order. - {$sort: {key: 1}}, - {$match: {"key.applicationName": {$in: [kApplicationName, kHashedApplicationName]}}}, - {$match: {"key.queryShape.find": {$exists: true}}} - ], - cursor: {batchSize: 10} - })); - return result.cursor.firstBatch; -}; +const kHashedCollName = "w6Ax20mVkbJu4wQWAMjL8Sl+DfXAr2Zqdc3kJRB7Oo0="; +const kHashedFieldName = "lU7Z0mLRPRUL+RfAD5jhYPRRpXBsZBxS/20EzDwfOG4="; // Turn on the collecting of telemetry metrics. let options = { @@ -42,30 +29,11 @@ coll.find({v: 1}).toArray(); let telemetry = getTelemetry(conn); assert.eq(1, telemetry.length, telemetry); -assert.eq({ - queryShape: { - cmdNs: {db: testDB.getName(), coll: coll.getName()}, - find: coll.getName(), - filter: {v: {"$eq": "?number"}}, - }, - applicationName: kApplicationName -}, - telemetry[0].key, - telemetry); +assert.eq(kApplicationName, telemetry[0].key.applicationName, telemetry); -telemetry = getTelemetry(conn, true); +telemetry = getTelemetryRedacted(conn, true); assert.eq(1, telemetry.length, telemetry); -const hashedColl = "tU+RtrEU9QHrWsxNIL8OUDvfpUdavYkcuw7evPKfxdU="; -assert.eq({ - queryShape: { - cmdNs: {db: "Q7DO+ZJl+eNMEOqdNQGSbSezn1fG1nRWHYuiNueoGfs=", coll: hashedColl}, - find: hashedColl, - filter: {"ksdi13D4gc1BJ0Es4yX6QtG6MAwIeNLsCgeGRePOvFE=": {"$eq": "?number"}}, - }, - applicationName: kHashedApplicationName -}, - telemetry[0].key, - telemetry); +assert.eq(kApplicationName, telemetry[0].key.applicationName, telemetry); MongoRunner.stopMongod(conn); }()); diff --git a/jstests/noPassthrough/telemetry/query_stats_key.js b/jstests/noPassthrough/telemetry/query_stats_key.js new file mode 100644 index 00000000000..68d77110bc6 --- /dev/null +++ b/jstests/noPassthrough/telemetry/query_stats_key.js @@ -0,0 +1,111 @@ +/** + * This test confirms that telemetry store key fields are properly nested and none are missing. + * @tags: [featureFlagTelemetry] + */ +load("jstests/libs/telemetry_utils.js"); +(function() { +"use strict"; + +function confirmAllFieldsPresent(queryStatsEntries) { + const kApplicationName = "MongoDB Shell"; + const queryShapeFindFields = [ + "cmdNs", + "command", + "filter", + "sort", + "projection", + "hint", + "skip", + "limit", + "singleBatch", + "max", + "min", + "returnKey", + "showRecordId", + "tailable", + "oplogReplay", + "awaitData", + "collation", + "allowDiskUse", + "let" + ]; + + // The outer fields not nested inside queryShape. + const queryStatsKeyFields = [ + "queryShape", + "batchSize", + "comment", + "maxTimeMS", + "noCursorTimeout", + "readConcern", + "allowPartialResults", + "applicationName" + ]; + + for (const entry of queryStatsEntries) { + let fieldCounter = 0; + assert.eq(entry.key.queryShape.command, "find"); + assert.eq(entry.key.applicationName, kApplicationName); + + for (const field in entry.key.queryShape) { + assert(queryShapeFindFields.includes(field)); + fieldCounter++; + } + assert.eq(fieldCounter, queryShapeFindFields.length); + + fieldCounter = 0; + for (const field in entry.key) { + assert(queryStatsKeyFields.includes(field)); + fieldCounter++; + } + assert.eq(fieldCounter, queryStatsKeyFields.length); + } +} + +// Turn on the collecting of telemetry metrics. +let options = { + setParameter: {internalQueryConfigureTelemetrySamplingRate: -1}, +}; + +const conn = MongoRunner.runMongod(options); +const testDB = conn.getDB('test'); +var coll = testDB[jsTestName()]; +coll.drop(); + +// Have to create an index for hint not to fail. +assert.commandWorked(coll.createIndex({v: 1})); + +let commandObj = { + find: coll.getName(), + filter: {v: {$eq: 2}}, + oplogReplay: true, + comment: "this is a test!!", + min: {"v": 0}, + max: {"v": 4}, + hint: {"v": 1}, + sort: {a: -1}, + returnKey: false, + noCursorTimeout: true, + showRecordId: false, + tailable: false, + awaitData: false, + allowPartialResults: true, + skip: 1, + limit: 2, + maxTimeMS: 500, + collation: {locale: "en_US", strength: 2}, + allowDiskUse: true, + readConcern: {level: "local"}, + batchSize: 2, + singleBatch: true, + let : {}, + projection: {_id: 0}, +}; + +assert.commandWorked(testDB.runCommand(commandObj)); +let telemetry = getTelemetry(conn); +assert.eq(1, telemetry.length); +confirmAllFieldsPresent(telemetry); + +MongoRunner.stopMongod(conn); +}()); diff --git a/jstests/noPassthrough/telemetry/telemetry_collect_on_mongos.js b/jstests/noPassthrough/telemetry/telemetry_collect_on_mongos.js index 69a6b79ba18..97e4f9df3cf 100644 --- a/jstests/noPassthrough/telemetry/telemetry_collect_on_mongos.js +++ b/jstests/noPassthrough/telemetry/telemetry_collect_on_mongos.js @@ -73,11 +73,11 @@ const assertExpectedResults = (results, const telemetryKey = { queryShape: { cmdNs: {db: "test", coll: "coll"}, - find: collName, + command: "find", filter: {$and: [{v: {$gt: "?number"}}, {v: {$lt: "?number"}}]}, - batchSize: "?number", }, readConcern: {level: "local", provenance: "implicitDefault"}, + batchSize: "?number", applicationName: "MongoDB Shell", }; @@ -208,11 +208,11 @@ const assertExpectedResults = (results, const telemetryKey = { queryShape: { cmdNs: {db: "test", coll: "coll"}, - find: collName, + command: "find", filter: {$and: [{v: {$gt: "?number"}}, {v: {$lt: "?number"}}]}, - batchSize: "?number", }, readConcern: {level: "local", provenance: "implicitDefault"}, + batchSize: "?number", applicationName: "MongoDB Shell" }; diff --git a/jstests/noPassthrough/telemetry/telemetry_metrics_across_getMore_calls.js b/jstests/noPassthrough/telemetry/telemetry_metrics_across_getMore_calls.js index 657f036b551..91605c5e069 100644 --- a/jstests/noPassthrough/telemetry/telemetry_metrics_across_getMore_calls.js +++ b/jstests/noPassthrough/telemetry/telemetry_metrics_across_getMore_calls.js @@ -102,7 +102,7 @@ const fooNeBatchSize = 3; // This filters telemetry entires to just the ones entered when running above find queries. let telemetryResults = testDB.getSiblingDB("admin") - .aggregate([{$telemetry: {}}, {$match: {"key.queryShape.find": {$exists: true}}}]) + .aggregate([{$telemetry: {}}, {$match: {"key.queryShape.command": "find"}}]) .toArray(); assert.eq(telemetryResults.length, 4, telemetryResults); diff --git a/jstests/noPassthrough/telemetry/telemetry_redact_find_cmd.js b/jstests/noPassthrough/telemetry/telemetry_redact_find_cmd.js index d50e210d958..54b909adae9 100644 --- a/jstests/noPassthrough/telemetry/telemetry_redact_find_cmd.js +++ b/jstests/noPassthrough/telemetry/telemetry_redact_find_cmd.js @@ -20,7 +20,7 @@ function runTest(conn) { let telemetry = getTelemetryRedacted(admin); assert.eq(1, telemetry.length); - assert.eq(kHashedCollName, telemetry[0].key.queryShape.find); + assert.eq("find", telemetry[0].key.queryShape.command); assert.eq({[kHashedFieldName]: {$eq: "?number"}}, telemetry[0].key.queryShape.filter); db.test.insert({v: 2}); @@ -35,7 +35,7 @@ function runTest(conn) { telemetry = getTelemetryRedacted(admin); assert.eq(2, telemetry.length); - assert.eq(kHashedCollName, telemetry[1].key.queryShape.find); + assert.eq("find", telemetry[1].key.queryShape.command); assert.eq({ "$and": [{[kHashedFieldName]: {"$gt": "?number"}}, {[kHashedFieldName]: {"$lt": "?number"}}] }, |