summaryrefslogtreecommitdiff
path: root/jstests/core/set_param1.js
blob: c1ef5995578f6b5b57d7b32eef7e53414579b606 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// @tags: [
//   assumes_superuser_permissions,
//   does_not_support_stepdowns,
//   requires_fcv_61,
//   # This test attempts to compare the response from running the {getParameter: "*"}
//   # command multiple times, which may observe the change to the failpoint enabled by the
//   # migration hook.
//   tenant_migration_incompatible,
// ]

// Tests for accessing logLevel server parameter using getParameter/setParameter commands
// and shell helpers.

(function() {
'use strict';

function scrub(obj) {
    delete obj["operationTime"];
    delete obj["$clusterTime"];
    delete obj["lastCommittedOpTime"];
    // There are Failpoint manipulations in concurrent tasks in the jstest
    // environment. So scrub the volatile "failpoint." parameters.
    for (let key in obj)
        if (key.startsWith("failpoint."))
            delete obj[key];
    return obj;
}

const old = scrub(assert.commandWorked(db.adminCommand({"getParameter": "*"})));
// the first time getParameter sends a request to with a shardingTaskExecutor and this sets an
// operationTime. The following commands do not use shardingTaskExecutor.
const tmp1 = assert.commandWorked(db.adminCommand({"setParameter": 1, "logLevel": 5}));
const tmp2 = assert.commandWorked(db.adminCommand({"setParameter": 1, "logLevel": old.logLevel}));
const now = scrub(assert.commandWorked(db.adminCommand({"getParameter": "*"})));

assert.eq(old, now, "A");
assert.eq(old.logLevel, tmp1.was, "B");
assert.eq(5, tmp2.was, "C");

//
// component verbosity
//

// verbosity for log component hierarchy
printjson(old.logComponentVerbosity);
assert.neq(undefined, old.logComponentVerbosity, "log component verbosity not available");
assert.eq(old.logLevel,
          old.logComponentVerbosity.verbosity,
          "default component verbosity should match logLevel");
assert.neq(undefined,
           old.logComponentVerbosity.storage.journal.verbosity,
           "journal verbosity not available");

// Non-object log component verbosity should be rejected.
assert.commandFailed(db.adminCommand({"setParameter": 1, logComponentVerbosity: "not an object"}));

// Non-numeric verbosity for component should be rejected.
assert.commandFailed(db.adminCommand(
    {"setParameter": 1, logComponentVerbosity: {storage: {journal: {verbosity: "not a number"}}}}));

// Invalid component shall be rejected
assert.commandFailed(
    db.adminCommand({"setParameter": 1, logComponentVerbosity: {NoSuchComponent: {verbosity: 2}}}));

// Set multiple component log levels at once.
(function() {
assert.commandWorked(db.adminCommand({
    "setParameter": 1,
    logComponentVerbosity: {
        verbosity: 2,
        accessControl: {verbosity: 0},
        storage: {verbosity: 3, journal: {verbosity: 5}}
    }
}));

const result = assert.commandWorked(db.adminCommand({"getParameter": 1, logComponentVerbosity: 1}))
                   .logComponentVerbosity;

assert.eq(2, result.verbosity);
assert.eq(0, result.accessControl.verbosity);
assert.eq(3, result.storage.verbosity);
assert.eq(5, result.storage.journal.verbosity);
})();

// Set multiple component log levels at once.
// Unrecognized field names not mapping to a log component shall be rejected
// No changes shall apply.
(function() {
assert.commandFailed(db.adminCommand({
    "setParameter": 1,
    logComponentVerbosity: {
        verbosity: 6,
        accessControl: {verbosity: 5},
        storage: {verbosity: 4, journal: {verbosity: 6}},
        NoSuchComponent: {verbosity: 2},
        extraField: 123
    }
}));

const result = assert.commandWorked(db.adminCommand({"getParameter": 1, logComponentVerbosity: 1}))
                   .logComponentVerbosity;

assert.eq(2, result.verbosity);
assert.eq(0, result.accessControl.verbosity);
assert.eq(3, result.storage.verbosity);
assert.eq(5, result.storage.journal.verbosity);
})();

// Clear verbosity for default and journal.
(function() {
assert.commandWorked(db.adminCommand({
    "setParameter": 1,
    logComponentVerbosity: {verbosity: -1, storage: {journal: {verbosity: -1}}}
}));

const result = assert.commandWorked(db.adminCommand({"getParameter": 1, logComponentVerbosity: 1}))
                   .logComponentVerbosity;

assert.eq(0, result.verbosity);
assert.eq(0, result.accessControl.verbosity);
assert.eq(3, result.storage.verbosity);
assert.eq(-1, result.storage.journal.verbosity);
})();

// Set accessControl verbosity using numerical level instead of
// subdocument with 'verbosity' field.
(function() {
assert.commandWorked(
    db.adminCommand({"setParameter": 1, logComponentVerbosity: {accessControl: 5}}));

const result = assert.commandWorked(db.adminCommand({"getParameter": 1, logComponentVerbosity: 1}))
                   .logComponentVerbosity;

assert.eq(5, result.accessControl.verbosity);
})();

// Restore old verbosity values.
assert.commandWorked(
    db.adminCommand({"setParameter": 1, logComponentVerbosity: old.logComponentVerbosity}));

// Checks server parameter for redaction of encrypted fields in BSON Objects.
assert(old.hasOwnProperty('redactEncryptedFields'),
       'server parameter for toggling bindata 6 redaction not available: ' + tojson(old));
assert.commandWorked(db.adminCommand({"setParameter": 1, redactEncryptedFields: false}));
const result = assert.commandWorked(db.adminCommand({"getParameter": 1, redactEncryptedFields: 1}))
                   .redactEncryptedFields;
assert(!result,
       'setParameter worked on redaction setting but getParameter returned unexpected result.');
assert.commandWorked(
    db.adminCommand({"setParameter": 1, redactEncryptedFields: old.redactEncryptedFields}));

const isMongos = (db.hello().msg === 'isdbgrid');
if (!isMongos) {
    //
    // oplogFetcherSteadyStateMaxFetcherRestarts
    //
    let origRestarts = assert
                           .commandWorked(db.adminCommand(
                               {getParameter: 1, oplogFetcherSteadyStateMaxFetcherRestarts: 1}))
                           .oplogFetcherSteadyStateMaxFetcherRestarts;
    assert.gte(origRestarts,
               0,
               'default value of oplogFetcherSteadyStateMaxFetcherRestarts cannot be negative');
    assert.commandFailedWithCode(
        db.adminCommand({setParameter: 1, oplogFetcherSteadyStateMaxFetcherRestarts: -1}),
        ErrorCodes.BadValue,
        'server should reject negative values for oplogFetcherSteadyStateMaxFetcherRestarts');
    assert.commandWorked(
        db.adminCommand({setParameter: 1, oplogFetcherSteadyStateMaxFetcherRestarts: 0}));
    assert.commandWorked(db.adminCommand(
        {setParameter: 1, oplogFetcherSteadyStateMaxFetcherRestarts: origRestarts + 20}));
    assert.eq(origRestarts + 20,
              assert
                  .commandWorked(db.adminCommand(
                      {getParameter: 1, oplogFetcherSteadyStateMaxFetcherRestarts: 1}))
                  .oplogFetcherSteadyStateMaxFetcherRestarts);
    // Restore original value.
    assert.commandWorked(db.adminCommand(
        {setParameter: 1, oplogFetcherSteadyStateMaxFetcherRestarts: origRestarts}));

    //
    // oplogFetcherInitialSyncStateMaxFetcherRestarts
    //
    origRestarts = assert
                       .commandWorked(db.adminCommand(
                           {getParameter: 1, oplogFetcherInitialSyncMaxFetcherRestarts: 1}))
                       .oplogFetcherInitialSyncMaxFetcherRestarts;
    assert.gte(origRestarts,
               0,
               'default value of oplogFetcherSteadyStateMaxFetcherRestarts cannot be negative');
    assert.commandFailedWithCode(
        db.adminCommand({setParameter: 1, oplogFetcherInitialSyncMaxFetcherRestarts: -1}),
        ErrorCodes.BadValue,
        'server should reject negative values for oplogFetcherSteadyStateMaxFetcherRestarts');
    assert.commandWorked(
        db.adminCommand({setParameter: 1, oplogFetcherInitialSyncMaxFetcherRestarts: 0}));
    assert.commandWorked(db.adminCommand(
        {setParameter: 1, oplogFetcherInitialSyncMaxFetcherRestarts: origRestarts + 20}));
    assert.eq(origRestarts + 20,
              assert
                  .commandWorked(db.adminCommand(
                      {getParameter: 1, oplogFetcherInitialSyncMaxFetcherRestarts: 1}))
                  .oplogFetcherInitialSyncMaxFetcherRestarts);
    // Restore original value.
    assert.commandWorked(db.adminCommand(
        {setParameter: 1, oplogFetcherInitialSyncMaxFetcherRestarts: origRestarts}));
}
})();