diff options
author | Will Buerger <will.buerger@mongodb.com> | 2023-05-17 11:49:47 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-05-17 12:58:52 +0000 |
commit | ae65ecae5514adc99d60b7396137a1acf2b44335 (patch) | |
tree | 24169f9a640321bfbbec649e869fe51b273b35e3 /jstests/noPassthrough/queryStats/clear_query_stats_store.js | |
parent | 1b4a551a6b8c85611e26857217ce1a1e1363e716 (diff) | |
download | mongo-ae65ecae5514adc99d60b7396137a1acf2b44335.tar.gz |
SERVER-76427 Rename $telemetry to $queryStats
Diffstat (limited to 'jstests/noPassthrough/queryStats/clear_query_stats_store.js')
-rw-r--r-- | jstests/noPassthrough/queryStats/clear_query_stats_store.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/jstests/noPassthrough/queryStats/clear_query_stats_store.js b/jstests/noPassthrough/queryStats/clear_query_stats_store.js new file mode 100644 index 00000000000..9c2b888cd76 --- /dev/null +++ b/jstests/noPassthrough/queryStats/clear_query_stats_store.js @@ -0,0 +1,43 @@ +/** + * Test that the telemetry store can be cleared when the cache size is reset to 0. + * @tags: [featureFlagQueryStats] + */ +load("jstests/libs/telemetry_utils.js"); // For verifyMetrics. + +(function() { +"use strict"; + +// Turn on the collecting of telemetry metrics. +let options = { + setParameter: {internalQueryStatsSamplingRate: -1, internalQueryStatsCacheSize: "10MB"}, +}; + +const conn = MongoRunner.runMongod(options); +const testDB = conn.getDB('test'); +var coll = testDB[jsTestName()]; +coll.drop(); + +let query = {}; +for (var j = 0; j < 10; ++j) { + query["foo.field.xyz." + j] = 1; + query["bar.field.xyz." + j] = 2; + query["baz.field.xyz." + j] = 3; + coll.aggregate([{$match: query}]).itcount(); +} + +// Confirm number of entries in the store and that none have been evicted. +let telemetryResults = testDB.getSiblingDB("admin").aggregate([{$queryStats: {}}]).toArray(); +assert.eq(telemetryResults.length, 10, telemetryResults); +assert.eq(testDB.serverStatus().metrics.queryStats.numEvicted, 0); + +// Command to clear the cache. +assert.commandWorked(testDB.adminCommand({setParameter: 1, internalQueryStatsCacheSize: "0MB"})); + +// 10 regular queries plus the $queryStats query, means 11 entries evicted when the cache is +// cleared. +assert.eq(testDB.serverStatus().metrics.queryStats.numEvicted, 11); + +// Calling $queryStats should fail when the telemetry store size is 0 bytes. +assert.throwsWithCode(() => testDB.getSiblingDB("admin").aggregate([{$queryStats: {}}]), 6579000); +MongoRunner.stopMongod(conn); +}()); |