summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/free_mon/free_mon_controller_test.cpp62
-rw-r--r--src/mongo/db/free_mon/free_mon_mongod.cpp2
-rw-r--r--src/mongo/db/free_mon/free_mon_processor.cpp16
-rw-r--r--src/mongo/db/free_mon/free_mon_processor.h4
-rw-r--r--src/mongo/db/free_mon/http_client_winhttp.cpp7
-rw-r--r--src/mongo/shell/dbshell.cpp3
-rw-r--r--src/mongo/shell/mongo.js8
-rw-r--r--src/mongo/shell/utils.js41
8 files changed, 81 insertions, 62 deletions
diff --git a/src/mongo/db/free_mon/free_mon_controller_test.cpp b/src/mongo/db/free_mon/free_mon_controller_test.cpp
index a16eb53acac..71db8b75fba 100644
--- a/src/mongo/db/free_mon/free_mon_controller_test.cpp
+++ b/src/mongo/db/free_mon/free_mon_controller_test.cpp
@@ -175,8 +175,10 @@ public:
if (_count > 0) {
--_count;
- _payload = std::move(payload);
- _condvar.notify_one();
+ if (_count == 0) {
+ _payload = std::move(payload);
+ _condvar.notify_one();
+ }
}
}
@@ -860,7 +862,6 @@ struct ControllerHolder {
std::unique_ptr<FreeMonController> controller;
};
-
// Positive: Test Register works
TEST_F(FreeMonControllerTest, TestRegister) {
ControllerHolder controller(_mockThreadPool.get(), FreeMonNetworkInterfaceMock::Options());
@@ -1019,11 +1020,11 @@ TEST_F(FreeMonControllerTest, TestMetricsWithDisabledStorageThenRegister) {
FreeMonStorage::replace(_opCtx.get(), initStorage(StorageStateEnum::disabled));
controller.start(RegistrationType::RegisterAfterOnTransitionToPrimary);
- controller->turnCrankForTest(Turner().registerServer().collect(4));
+ controller->turnCrankForTest(Turner().registerServer().metricsSend().collect(4));
ASSERT_OK(controller->registerServerCommand(Milliseconds::min()));
- controller->turnCrankForTest(Turner().registerCommand().collect(2).metricsSend());
+ controller->turnCrankForTest(Turner().registerCommand().metricsSend().collect(2).metricsSend());
ASSERT_GTE(controller.network->getRegistersCalls(), 1);
ASSERT_GTE(controller.network->getMetricsCalls(), 1);
@@ -1040,7 +1041,7 @@ TEST_F(FreeMonControllerTest, TestMetricsWithDisabledStorageThenRegisterAndRereg
FreeMonStorage::replace(_opCtx.get(), initStorage(StorageStateEnum::disabled));
controller.start(RegistrationType::RegisterAfterOnTransitionToPrimary);
- controller->turnCrankForTest(Turner().registerServer().collect(4));
+ controller->turnCrankForTest(Turner().registerServer().metricsSend().collect(4));
ASSERT_OK(controller->registerServerCommand(Milliseconds::min()));
@@ -1056,7 +1057,7 @@ TEST_F(FreeMonControllerTest, TestMetricsWithDisabledStorageThenRegisterAndRereg
ASSERT_OK(controller->registerServerCommand(Milliseconds::min()));
- controller->turnCrankForTest(Turner().registerCommand().collect(2).metricsSend());
+ controller->turnCrankForTest(Turner().registerCommand().metricsSend().collect(2).metricsSend());
ASSERT_TRUE(FreeMonStorage::read(_opCtx.get())->getState() == StorageStateEnum::enabled);
@@ -1102,7 +1103,7 @@ TEST_F(FreeMonControllerTest, TestMetricsHalt) {
controller.start(RegistrationType::RegisterOnStart);
controller->turnCrankForTest(
- Turner().registerServer().registerCommand().collect(4).metricsSend());
+ Turner().registerServer().registerCommand().metricsSend().collect(4).metricsSend());
ASSERT_TRUE(!FreeMonStorage::read(_opCtx.get()).get().getRegistrationId().empty());
ASSERT_TRUE(FreeMonStorage::read(_opCtx.get()).get().getState() == StorageStateEnum::disabled);
@@ -1166,13 +1167,11 @@ TEST_F(FreeMonControllerTest, TestPreRegistrationMetricBatching) {
controller.start(RegistrationType::RegisterAfterOnTransitionToPrimary);
- controller->turnCrankForTest(Turner().registerServer().collect(3));
+ controller->turnCrankForTest(Turner().registerServer().collect(4));
ASSERT_OK(controller->registerServerCommand(Milliseconds::min()));
- controller->turnCrankForTest(Turner().registerCommand().collect(1));
-
- controller->turnCrankForTest(Turner().metricsSend().collect(1));
+ controller->turnCrankForTest(Turner().registerCommand().metricsSend());
// Ensure we sent all the metrics batched before registration
ASSERT_EQ(controller.network->getLastMetrics().nFields(), 4);
@@ -1183,27 +1182,6 @@ TEST_F(FreeMonControllerTest, TestPreRegistrationMetricBatching) {
ASSERT_EQ(controller.network->getLastMetrics().nFields(), 2);
}
-// Negative: Test metrics buffers on failure, and retries
-TEST_F(FreeMonControllerTest, TestMetricBatchingOnError) {
- FreeMonNetworkInterfaceMock::Options opts;
- opts.fail2MetricsUploads = true;
- ControllerHolder controller(_mockThreadPool.get(), opts);
-
- controller.start(RegistrationType::RegisterOnStart);
-
- controller->turnCrankForTest(Turner().registerServer().registerCommand().collect(2));
-
- controller->turnCrankForTest(Turner().metricsSend().collect());
-
- // Ensure we sent all the metrics batched before registration
- ASSERT_EQ(controller.network->getLastMetrics().nFields(), 2);
-
- controller->turnCrankForTest(Turner().metricsSend().collect());
-
- // Ensure we resent all the failed metrics
- ASSERT_EQ(controller.network->getLastMetrics().nFields(), 3);
-}
-
// Negative: Test metrics buffers on failure, and retries and ensure 2 metrics occurs after a blip
// of an error
// Note: this test operates in real-time because it needs to test multiple retries matched with
@@ -1215,18 +1193,13 @@ TEST_F(FreeMonControllerTest, TestMetricBatchingOnErrorRealtime) {
controller.start(RegistrationType::RegisterOnStart);
- // Ensure the first upload sends 2 samples
- ASSERT_TRUE(controller.network->waitMetricsCalls(1, Seconds(5)).is_initialized());
+ // Ensure the second upload sends 1 samples
+ ASSERT_TRUE(controller.network->waitMetricsCalls(2, Seconds(5)).is_initialized());
ASSERT_EQ(controller.network->getLastMetrics().nFields(), 2);
- // Ensure the second upload sends 3 samples because first failed
- ASSERT_TRUE(controller.network->waitMetricsCalls(1, Seconds(5)).is_initialized());
- ASSERT_EQ(controller.network->getLastMetrics().nFields(), 3);
-
- // Ensure the third upload sends 5 samples because second failed
- // Since the second retry is 2s, we collected 2 samples
+ // Ensure the third upload sends 3 samples because first failed
ASSERT_TRUE(controller.network->waitMetricsCalls(1, Seconds(5)).is_initialized());
- ASSERT_GTE(controller.network->getLastMetrics().nFields(), 4);
+ ASSERT_EQ(controller.network->getLastMetrics().nFields(), 4);
// Ensure the fourth upload sends 2 samples
ASSERT_TRUE(controller.network->waitMetricsCalls(1, Seconds(5)).is_initialized());
@@ -1460,7 +1433,8 @@ TEST_F(FreeMonControllerRSTest, SecondaryStartOnBadUpdate) {
controller.start(RegistrationType::RegisterAfterOnTransitionToPrimary);
- controller->turnCrankForTest(Turner().registerServer().registerCommand().collect(2));
+ controller->turnCrankForTest(
+ Turner().registerServer().registerCommand().metricsSend().collect(2));
controller->notifyOnUpsert(BSON("version" << 2LL));
@@ -1497,7 +1471,7 @@ TEST_F(FreeMonControllerRSTest, SecondaryRollbackStopMetrics) {
controller->notifyOnRollback();
controller->turnCrankForTest(
- Turner().notifyOnRollback().registerCommand().collect(2).metricsSend());
+ Turner().notifyOnRollback().registerCommand().metricsSend().collect(2).metricsSend());
// Since there is no local write, it remains enabled
ASSERT_TRUE(FreeMonStorage::read(_opCtx.get()).get().getState() == StorageStateEnum::enabled);
diff --git a/src/mongo/db/free_mon/free_mon_mongod.cpp b/src/mongo/db/free_mon/free_mon_mongod.cpp
index 9b022fcb85e..15ec0e3e984 100644
--- a/src/mongo/db/free_mon/free_mon_mongod.cpp
+++ b/src/mongo/db/free_mon/free_mon_mongod.cpp
@@ -76,7 +76,7 @@ class ExportedFreeMonEndpointURL : public LockedServerParameter<std::string> {
public:
ExportedFreeMonEndpointURL()
: LockedServerParameter<std::string>("cloudFreeMonitoringEndpointURL",
- "https://localhost:8080",
+ "https://cloud.mongodb.com/freemonitoring/mongo",
ServerParameterType::kStartupOnly) {}
diff --git a/src/mongo/db/free_mon/free_mon_processor.cpp b/src/mongo/db/free_mon/free_mon_processor.cpp
index 2e2d1a70808..c192ab21d93 100644
--- a/src/mongo/db/free_mon/free_mon_processor.cpp
+++ b/src/mongo/db/free_mon/free_mon_processor.cpp
@@ -318,6 +318,9 @@ void FreeMonProcessor::writeState(Client* client) {
void FreeMonProcessor::doServerRegister(
Client* client, const FreeMonMessageWithPayload<FreeMonMessageType::RegisterServer>* msg) {
+ // Enqueue the first metrics gather first so we have something to send on intial registration
+ enqueue(FreeMonMessage::createNow(FreeMonMessageType::MetricsCollect));
+
// If we are asked to register now, then kick off a registration request
const auto regType = msg->getPayload().first;
if (regType == RegistrationType::RegisterOnStart) {
@@ -350,9 +353,6 @@ void FreeMonProcessor::doServerRegister(
}
}
}
-
- // Enqueue the first metrics gather unless we are not going to register
- enqueue(FreeMonMessage::createNow(FreeMonMessageType::MetricsCollect));
}
namespace {
@@ -623,6 +623,7 @@ void FreeMonProcessor::doAsyncRegisterComplete(
// Update in-memory state
_registrationRetry->setMin(Seconds(resp.getReportingInterval()));
+ _metricsGatherInterval = Seconds(resp.getReportingInterval());
{
auto state = _state.synchronize();
@@ -651,9 +652,8 @@ void FreeMonProcessor::doAsyncRegisterComplete(
log() << "Free Monitoring is Enabled. Frequency: " << resp.getReportingInterval() << " seconds";
- // Enqueue next metrics upload
- enqueue(FreeMonMessage::createWithDeadline(FreeMonMessageType::MetricsSend,
- _registrationRetry->getNextDeadline(client)));
+ // Enqueue next metrics upload immediately to deliver a good experience
+ enqueue(FreeMonMessage::createNow(FreeMonMessageType::MetricsSend));
}
void FreeMonProcessor::doAsyncRegisterFail(
@@ -823,12 +823,13 @@ void FreeMonProcessor::doAsyncMetricsComplete(
writeState(client);
// Reset retry counter
+ _metricsGatherInterval = Seconds(resp.getReportingInterval());
_metricsRetry->setMin(Seconds(resp.getReportingInterval()));
_metricsRetry->reset();
// Enqueue next metrics upload
enqueue(FreeMonMessage::createWithDeadline(FreeMonMessageType::MetricsSend,
- _registrationRetry->getNextDeadline(client)));
+ _metricsRetry->getNextDeadline(client)));
}
void FreeMonProcessor::doAsyncMetricsFail(
@@ -906,7 +907,6 @@ void FreeMonProcessor::processInMemoryStateChange(const FreeMonStorageState& ori
}
}
-
void FreeMonProcessor::doNotifyOnUpsert(
Client* client, const FreeMonMessageWithPayload<FreeMonMessageType::NotifyOnUpsert>* msg) {
try {
diff --git a/src/mongo/db/free_mon/free_mon_processor.h b/src/mongo/db/free_mon/free_mon_processor.h
index 06bfd15b140..0aaf4c7328e 100644
--- a/src/mongo/db/free_mon/free_mon_processor.h
+++ b/src/mongo/db/free_mon/free_mon_processor.h
@@ -247,7 +247,9 @@ public:
if (_count > 0) {
--_count;
- _condvar.notify_one();
+ if (_count == 0) {
+ _condvar.notify_one();
+ }
}
}
diff --git a/src/mongo/db/free_mon/http_client_winhttp.cpp b/src/mongo/db/free_mon/http_client_winhttp.cpp
index 589642d46ae..4393562c5ab 100644
--- a/src/mongo/db/free_mon/http_client_winhttp.cpp
+++ b/src/mongo/db/free_mon/http_client_winhttp.cpp
@@ -205,6 +205,13 @@ private:
return;
}
+ DWORD setting;
+ DWORD settingLength = sizeof(setting);
+ setting = WINHTTP_OPTION_REDIRECT_POLICY_NEVER;
+ if (!WinHttpSetOption(session, WINHTTP_OPTION_REDIRECT_POLICY, &setting, settingLength)) {
+ setError("Failed setting HTTP session option");
+ return;
+ }
if (!WinHttpSetTimeouts(
session, kResolveTimeout, kConnectTimeout, kSendTimeout, kReceiveTimeout)) {
setError("Failed setting HTTP timeout");
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp
index 9155154a4dd..c06d9a568b7 100644
--- a/src/mongo/shell/dbshell.cpp
+++ b/src/mongo/shell/dbshell.cpp
@@ -1026,6 +1026,9 @@ int _main(int argc, char* argv[], char** envp) {
scope->exec(
"shellHelper( 'show', 'startupWarnings' )", "(shellwarnings)", false, true, false);
+ scope->exec(
+ "shellHelper( 'show', 'freeMonitoring' )", "(freeMonitoring)", false, true, false);
+
scope->exec("shellHelper( 'show', 'automationNotices' )",
"(automationnotices)",
false,
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index 98c5676b554..bfb1e04f7cf 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -266,14 +266,6 @@ connect = function(url, user, pass) {
chatty("WARNING: shell and server versions do not match");
}
- // Optionally display free monitoring message.
- const freemonStatus = db.adminCommand({getFreeMonitoringStatus: 1});
- if (freemonStatus.ok) {
- if (freemonStatus.userReminder) {
- chatty(freemonStatus.userReminder);
- }
- }
-
return db;
};
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index 54ceb590ba5..3820eac4f36 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -999,6 +999,47 @@ shellHelper.show = function(what) {
}
}
+ if (what == "freeMonitoring") {
+ var dbDeclared, ex;
+ try {
+ // !!db essentially casts db to a boolean
+ // Will throw a reference exception if db hasn't been declared.
+ dbDeclared = !!db;
+ } catch (ex) {
+ dbDeclared = false;
+ }
+
+ if (dbDeclared) {
+ const freemonStatus = db.adminCommand({getFreeMonitoringStatus: 1});
+
+ if (freemonStatus.ok) {
+ if (freemonStatus.state == 'enabled' &&
+ freemonStatus.hasOwnProperty('userReminder')) {
+ print("---");
+ print(freemonStatus.userReminder);
+ print("---");
+ } 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" +
+ "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");
+ }
+ }
+
+ return "";
+ } else {
+ print("Cannot show freeMonitoring, \"db\" is not set");
+ return "";
+ }
+ }
+
throw Error("don't know how to show [" + what + "]");
};