/** * Utility for checking that the aggregated telemetry metrics are logical (follows sum >= max >= * min, and sum = max = min if only one execution). */ function verifyMetrics(batch) { batch.forEach(element => { if (element.metrics.execCount === 1) { for (const [metricName, summaryValues] of Object.entries(element.metrics)) { // Skip over fields that aren't aggregated metrics with sum/min/max (execCount, // lastExecutionMicros). if (summaryValues.sum === undefined) { continue; } const debugInfo = {[metricName]: summaryValues}; // If there has only been one execution, all metrics should have min, max, and sum // equal to each other. assert.eq(summaryValues.sum, summaryValues.min, debugInfo); assert.eq(summaryValues.sum, summaryValues.max, debugInfo); assert.eq(summaryValues.min, summaryValues.max, debugInfo); } } else { for (const [metricName, summaryValues] of Object.entries(element.metrics)) { // Skip over fields that aren't aggregated metrics with sum/min/max (execCount, // lastExecutionMicros). if (summaryValues.sum === undefined) { continue; } const debugInfo = {[metricName]: summaryValues}; assert.gte(summaryValues.sum, summaryValues.min, debugInfo); assert.gte(summaryValues.sum, summaryValues.max, debugInfo); assert.lte(summaryValues.min, summaryValues.max, debugInfo); } } }); } /** * * Collect telemetry from a given collection. Only include query shapes generated by the shell that * is running tests. * */ function getTelemetry(conn) { const kApplicationName = "MongoDB Shell"; const result = conn.adminCommand({ aggregate: 1, pipeline: [ {$queryStats: {}}, // Sort on telemetry key so entries are in a deterministic order. {$sort: {key: 1}}, {$match: {"key.applicationName": kApplicationName}} ], cursor: {} }); assert.commandWorked(result); return result.cursor.firstBatch; } function getTelemetryRedacted( conn, applyHmacToIdentifiers = true, hmacKey = BinData(0, "MjM0NTY3ODkxMDExMTIxMzE0MTUxNjE3MTgxOTIwMjE=")) { // Hashed application name is generated using the default hmacKey argument. const kApplicationName = "MongoDB Shell"; // Filter out agg queries, including $queryStats. const match = { $match: {"key.queryShape.command": "find", "key.applicationName": kApplicationName} }; const result = conn.adminCommand({ aggregate: 1, pipeline: [ {$queryStats: {applyHmacToIdentifiers: applyHmacToIdentifiers, hmacKey: hmacKey}}, match, // Sort on telemetry key so entries are in a deterministic order. {$sort: {key: 1}}, ], cursor: {} }); assert.commandWorked(result); return result.cursor.firstBatch; }