summaryrefslogtreecommitdiff
path: root/jstests/free_mon/free_mon_server_status.js
blob: 0dce068a494eaa1bc5fb71b6f164f1758b2d32e9 (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
// Validate serverStatus output.
//
load("jstests/free_mon/libs/free_mon.js");

(function() {
    'use strict';

    const mock_web = new FreeMonWebServer();
    mock_web.start();

    const mongod = MongoRunner.runMongod({
        setParameter: "cloudFreeMonitoringEndpointURL=" + mock_web.getURL(),
    });
    assert.neq(mongod, null, 'mongod not running');
    const admin = mongod.getDB('admin');

    const kRetryIntervalSecs = 1;
    function freeMonStats() {
        return assert.commandWorked(admin.runCommand({serverStatus: 1})).freeMonitoring;
    }

    // Initial state.
    assert.eq(freeMonStats().state, 'undecided');

    admin.enableFreeMonitoring();
    WaitForRegistration(mongod);

    // Enabled.
    const enabled = freeMonStats();
    assert.eq(enabled.state, 'enabled');
    assert.eq(enabled.retryIntervalSecs, kRetryIntervalSecs);
    assert.eq(enabled.registerErrors, 0);
    assert.eq(enabled.metricsErrors, 0);

    // Explicitly disabled.
    admin.disableFreeMonitoring();
    sleep(2);  // Give the async command time to run.

    const disabled = freeMonStats();
    assert.eq(disabled.state, 'disabled');
    assert.eq(disabled.retryIntervalSecs, kRetryIntervalSecs);
    assert.eq(disabled.registerErrors, 0);
    assert.eq(disabled.metricsErrors, 0);

    // Cleanup.
    MongoRunner.stopMongod(mongod);
    mock_web.stop();
})();