summaryrefslogtreecommitdiff
path: root/jstests/serverless/cluster_parameter_op_observer_serverless.js
blob: 74d76c1baba98a98bb9cbe3148384a5242680ea5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 * Test that ClusterServerParameterOpObserver fires appropriately on serverless replsets.
 * @tags: [
 *   does_not_support_stepdowns,
 *   requires_replication,
 *   requires_fcv_62,
 *   serverless
 *  ]
 */

(function() {
'use strict';
// For ChangeStreamMultitenantReplicaSetTest.
load("jstests/serverless/libs/change_collection_util.js");

const getTenantConnection = ChangeStreamMultitenantReplicaSetTest.getTenantConnection;

const kUnknownCSPLogId = 6226300;
const kUnknownCSPLogComponent = 'control';
const kUnknownCSPLogLevel = 3;
const tenantId = ObjectId();

function runTest(conn) {
    const tenantConn = getTenantConnection(conn.host, tenantId);
    let i = 0;
    const connConfig = conn.getDB('config');
    for (let myConn of [conn, tenantConn]) {
        const myConnConfig = myConn.getDB('config');
        // Using non-tenant connection, check that there's no log message yet and set the log level
        // to debug
        assert(!checkLog.checkContainsOnceJson(conn, kUnknownCSPLogId, {name: 'foo_' + i}));
        const originalLogLevel =
            assert
                .commandWorked(connConfig.setLogLevel(kUnknownCSPLogLevel, kUnknownCSPLogComponent))
                .was.verbosity;

        // With given connection, insert into this tenant's cluster parameter collection
        assert.writeOK(myConnConfig.clusterParameters.insert(
            {_id: 'foo_' + i, clusterParameterTime: Date(), value: 123}));

        // With non-tenant connection, reset log level and check that the op observer triggered and
        // caused a log message about unknown cluster parameter
        assert.commandWorked(connConfig.setLogLevel(originalLogLevel, kUnknownCSPLogComponent));
        assert(checkLog.checkContainsOnceJson(conn, kUnknownCSPLogId, {name: 'foo_' + i}));
        i += 1;
    }
}

const rst = new ReplSetTest({nodes: 3});
rst.startSet({
    setParameter: {
        multitenancySupport: true,
        featureFlagRequireTenantID: true,
        featureFlagSecurityToken: true
    }
});
rst.initiate();

// Create a root user within the multitenant environment so that getTenantConnection works.
assert.commandWorked(
    rst.getPrimary().getDB("admin").runCommand({createUser: "root", pwd: "pwd", roles: ["root"]}));

runTest(rst.getPrimary());
rst.stopSet();
})();