diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2018-07-13 17:10:01 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2018-07-13 17:10:01 -0400 |
commit | 77ab40c05f28c6c0afbc84bb72375a9867f79ecb (patch) | |
tree | acd2fc8198419a2b60bbd50abf781c7c87e11dbd /jstests/free_mon | |
parent | 5a7537b07dbf7d8db74531632dc06883042b4234 (diff) | |
download | mongo-77ab40c05f28c6c0afbc84bb72375a9867f79ecb.tar.gz |
SERVER-35692 Add support to an optional re-registration bool in metrics response
Diffstat (limited to 'jstests/free_mon')
-rw-r--r-- | jstests/free_mon/free_mon_register.js | 4 | ||||
-rw-r--r-- | jstests/free_mon/free_mon_register_cmd.js | 4 | ||||
-rw-r--r-- | jstests/free_mon/free_mon_register_resend.js | 28 | ||||
-rw-r--r-- | jstests/free_mon/free_mon_rs_register.js | 3 | ||||
-rw-r--r-- | jstests/free_mon/free_mon_rs_resend.js | 66 | ||||
-rw-r--r-- | jstests/free_mon/libs/free_mon.js | 11 | ||||
-rw-r--r-- | jstests/free_mon/libs/mock_http_server.py | 37 |
7 files changed, 143 insertions, 10 deletions
diff --git a/jstests/free_mon/free_mon_register.js b/jstests/free_mon/free_mon_register.js index d0d29f114de..6d1ae50274a 100644 --- a/jstests/free_mon/free_mon_register.js +++ b/jstests/free_mon/free_mon_register.js @@ -31,7 +31,7 @@ load("jstests/free_mon/libs/free_mon.js"); const last_register = mock_web.query("last_register"); print(tojson(last_register)); - assert.eq(last_register.version, 1); + assert.eq(last_register.version, 2); assert.gt(new Date().setTime(last_register.localTime["$date"]), localTime); assert.eq(last_register.payload.buildInfo.bits, 64); assert.eq(last_register.payload.buildInfo.ok, 1); @@ -44,7 +44,7 @@ load("jstests/free_mon/libs/free_mon.js"); const last_metrics = mock_web.query("last_metrics"); print(tojson(last_metrics)); - assert.eq(last_metrics.version, 1); + assert.eq(last_metrics.version, 2); assert.gt(new Date().setTime(last_metrics.localTime["$date"]), localTime); MongoRunner.stopMongod(conn); diff --git a/jstests/free_mon/free_mon_register_cmd.js b/jstests/free_mon/free_mon_register_cmd.js index 6eb0c1f9c69..35fdc9397af 100644 --- a/jstests/free_mon/free_mon_register_cmd.js +++ b/jstests/free_mon/free_mon_register_cmd.js @@ -41,7 +41,7 @@ load("jstests/free_mon/libs/free_mon.js"); const last_register = mock_web.query("last_register"); print(tojson(last_register)); - assert.eq(last_register.version, 1); + 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); @@ -52,7 +52,7 @@ load("jstests/free_mon/libs/free_mon.js"); const last_metrics = mock_web.query("last_metrics"); print(tojson(last_metrics)); - assert.eq(last_metrics.version, 1); + assert.eq(last_metrics.version, 2); assert.commandWorked(conn.adminCommand({setFreeMonitoring: 1, action: "disable"})); diff --git a/jstests/free_mon/free_mon_register_resend.js b/jstests/free_mon/free_mon_register_resend.js new file mode 100644 index 00000000000..de98e038ac6 --- /dev/null +++ b/jstests/free_mon/free_mon_register_resend.js @@ -0,0 +1,28 @@ +// Validate resend registration works in a replica set +// +load("jstests/free_mon/libs/free_mon.js"); + +(function() { + 'use strict'; + + let mock_web = new FreeMonWebServer(FAULT_RESEND_REGISTRATION_ONCE); + + mock_web.start(); + + let options = { + setParameter: "cloudFreeMonitoringEndpointURL=" + mock_web.getURL(), + enableFreeMonitoring: "on", + verbose: 1, + }; + + const conn = MongoRunner.runMongod(options); + assert.neq(null, conn, 'mongod was unable to start up'); + + WaitForRegistration(conn); + + mock_web.waitRegisters(2); + + MongoRunner.stopMongod(conn); + + mock_web.stop(); +})(); diff --git a/jstests/free_mon/free_mon_rs_register.js b/jstests/free_mon/free_mon_rs_register.js index 1c518456a2f..acbdab3301c 100644 --- a/jstests/free_mon/free_mon_rs_register.js +++ b/jstests/free_mon/free_mon_rs_register.js @@ -15,6 +15,7 @@ load("jstests/free_mon/libs/free_mon.js"); }; const rst = new ReplSetTest({nodes: 2, nodeOptions: options}); + rst.startSet(); rst.initiate(); rst.awaitReplication(); @@ -33,7 +34,7 @@ load("jstests/free_mon/libs/free_mon.js"); const last_register = mock_web.query("last_register"); print(tojson(last_register)); - assert.eq(last_register.version, 1); + 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); diff --git a/jstests/free_mon/free_mon_rs_resend.js b/jstests/free_mon/free_mon_rs_resend.js new file mode 100644 index 00000000000..464caf396e5 --- /dev/null +++ b/jstests/free_mon/free_mon_rs_resend.js @@ -0,0 +1,66 @@ +// Validate resend registration works in a replica set +// +load("jstests/free_mon/libs/free_mon.js"); + +(function() { + 'use strict'; + + let mock_web = new FreeMonWebServer(FAULT_RESEND_REGISTRATION_AT_3); + let mock_web_sec = new FreeMonWebServer(FAULT_RESEND_REGISTRATION_ONCE, true); + + mock_web.start(); + mock_web_sec.start(); + + const rst = new ReplSetTest({ + name: "free_mon_rs_register", + nodes: [ + { + setParameter: "cloudFreeMonitoringEndpointURL=" + mock_web.getURL(), + verbose: 1, + }, + { + setParameter: "cloudFreeMonitoringEndpointURL=" + mock_web_sec.getURL(), + verbose: 1, + } + ] + }); + + rst.startSet(); + rst.initiate(); + rst.awaitReplication(); + + sleep(10 * 1000); + assert.eq(0, mock_web.queryStats().registers, "mongod registered without enabling free_mod"); + assert.eq( + 0, mock_web_sec.queryStats().registers, "mongod registered without enabling free_mod"); + + assert.commandWorked(rst.getPrimary().adminCommand({setFreeMonitoring: 1, action: "enable"})); + WaitForRegistration(rst.getPrimary()); + + mock_web.waitRegisters(1); + mock_web_sec.waitRegisters(1); + + assert.eq(FreeMonGetServerStatus(rst.getPrimary()).state, 'enabled'); + assert.eq(FreeMonGetServerStatus(rst.getSecondary()).state, 'enabled'); + + mock_web.waitRegisters(2); + mock_web_sec.waitRegisters(2); + mock_web_sec.disableFaults(); + + // Trigger resend on the secondary only + mock_web_sec.enableFaults(); + mock_web_sec.waitFaults(1); + mock_web_sec.waitRegisters(3); + + // Double check registers were as expected + const stats = mock_web.queryStats(); + assert.eq(stats.registers, 2); + + const stats_sec = mock_web_sec.queryStats(); + assert.gte(stats_sec.registers, 3); + + rst.stopSet(); + + mock_web.stop(); + mock_web_sec.stop(); +})(); diff --git a/jstests/free_mon/libs/free_mon.js b/jstests/free_mon/libs/free_mon.js index 3cb9f90e364..74da57b3e6b 100644 --- a/jstests/free_mon/libs/free_mon.js +++ b/jstests/free_mon/libs/free_mon.js @@ -9,6 +9,8 @@ const FAULT_FAIL_REGISTER = "fail_register"; const FAULT_INVALID_REGISTER = "invalid_register"; const FAULT_HALT_METRICS_5 = "halt_metrics_5"; const FAULT_PERMANENTLY_DELETE_AFTER_3 = "permanently_delete_after_3"; +const FAULT_RESEND_REGISTRATION_AT_3 = "resend_registration_at_3"; +const FAULT_RESEND_REGISTRATION_ONCE = "resend_registration_once"; const DISABLE_FAULTS = "disable_faults"; const ENABLE_FAULTS = "enable_faults"; @@ -175,10 +177,11 @@ class FreeMonWebServer { */ waitRegisters(count) { const qs = this.queryStats.bind(this); + const port = this.port; // Wait for registration to occur assert.soon(function() { const stats = qs(); - print("QS : " + tojson(stats)); + print("w" + port + "| waiting for registers >= (" + count + ") QS : " + tojson(stats)); return stats.registers >= count; }, "Failed to web server register", 60 * 1000); } @@ -190,10 +193,11 @@ class FreeMonWebServer { */ waitMetrics(count) { const qs = this.queryStats.bind(this); + const port = this.port; // Wait for metrics uploads to occur assert.soon(function() { const stats = qs(); - print("QS : " + tojson(stats)); + print("w" + port + "| waiting for metrics >= (" + count + ") QS : " + tojson(stats)); return stats.metrics >= count; }, "Failed to web server metrics", 60 * 1000); } @@ -205,10 +209,11 @@ class FreeMonWebServer { */ waitFaults(count) { const qs = this.queryStats.bind(this); + const port = this.port; // Wait for faults to be triggered assert.soon(function() { const stats = qs(); - print("QS : " + tojson(stats)); + print("w" + port + "| waiting for faults >= (" + count + ") QS : " + tojson(stats)); return stats.faults >= count; }, "Failed to web server faults", 60 * 1000); } diff --git a/jstests/free_mon/libs/mock_http_server.py b/jstests/free_mon/libs/mock_http_server.py index 2005575463c..f6ce1a39299 100644 --- a/jstests/free_mon/libs/mock_http_server.py +++ b/jstests/free_mon/libs/mock_http_server.py @@ -36,12 +36,20 @@ FAULT_HALT_METRICS_5 = "halt_metrics_5" """Fault which causes metrics to return permanentlyDelete = true after 3 uploads.""" FAULT_PERMANENTLY_DELETE_AFTER_3 = "permanently_delete_after_3" +"""Fault which causes metrics to trigger resentRegistration at 3 uploads.""" +FAULT_RESEND_REGISTRATION_AT_3 = "resend_registration_at_3" + +"""Fault which causes metrics to trigger resentRegistration once.""" +FAULT_RESEND_REGISTRATION_ONCE = "resend_registration_once" + # List of supported fault types SUPPORTED_FAULT_TYPES = [ FAULT_FAIL_REGISTER, FAULT_INVALID_REGISTER, FAULT_HALT_METRICS_5, FAULT_PERMANENTLY_DELETE_AFTER_3, + FAULT_RESEND_REGISTRATION_AT_3, + FAULT_RESEND_REGISTRATION_ONCE, ] # Supported POST URL types @@ -117,7 +125,7 @@ class FreeMonHandler(http.server.BaseHTTPRequestHandler): data = bson.BSON.encode({ 'version': bson.int64.Int64(42), 'haltMetricsUploading': False, - 'id': 'mock123', + 'id': '', 'informationalURL': 'http://www.example.com/123', 'message': 'Welcome to the Mock Free Monitoring Endpoint', 'reportingInterval': bson.int64.Int64(1), @@ -177,12 +185,37 @@ You can disable monitoring at any time by running db.disableFreeMonitoring().""" 'reportingInterval': bson.int64.Int64(1), 'message': 'Thanks for all the metrics', }) + elif not disable_faults and \ + stats.metrics_calls > 3 and \ + stats.fault_calls < 1 and fault_type == FAULT_RESEND_REGISTRATION_ONCE: + stats.fault_calls += 1 + data = bson.BSON.encode({ + 'version': bson.int64.Int64(2), + 'haltMetricsUploading': False, + 'permanentlyDelete': False, + 'id': 'mock123', + 'reportingInterval': bson.int64.Int64(1), + 'message': 'Thanks for all the metrics', + 'resendRegistration' : True, + }) + elif not disable_faults and \ + stats.metrics_calls == 3 and fault_type == FAULT_RESEND_REGISTRATION_AT_3: + stats.fault_calls += 1 + data = bson.BSON.encode({ + 'version': bson.int64.Int64(2), + 'haltMetricsUploading': False, + 'permanentlyDelete': False, + 'id': 'mock123', + 'reportingInterval': bson.int64.Int64(1), + 'message': 'Thanks for all the metrics', + 'resendRegistration' : True, + }) else: data = bson.BSON.encode({ 'version': bson.int64.Int64(1), 'haltMetricsUploading': False, 'permanentlyDelete': False, - 'id': 'mock123', + 'id': '', 'reportingInterval': bson.int64.Int64(1), 'message': 'Thanks for all the metrics', }) |