diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2018-06-18 19:45:08 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2018-06-18 21:44:17 -0400 |
commit | 272625228597da9c04aa9843b8128585da16390a (patch) | |
tree | c27c36417361d4b4e6176eafe766dbc1af785e9c | |
parent | a9a9e398d86591c7559ba26580a38c2d439d7835 (diff) | |
download | mongo-272625228597da9c04aa9843b8128585da16390a.tar.gz |
SERVER-35650 Free Monitoring default interval should be 60 seconds
(cherry picked from commit fc4a3ebf568a3a17cff2a4676a8f4972134747db)
-rw-r--r-- | src/mongo/db/free_mon/free_mon_controller.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/free_mon/free_mon_controller.h | 4 | ||||
-rw-r--r-- | src/mongo/db/free_mon/free_mon_controller_test.cpp | 33 | ||||
-rw-r--r-- | src/mongo/db/free_mon/free_mon_mongod.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/free_mon/free_mon_processor.cpp | 27 | ||||
-rw-r--r-- | src/mongo/db/free_mon/free_mon_processor.h | 3 |
6 files changed, 62 insertions, 23 deletions
diff --git a/src/mongo/db/free_mon/free_mon_controller.cpp b/src/mongo/db/free_mon/free_mon_controller.cpp index 8b3f787b55e..77f30fda1b1 100644 --- a/src/mongo/db/free_mon/free_mon_controller.cpp +++ b/src/mongo/db/free_mon/free_mon_controller.cpp @@ -134,7 +134,9 @@ void FreeMonController::_enqueue(std::shared_ptr<FreeMonMessage> msg) { _processor->enqueue(std::move(msg)); } -void FreeMonController::start(RegistrationType registrationType, std::vector<std::string>& tags) { +void FreeMonController::start(RegistrationType registrationType, + std::vector<std::string>& tags, + Seconds gatherMetricsInterval) { { stdx::lock_guard<stdx::mutex> lock(_mutex); @@ -142,8 +144,11 @@ void FreeMonController::start(RegistrationType registrationType, std::vector<std } // Start the agent - _processor = std::make_shared<FreeMonProcessor>( - _registrationCollectors, _metricCollectors, _network.get(), _useCrankForTest); + _processor = std::make_shared<FreeMonProcessor>(_registrationCollectors, + _metricCollectors, + _network.get(), + _useCrankForTest, + gatherMetricsInterval); _thread = stdx::thread([this] { _processor->run(); }); diff --git a/src/mongo/db/free_mon/free_mon_controller.h b/src/mongo/db/free_mon/free_mon_controller.h index f037a6c68d9..2b7bb89ba8a 100644 --- a/src/mongo/db/free_mon/free_mon_controller.h +++ b/src/mongo/db/free_mon/free_mon_controller.h @@ -59,7 +59,9 @@ public: * Initializes free monitoring. * Start free monitoring thread in the background. */ - void start(RegistrationType registrationType, std::vector<std::string>& tags); + void start(RegistrationType registrationType, + std::vector<std::string>& tags, + Seconds gatherMetricsInterval); /** * Stops free monitoring thread. 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 535e22e0b40..28b164bbfeb 100644 --- a/src/mongo/db/free_mon/free_mon_controller_test.cpp +++ b/src/mongo/db/free_mon/free_mon_controller_test.cpp @@ -556,6 +556,19 @@ TEST(FreeMonProcessorTest, TestRegistrationResponseValidation) { << "reportingInterval" << 1LL)))); + // max reporting interval + ASSERT_OK(FreeMonProcessor::validateRegistrationResponse(FreeMonRegistrationResponse::parse( + IDLParserErrorContext("foo"), + BSON("version" << 1LL << "haltMetricsUploading" << false << "id" + << "mock123" + << "informationalURL" + << "http://www.example.com/123" + << "message" + << "msg456" + << "reportingInterval" + << 30 * 60 * 60 * 24LL)))); + + // Negative: bad protocol version ASSERT_NOT_OK(FreeMonProcessor::validateRegistrationResponse(FreeMonRegistrationResponse::parse( IDLParserErrorContext("foo"), @@ -637,7 +650,7 @@ TEST(FreeMonProcessorTest, TestRegistrationResponseValidation) { << "message" << "msg456" << "reportingInterval" - << (60LL * 60 * 24 + 1LL))))); + << (60LL * 60 * 24 * 30 + 1LL))))); } @@ -656,6 +669,20 @@ TEST(FreeMonProcessorTest, TestMetricsResponseValidation) { << "reportingInterval" << 1LL)))); + // max reporting interval + ASSERT_OK(FreeMonProcessor::validateMetricsResponse(FreeMonMetricsResponse::parse( + IDLParserErrorContext("foo"), + + BSON("version" << 1LL << "haltMetricsUploading" << false << "permanentlyDelete" << false + << "id" + << "mock123" + << "informationalURL" + << "http://www.example.com/123" + << "message" + << "msg456" + << "reportingInterval" + << 60 * 60 * 24 * 30LL)))); + // Negative: bad protocol version ASSERT_NOT_OK(FreeMonProcessor::validateMetricsResponse(FreeMonMetricsResponse::parse( IDLParserErrorContext("foo"), @@ -748,7 +775,7 @@ TEST(FreeMonProcessorTest, TestMetricsResponseValidation) { << "message" << "msg456" << "reportingInterval" - << (60LL * 60 * 24 + 1LL))))); + << (60LL * 60 * 24 * 30 + 1LL))))); } /** @@ -847,7 +874,7 @@ struct ControllerHolder { void start(RegistrationType registrationType) { std::vector<std::string> tags; - controller->start(registrationType, tags); + controller->start(registrationType, tags, Seconds(1)); } diff --git a/src/mongo/db/free_mon/free_mon_mongod.cpp b/src/mongo/db/free_mon/free_mon_mongod.cpp index 15ec0e3e984..9fb00431210 100644 --- a/src/mongo/db/free_mon/free_mon_mongod.cpp +++ b/src/mongo/db/free_mon/free_mon_mongod.cpp @@ -69,6 +69,9 @@ namespace mongo { namespace { + +constexpr Seconds kDefaultMetricsGatherInterval(60); + /** * Expose cloudFreeMonitoringEndpointURL set parameter to URL for free monitoring. */ @@ -360,7 +363,9 @@ void startFreeMonitoring(ServiceContext* serviceContext) { registrationType = RegistrationType::RegisterAfterOnTransitionToPrimaryIfEnabled; } - controllerPtr->start(registrationType, globalFreeMonParams.freeMonitoringTags); + controllerPtr->start(registrationType, + globalFreeMonParams.freeMonitoringTags, + Seconds(kDefaultMetricsGatherInterval)); } void stopFreeMonitoring() { diff --git a/src/mongo/db/free_mon/free_mon_processor.cpp b/src/mongo/db/free_mon/free_mon_processor.cpp index c558ee0fb04..e476278e34b 100644 --- a/src/mongo/db/free_mon/free_mon_processor.cpp +++ b/src/mongo/db/free_mon/free_mon_processor.cpp @@ -60,10 +60,8 @@ constexpr auto kInformationalURLMaxLength = 4096; constexpr auto kInformationalMessageMaxLength = 4096; constexpr auto kUserReminderMaxLength = 4096; -constexpr Seconds kDefaultMetricsGatherInterval(1); - -constexpr auto kReportingIntervalMinutesMin = 1; -constexpr auto kReportingIntervalMinutesMax = 60 * 60 * 24; +constexpr auto kReportingIntervalSecondsMin = 1; +constexpr auto kReportingIntervalSecondsMax = 30 * 60 * 60 * 24; constexpr auto kMetricsRequestArrayElement = "data"_sd; @@ -123,14 +121,15 @@ bool MetricsRetryCounter::incrementError() { FreeMonProcessor::FreeMonProcessor(FreeMonCollectorCollection& registration, FreeMonCollectorCollection& metrics, FreeMonNetworkInterface* network, - bool useCrankForTest) + bool useCrankForTest, + Seconds metricsGatherInterval) : _registration(registration), _metrics(metrics), _network(network), _random(Date_t::now().asInt64()), _registrationRetry(RegistrationRetryCounter(_random)), _metricsRetry(MetricsRetryCounter(_random)), - _metricsGatherInterval(kDefaultMetricsGatherInterval), + _metricsGatherInterval(metricsGatherInterval), _queue(useCrankForTest) { _registrationRetry->reset(); _metricsRetry->reset(); @@ -495,14 +494,14 @@ Status FreeMonProcessor::validateRegistrationResponse(const FreeMonRegistrationR << "'"); } - if (resp.getReportingInterval() < kReportingIntervalMinutesMin || - resp.getReportingInterval() > kReportingIntervalMinutesMax) { + if (resp.getReportingInterval() < kReportingIntervalSecondsMin || + resp.getReportingInterval() > kReportingIntervalSecondsMax) { return Status(ErrorCodes::FreeMonHttpPermanentFailure, str::stream() << "Reporting Interval '" << resp.getReportingInterval() << "' must be in the range [" - << kReportingIntervalMinutesMin + << kReportingIntervalSecondsMin << "," - << kReportingIntervalMinutesMax + << kReportingIntervalSecondsMax << "]"); } @@ -571,14 +570,14 @@ Status FreeMonProcessor::validateMetricsResponse(const FreeMonMetricsResponse& r << "'"); } - if (resp.getReportingInterval() < kReportingIntervalMinutesMin || - resp.getReportingInterval() > kReportingIntervalMinutesMax) { + if (resp.getReportingInterval() < kReportingIntervalSecondsMin || + resp.getReportingInterval() > kReportingIntervalSecondsMax) { return Status(ErrorCodes::FreeMonHttpPermanentFailure, str::stream() << "Reporting Interval '" << resp.getReportingInterval() << "' must be in the range [" - << kReportingIntervalMinutesMin + << kReportingIntervalSecondsMin << "," - << kReportingIntervalMinutesMax + << kReportingIntervalSecondsMax << "]"); } diff --git a/src/mongo/db/free_mon/free_mon_processor.h b/src/mongo/db/free_mon/free_mon_processor.h index 0aaf4c7328e..cfaf1b504ad 100644 --- a/src/mongo/db/free_mon/free_mon_processor.h +++ b/src/mongo/db/free_mon/free_mon_processor.h @@ -283,7 +283,8 @@ public: FreeMonProcessor(FreeMonCollectorCollection& registration, FreeMonCollectorCollection& metrics, FreeMonNetworkInterface* network, - bool useCrankForTest); + bool useCrankForTest, + Seconds metricsGatherInterval); /** * Enqueue a message to process |