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
|
// Validate registration works in a replica set
//
load("jstests/free_mon/libs/free_mon.js");
(function() {
'use strict';
let mock_web = new FreeMonWebServer();
mock_web.start();
let options = {
setParameter: "cloudFreeMonitoringEndpointURL=" + mock_web.getURL(),
verbose: 1,
};
const rst = new ReplSetTest({nodes: 2, nodeOptions: options});
rst.startSet();
rst.initiate();
rst.awaitReplication();
sleep(10 * 1000);
assert.eq(0, mock_web.queryStats().registers, "mongod registered without enabling free_mod");
assert.commandWorked(rst.getPrimary().adminCommand({setFreeMonitoring: 1, action: "enable"}));
WaitForRegistration(rst.getPrimary());
mock_web.waitRegisters(2);
WaitForRegistration(rst.getPrimary());
WaitForRegistration(rst.getSecondary());
ValidateFreeMonReplicaSet(rst);
const last_register = mock_web.query("last_register");
print(tojson(last_register));
assert.eq(last_register.version, 2);
assert.eq(last_register.payload.buildInfo.bits, 64);
assert.eq(last_register.payload.buildInfo.ok, 1);
assert.eq(last_register.payload.storageEngine.readOnly, false);
assert.eq(last_register.payload.isMaster.ok, 1);
assert.gte(last_register.payload.replSetGetConfig.config.version, 2);
function isUUID(val) {
// Mock webserver gives us back unpacked BinData/UUID in the form:
// { '$uuid': '0123456789abcdef0123456789abcdef' }.
if ((typeof val) !== 'object') {
return false;
}
const uuid = val['$uuid'];
if ((typeof uuid) !== 'string') {
return false;
}
return uuid.match(/^[0-9a-fA-F]{32}$/) !== null;
}
assert.eq(isUUID(last_register.payload.uuid['local.oplog.rs']), true);
// Restart the secondary
var s1 = rst.getSecondary();
var s1Id = rst.getNodeId(s1);
rst.stop(s1Id);
rst.waitForState(s1, ReplSetTest.State.DOWN);
rst.restart(s1Id);
mock_web.waitRegisters(3);
// Now disable it
assert.commandWorked(rst.getPrimary().adminCommand({setFreeMonitoring: 1, action: "disable"}));
WaitForUnRegistration(rst.getPrimary());
WaitForUnRegistration(rst.getSecondary());
WaitForFreeMonServerStatusState(rst.getPrimary(), 'disabled');
WaitForFreeMonServerStatusState(rst.getSecondary(), 'disabled');
// Restart the secondary with it disabled
var s1 = rst.getSecondary();
var s1Id = rst.getNodeId(s1);
rst.stop(s1Id);
rst.waitForState(s1, ReplSetTest.State.DOWN);
rst.restart(s1Id);
// Make sure it is disabled
WaitForFreeMonServerStatusState(rst.getPrimary(), 'disabled');
WaitForFreeMonServerStatusState(rst.getSecondary(), 'disabled');
rst.stopSet();
mock_web.stop();
})();
|