summaryrefslogtreecommitdiff
path: root/jstests/sharding/health_monitor/parameters.js
blob: b73eb8f5446fa026f5b95dc5840781de8d4f184d (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
/*
 *  @tags: [multiversion_incompatible]
 */

(function() {
'use strict';

let CUSTOM_INTERVAL = 1337;
let CUSTOM_DEADLINE = 5;

var st = new ShardingTest({
    mongos: [
        {
            setParameter: {
                healthMonitoringIntensities: tojson({
                    values: [
                        {type: "dns", intensity: "off"},
                        {type: "ldap", intensity: "critical"},
                        {type: "test", intensity: "off"}
                    ]
                }),
            }
        },
        {
            setParameter: {
                healthMonitoringIntensities: tojson({
                    values: [
                        {type: "dns", intensity: "off"},
                        {type: "ldap", intensity: "off"},
                        {type: "test", intensity: "off"}
                    ]
                }),
                progressMonitor: tojson({interval: CUSTOM_INTERVAL, deadline: CUSTOM_DEADLINE}),
                healthMonitoringIntervals:
                    tojson({values: [{type: "test", interval: CUSTOM_INTERVAL}]})
            }
        }
    ],
    shards: 1,
});

// Intensity parameter
let result = st.s0.adminCommand({"getParameter": 1, "healthMonitoringIntensities": 1});
let getIntensity = (result, typeOfObserver) => {
    let intensities = result.healthMonitoringIntensities.values;
    let foundPair = intensities.find(({type}) => type === typeOfObserver);
    if (foundPair) {
        return foundPair.intensity;
    }
};

assert.eq(getIntensity(result, "dns"), "off");
assert.eq(getIntensity(result, "ldap"), "critical");

assert.commandWorked(st.s0.adminCommand({
    "setParameter": 1,
    healthMonitoringIntensities: {values: [{type: "dns", intensity: "critical"}]}
}));
assert.commandFailed(st.s0.adminCommand({
    "setParameter": 1,
    healthMonitoringIntensities: {values: [{type: "dns", intensity: "INVALID"}]}
}));
assert.commandFailed(st.s0.adminCommand({
    "setParameter": 1,
    healthMonitoringIntensities: {values: [{type: "invalid", intensity: "off"}]}
}));

// Tests that ldap param is unchanged after dns was changed.
result =
    assert.commandWorked(st.s0.adminCommand({"getParameter": 1, healthMonitoringIntensities: 1}));
assert.eq(getIntensity(result, "dns"), "critical");
assert.eq(getIntensity(result, "ldap"), "critical");

assert.commandWorked(st.s0.adminCommand({
    "setParameter": 1,
    healthMonitoringIntensities:
        {values: [{type: "dns", intensity: 'non-critical'}, {type: "ldap", intensity: 'off'}]}
}));
result =
    assert.commandWorked(st.s0.adminCommand({"getParameter": 1, healthMonitoringIntensities: 1}));

assert.eq(getIntensity(result, "dns"), "non-critical");
assert.eq(getIntensity(result, "ldap"), "off");

// Interval parameter
let getInterval = (commandResult, typeOfObserver) => {
    let allValues = commandResult.healthMonitoringIntervals.values;
    let foundPair = allValues.find(({type}) => type === typeOfObserver);
    if (foundPair) {
        return foundPair.interval;
    }
};

result = st.s1.adminCommand({"getParameter": 1, "healthMonitoringIntervals": 1});
assert.eq(getInterval(result, "test"), CUSTOM_INTERVAL);

assert.commandWorked(st.s1.adminCommand({
    "setParameter": 1,
    healthMonitoringIntervals: {values: [{type: "dns", interval: NumberInt(100)}]}
}));
assert.commandFailed(st.s1.adminCommand({
    "setParameter": 1,
    healthMonitoringIntervals: {values: [{type: "dns", interval: NumberInt(0)}]}
}));
assert.commandFailed(st.s1.adminCommand({
    "setParameter": 1,
    healthMonitoringIntervals: {values: [{type: "invalid", interval: NumberInt(100)}]}
}));

// Tests that test param is unchanged, dns is set to 100.
result =
    assert.commandWorked(st.s1.adminCommand({"getParameter": 1, healthMonitoringIntervals: 1}));
assert.eq(getInterval(result, "test"), CUSTOM_INTERVAL);
assert.eq(getInterval(result, "dns"), 100);

assert.commandWorked(st.s1.adminCommand({
    "setParameter": 1,
    healthMonitoringIntervals: {
        values:
            [{type: "dns", interval: NumberInt(2000)}, {type: "ldap", interval: NumberInt(600000)}]
    }
}));

result =
    assert.commandWorked(st.s1.adminCommand({"getParameter": 1, healthMonitoringIntervals: 1}));
assert.eq(getInterval(result, "dns"), 2000);
assert.eq(getInterval(result, "ldap"), 600000);

// Check that custom liveness values were set properly.
result = st.s1.adminCommand({"getParameter": 1, "progressMonitor": 1});
assert.eq(result.progressMonitor.interval, CUSTOM_INTERVAL);
assert.eq(result.progressMonitor.deadline, CUSTOM_DEADLINE);

// Validation tests: intervals must be > 0.
assert.commandFailed(st.s1.adminCommand({"setParameter": 1, progressMonitor: {interval: 0}}));
assert.commandFailed(st.s1.adminCommand({"setParameter": 1, progressMonitor: {interval: -5}}));
assert.commandFailed(st.s1.adminCommand({"setParameter": 1, progressMonitor: {deadline: 0}}));
assert.commandFailed(st.s1.adminCommand({"setParameter": 1, progressMonitor: {deadline: -5}}));

// Setting parameter properly during runtime.
assert.commandWorked(st.s1.adminCommand(
    {"setParameter": 1, progressMonitor: {deadline: NumberInt(CUSTOM_DEADLINE + 1)}}));
result = st.s1.adminCommand({"getParameter": 1, "progressMonitor": 1});
assert.eq(result.progressMonitor.deadline, CUSTOM_DEADLINE + 1);
// Setting only one sub-field will reset others to their default.
assert.eq(result.progressMonitor.interval, 1000);

assert.commandWorked(st.s1.adminCommand({
    "setParameter": 1,
    progressMonitor:
        {deadline: NumberInt(CUSTOM_DEADLINE + 1), interval: NumberInt(CUSTOM_INTERVAL)}
}));
result = st.s1.adminCommand({"getParameter": 1, "progressMonitor": 1});
assert.eq(result.progressMonitor.deadline, CUSTOM_DEADLINE + 1);
assert.eq(result.progressMonitor.interval, CUSTOM_INTERVAL);
st.stop();
}());