mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
SERVER-35903 Free monitoring disable without enabling does not work
This commit is contained in:
parent
daa559be88
commit
5a7537b07d
35
jstests/free_mon/free_mon_disable.js
Normal file
35
jstests/free_mon/free_mon_disable.js
Normal file
@ -0,0 +1,35 @@
|
||||
// Validate disable works
|
||||
//
|
||||
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(),
|
||||
freeMonitoringTag: "foo",
|
||||
verbose: 1,
|
||||
};
|
||||
|
||||
const conn = MongoRunner.runMongod(options);
|
||||
assert.neq(null, conn, 'mongod was unable to start up');
|
||||
|
||||
assert.commandWorked(conn.adminCommand({setFreeMonitoring: 1, action: "disable"}));
|
||||
|
||||
const stats = mock_web.queryStats();
|
||||
print(tojson(stats));
|
||||
|
||||
assert.eq(stats.registers, 0);
|
||||
|
||||
assert.eq(FreeMonGetStatus(conn).state, "disabled");
|
||||
|
||||
assert.eq(FreeMonGetServerStatus(conn).state, "disabled");
|
||||
|
||||
MongoRunner.stopMongod(conn);
|
||||
|
||||
mock_web.stop();
|
||||
})();
|
@ -24,8 +24,8 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
|
||||
mock_web.waitRegisters(2);
|
||||
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'enabled');
|
||||
|
||||
const qs1 = mock_web.queryStats();
|
||||
|
||||
@ -42,8 +42,8 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
assert.eq(qs1.registers, qs2.registers);
|
||||
|
||||
// Make sure we are back to the initial state.
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'undecided');
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'undecided');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'undecided');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'undecided');
|
||||
|
||||
// Enable it again to be sure we can resume
|
||||
assert.commandWorked(rst.getPrimary().adminCommand({setFreeMonitoring: 1, action: "enable"}));
|
||||
@ -52,8 +52,8 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
|
||||
sleep(20 * 1000);
|
||||
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'enabled');
|
||||
|
||||
rst.stopSet();
|
||||
|
||||
|
@ -23,8 +23,8 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
|
||||
mock_web.waitRegisters(2);
|
||||
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'enabled');
|
||||
|
||||
mock_web.enableFaults();
|
||||
mock_web.waitFaults(1);
|
||||
@ -40,8 +40,8 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
assert.eq(qs1.registers, qs2.registers);
|
||||
|
||||
// Halt causes us to disable free monitoring, not return it to initial state.
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'disabled');
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'disabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'disabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'disabled');
|
||||
|
||||
// Disable the fault so we can re-enable again
|
||||
mock_web.disableFaults();
|
||||
@ -53,8 +53,8 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
|
||||
sleep(20 * 1000);
|
||||
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'enabled');
|
||||
|
||||
rst.stopSet();
|
||||
|
||||
|
@ -24,8 +24,8 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
|
||||
mock_web.waitRegisters(2);
|
||||
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'enabled');
|
||||
|
||||
mock_web.enableFaults();
|
||||
mock_web.waitFaults(1);
|
||||
@ -33,9 +33,9 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
sleep(20 * 1000);
|
||||
|
||||
// Make sure we are back to the initial state.
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'undecided');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'undecided');
|
||||
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'undecided');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'undecided');
|
||||
|
||||
// Disable the fault so we can re-enable again
|
||||
mock_web.disableFaults();
|
||||
@ -47,8 +47,8 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
|
||||
sleep(20 * 1000);
|
||||
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'enabled');
|
||||
|
||||
rst.stopSet();
|
||||
|
||||
|
@ -27,8 +27,8 @@ load("jstests/free_mon/libs/free_mon.js");
|
||||
|
||||
mock_web.waitRegisters(2);
|
||||
|
||||
assert.eq(FreeMonGetStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetStatus(rst.getSecondary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'enabled');
|
||||
assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'enabled');
|
||||
|
||||
const last_register = mock_web.query("last_register");
|
||||
print(tojson(last_register));
|
||||
|
@ -251,9 +251,21 @@ function FreeMonGetRegistration(conn) {
|
||||
*
|
||||
* @param {object} serverStatus.freeMonitoring section
|
||||
*/
|
||||
function FreeMonGetStatus(conn) {
|
||||
function FreeMonGetServerStatus(conn) {
|
||||
'use strict';
|
||||
|
||||
const admin = conn.getDB("admin");
|
||||
return assert.commandWorked(admin.runCommand({serverStatus: 1})).freeMonitoring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current Free Monitoring Status via getFreeMonitoringStatus.
|
||||
*
|
||||
* @param {object} getFreeMonitoringStatus document
|
||||
*/
|
||||
function FreeMonGetStatus(conn) {
|
||||
'use strict';
|
||||
|
||||
const admin = conn.getDB("admin");
|
||||
return assert.commandWorked(admin.runCommand({getFreeMonitoringStatus: 1}));
|
||||
}
|
||||
|
@ -686,14 +686,13 @@ void FreeMonProcessor::doAsyncRegisterFail(
|
||||
void FreeMonProcessor::doCommandUnregister(
|
||||
Client* client, FreeMonWaitableMessageWithPayload<FreeMonMessageType::UnregisterCommand>* msg) {
|
||||
// Treat this request as idempotent
|
||||
if (_state->getState() != StorageStateEnum::disabled) {
|
||||
readState(client);
|
||||
|
||||
_state->setState(StorageStateEnum::disabled);
|
||||
_state->setState(StorageStateEnum::disabled);
|
||||
|
||||
writeState(client);
|
||||
writeState(client);
|
||||
|
||||
log() << "Free Monitoring is Disabled";
|
||||
}
|
||||
log() << "Free Monitoring is Disabled";
|
||||
|
||||
msg->setStatus(Status::OK());
|
||||
}
|
||||
|
@ -1033,15 +1033,16 @@ shellHelper.show = function(what) {
|
||||
} else if (freemonStatus.state === 'undecided') {
|
||||
print(
|
||||
"---\n" +
|
||||
"Enable MongoDB's free cloud-based monitoring service to collect and display\n" +
|
||||
"metrics about your deployment (disk utilization, CPU, operation statistics,\n" +
|
||||
"etc).\n" + "\n" +
|
||||
"The monitoring data will be available on a MongoDB website with a unique\n" +
|
||||
"URL created for you. Anyone you share the URL with will also be able to\n" +
|
||||
"view this page. MongoDB may use this information to make product\n" +
|
||||
"Enable MongoDB's free cloud-based monitoring service, which will then receive and display\n" +
|
||||
"metrics about your deployment (disk utilization, CPU, operation statistics, etc).\n" +
|
||||
"\n" +
|
||||
"The monitoring data will be available on a MongoDB website with a unique URL accessible to you\n" +
|
||||
"and anyone you share the URL with. MongoDB may use this information to make product\n" +
|
||||
"improvements and to suggest MongoDB products and deployment options to you.\n" +
|
||||
"\n" + "To enable free monitoring, run the following command:\n" +
|
||||
"db.enableFreeMonitoring()\n" + "---\n");
|
||||
"\n" +
|
||||
"To enable free monitoring, run the following command: db.enableFreeMonitoring()\n" +
|
||||
"To permanently disable this reminder, run the following command: db.disableFreeMonitoring()\n" +
|
||||
"---\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user