summaryrefslogtreecommitdiff
path: root/jstests/sharding/health_monitor/dns_health_check.js
blob: ee0ac875b0586ff58d07b04287da548cf0f07b66 (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
/**
 * Tests successful dns health check.
 *
 *  @tags: [multiversion_incompatible]
 */
(function() {
'use strict';

const kWaitForCompletedChecksCount = 30;
const kWaitForPassedChecksCount = 10;
const kMonitoringIntervalMs = 200;

const params = {
    setParameter: {
        healthMonitoringIntensities: tojson({values: [{type: "dns", intensity: "critical"}]}),
        featureFlagHealthMonitoring: true,
        healthMonitoringIntervals:
            tojson({values: [{type: "dns", interval: kMonitoringIntervalMs}]})
    }
};

let st = new ShardingTest({
    mongos: [params],
    shards: 1,
});

const checkServerStats = function() {
    while (true) {
        let result =
            assert.commandWorked(st.s0.adminCommand({serverStatus: 1, health: {details: true}}))
                .health;
        print(`Server status: ${tojson(result)}`);
        // Wait for: at least kWaitForPassedChecksCount checks completed.
        // At least some checks passed (more than 1).
        if (result.DNS.totalChecks >= kWaitForCompletedChecksCount &&
            result.DNS.totalChecks - result.DNS.totalChecksWithFailure >=
                kWaitForPassedChecksCount) {
            break;
        }
        sleep(1000);
    }
};

checkServerStats();

// Failpoint returns bad hostname.
assert.commandWorked(st.s0.adminCommand({
    "configureFailPoint": 'dnsHealthObserverFp',
    "data": {"hostname": "name.invalid"},
    "mode": "alwaysOn"
}));

let result;

assert.soon(() => {
    result = assert.commandWorked(st.s0.adminCommand({serverStatus: 1})).health;
    return result.state == "TransientFault";
});

// Failpoint off
assert.commandWorked(
    st.s0.adminCommand({"configureFailPoint": 'dnsHealthObserverFp', "mode": "off"}));

assert.soon(() => {
    result = assert.commandWorked(st.s0.adminCommand({serverStatus: 1})).health;
    return result.state == "Ok";
});

st.stop();
})();