mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-24 00:17:37 +01:00
771dabd098
GitOrigin-RevId: 744aa110a53786b23c62ff53f87a1418b5991e8d
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
/**
|
|
* Test that verifies the TenantID prefix the namespace in slow query logs.
|
|
*/
|
|
|
|
import {ReplSetTest} from "jstests/libs/replsettest.js";
|
|
|
|
const rst = new ReplSetTest({
|
|
nodes: 1,
|
|
nodeOptions: {
|
|
auth: '',
|
|
setParameter: {
|
|
multitenancySupport: true,
|
|
featureFlagSecurityToken: true,
|
|
},
|
|
useLogFiles: true
|
|
}
|
|
});
|
|
rst.startSet({keyFile: 'jstests/libs/key1'});
|
|
rst.initiate();
|
|
|
|
const kTenant = ObjectId();
|
|
const adminDb = rst.getPrimary().getDB('admin');
|
|
|
|
// Create a user for testing
|
|
assert.commandWorked(adminDb.runCommand({createUser: 'admin', pwd: 'pwd', roles: ['root']}));
|
|
assert(adminDb.auth('admin', 'pwd'));
|
|
|
|
// Set logLevel to 1 so that all queries will be logged.
|
|
assert.commandWorked(adminDb.setLogLevel(1));
|
|
|
|
// Set slow threshold to -1 to ensure that all operations are logged as SLOW.
|
|
assert.commandWorked(adminDb.setProfilingLevel(2, {slowms: -1}));
|
|
|
|
const primary = rst.getPrimary();
|
|
|
|
primary._setSecurityToken(_createTenantToken({tenant: kTenant}));
|
|
assert.commandWorked(
|
|
primary.getDB("test").runCommand({insert: "foo", documents: [{_id: 0, a: 1, b: 1}]}));
|
|
|
|
print(`Checking ${primary.fullOptions.logFile} for client metadata message`);
|
|
const log = cat(primary.fullOptions.logFile);
|
|
|
|
const predicate =
|
|
new RegExp(`Slow query.*"${kTenant.str}_test.foo.*"appName":"MongoDB Shell".*"command":` +
|
|
`{"insert":"foo",`);
|
|
|
|
// Dump the log line by line to avoid log truncation
|
|
for (var a of log.split("\n")) {
|
|
print("LOG_FILE_ENTRY: " + a);
|
|
}
|
|
|
|
assert(predicate.test(log),
|
|
"'Slow query' log line missing in mongod log file!\n" +
|
|
"Log file contents: " + rst.getPrimary().fullOptions.logFile);
|
|
|
|
primary._setSecurityToken(undefined);
|
|
rst.stopSet();
|