[SERVER-35617] Unpleasant db.enableFreeMonitoring "not master" error on newly launched mongod Created: 15/Jun/18  Updated: 29/Oct/23  Resolved: 01/Aug/18

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 4.0.0-rc5
Fix Version/s: 4.0.2, 4.1.2

Type: Improvement Priority: Trivial - P5
Reporter: Jeremy Mikola Assignee: Mark Benvenuto
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Backwards Compatibility: Fully Compatible
Backport Requested:
v4.0
Sprint: Platforms 2018-08-13
Participants:

 Description   

I launched a new mongod process with an empty database directory:

$ mongod --dbpath /tmp/db --replSet rs

Upon accessing the mongod with the shell, I saw a blurb inviting me to run db.enableFreeMonitoring(). I happened to run this before rs.initiate() and was greeted with the following, unpleasant error:

$ mongo
MongoDB shell version v4.0.0-rc5
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0-rc5
---
Enable MongoDB's free cloud-based monitoring service to collect and display
metrics about your deployment (disk utilization, CPU, operation statistics,
etc).
 
The monitoring data will be available on a MongoDB website with a unique
URL created for you. Anyone you share the URL with will also be able to
view this page. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
 
To enable free monitoring, run the following command:
db.enableFreeMonitoring()
---
 
> db.enableFreeMonitoring()
2018-06-15T13:00:32.014-0400 E QUERY    [js] Error: command failed: {
	"operationTime" : Timestamp(0, 0),
	"ok" : 0,
	"errmsg" : "not master",
	"code" : 10107,
	"codeName" : "NotMaster",
	"$clusterTime" : {
		"clusterTime" : Timestamp(0, 0),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:534:17
assert.commandWorked@src/mongo/shell/assert.js:618:16
DB.prototype.enableFreeMonitoring@src/mongo/shell/db.js:1955:1
@(shell):1:1
>

It may be trivial to improve the user experience here by having db.enableFreeMonitoring check that the active connection is a primary before attempting to run the setFreeMonitoring command.



 Comments   
Comment by Githook User [ 07/Aug/18 ]

Author:

{'name': 'Mark Benvenuto', 'email': 'mark.benvenuto@mongodb.com', 'username': 'markbenvenuto'}

Message: SERVER-35617 Improve free-monitoring message on non-primary node

(cherry picked from commit 30298ed63aadae19bd5494dd0e1f33e329389806)
Branch: v4.0
https://github.com/mongodb/mongo/commit/7ec059c99b21ec708d5bfe0975c16886b7e10072

Comment by Githook User [ 01/Aug/18 ]

Author:

{'username': 'markbenvenuto', 'name': 'Mark Benvenuto', 'email': 'mark.benvenuto@mongodb.com'}

Message: SERVER-35617 Improve free-monitoring message on non-primary node
Branch: master
https://github.com/mongodb/mongo/commit/30298ed63aadae19bd5494dd0e1f33e329389806

Comment by Mark Benvenuto [ 24/Jul/18 ]

jmikola and matt.lord, to improve the user experience when a user either connects to a secondary replica or uninitiated replica set, I can print a message like:

> db.enableFreeMonitoring()
db.enableFreeMonitoring() may only be run on a primary replica

I would like to continue to display the banner without checking replica set status since they may initialize the replica during a given shell session. I am open to suggestions.

Comment by Mark Benvenuto [ 15/Jun/18 ]

We can improve the user experience when in a replica set to check if the replica set has been initialized to give the user guidance about the next steps to take.

Generated at Thu Feb 08 04:40:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.