diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/shell/db.js | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/shell/db.js')
| -rw-r--r-- | src/mongo/shell/db.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js index 2364460d62a..d3800871af1 100644 --- a/src/mongo/shell/db.js +++ b/src/mongo/shell/db.js @@ -1745,6 +1745,57 @@ DB.prototype.watch = function(pipeline, options) { return this._runAggregate({aggregate: 1, pipeline: pipeline}, aggOptions); }; +DB.prototype.getFreeMonitoringStatus = function() { + 'use strict'; + return assert.commandWorked(this.adminCommand({getFreeMonitoringStatus: 1})); +}; + +DB.prototype.enableFreeMonitoring = function() { + 'use strict'; + let reply, isPrimary; + if (this.getMongo().getApiParameters().apiVersion) { + reply = this.hello(); + isPrimary = reply.isWritablePrimary; + } else { + reply = this.isMaster(); + isPrimary = reply.ismaster; + } + + if (!isPrimary) { + print("ERROR: db.enableFreeMonitoring() may only be run on a primary"); + return; + } + + assert.commandWorked(this.adminCommand({setFreeMonitoring: 1, action: 'enable'})); + + const cmd = this.adminCommand({getFreeMonitoringStatus: 1}); + if (!cmd.ok && (cmd.code == ErrorCode.Unauthorized)) { + // Edge case: It's technically possible that a user can change free-mon state, + // but is not allowed to inspect it. + print("Successfully initiated free monitoring, but unable to determine status " + + "as you lack the 'checkFreeMonitoringStatus' privilege."); + return; + } + assert.commandWorked(cmd); + + if (cmd.state !== 'enabled') { + const url = this.adminCommand({'getParameter': 1, 'cloudFreeMonitoringEndpointURL': 1}) + .cloudFreeMonitoringEndpointURL; + + print("Unable to get immediate response from the Cloud Monitoring service. We will" + + "continue to retry in the background. Please check your firewall " + + "settings to ensure that mongod can communicate with \"" + url + "\""); + return; + } + + print(tojson(cmd)); +}; + +DB.prototype.disableFreeMonitoring = function() { + 'use strict'; + assert.commandWorked(this.adminCommand({setFreeMonitoring: 1, action: 'disable'})); +}; + // Writing `this.hasOwnProperty` would cause DB.prototype.getCollection() to be called since the // DB's getProperty() handler in C++ takes precedence when a property isn't defined on the DB // instance directly. The "hasOwnProperty" property is defined on Object.prototype, so we must |
