diff options
author | Brett Nawrocki <brett.nawrocki@mongodb.com> | 2022-09-22 21:51:04 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-26 23:08:10 +0000 |
commit | b7025a4b61e658d1d07c56e057fcc13e792d6fb4 (patch) | |
tree | 165732ffc6ee3df3b4975acfb4a3efde1150975e /src/mongo/db/s/resharding/resharding_metrics_test.cpp | |
parent | 6592c29983b2c47fd2c19d01d19501e8ef566625 (diff) | |
download | mongo-b7025a4b61e658d1d07c56e057fcc13e792d6fb4.tar.gz |
SERVER-69575 Add unit tests for SDT instance and cumulative metrics
Diffstat (limited to 'src/mongo/db/s/resharding/resharding_metrics_test.cpp')
-rw-r--r-- | src/mongo/db/s/resharding/resharding_metrics_test.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/src/mongo/db/s/resharding/resharding_metrics_test.cpp b/src/mongo/db/s/resharding/resharding_metrics_test.cpp index 99b9d2d7cf6..b36d4a4d3aa 100644 --- a/src/mongo/db/s/resharding/resharding_metrics_test.cpp +++ b/src/mongo/db/s/resharding/resharding_metrics_test.cpp @@ -44,6 +44,7 @@ namespace mongo { namespace { constexpr auto kRunningTime = Seconds(12345); +constexpr auto kResharding = "resharding"; const auto kShardKey = BSON("newKey" << 1); class ReshardingMetricsTest : public ShardingDataTransformMetricsTestFixture { @@ -66,6 +67,10 @@ public: getCumulativeMetrics()); } + virtual StringData getRootSectionName() override { + return kResharding; + } + const UUID& getSourceCollectionId() { static UUID id = UUID::gen(); return id; @@ -194,6 +199,18 @@ public: report = metrics->reportForCurrentOp(); ASSERT_EQ(report.getIntField(fieldName), getExpectedDuration()); } + + void createMetricsAndAssertIncrementsCumulativeMetricsField( + const std::function<void(ReshardingMetrics*)>& mutate, + Section section, + const StringData& fieldName) { + auto metrics = createInstanceMetrics(getClockSource(), UUID::gen(), Role::kCoordinator); + assertIncrementsCumulativeMetricsField( + metrics.get(), + [&](auto base) { mutate(dynamic_cast<ReshardingMetrics*>(base)); }, + section, + fieldName); + } }; TEST_F(ReshardingMetricsTest, ReportForCurrentOpShouldHaveReshardingMetricsDescription) { @@ -534,5 +551,136 @@ TEST_F(ReshardingMetricsTest, CurrentOpDoesNotReportRecipientEstimateIfNotSet) { ASSERT_FALSE(report.hasField("remainingOperationTimeEstimatedSecs")); } +TEST_F(ReshardingMetricsTest, OnInsertAppliedIncrementsCumulativeMetrics) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onInsertApplied(); }, Section::kActive, "insertsApplied"); +} + +TEST_F(ReshardingMetricsTest, OnUpdateAppliedIncrementsCumulativeMetrics) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onUpdateApplied(); }, Section::kActive, "updatesApplied"); +} + +TEST_F(ReshardingMetricsTest, OnDeleteAppliedIncrementsCumulativeMetrics) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onDeleteApplied(); }, Section::kActive, "deletesApplied"); +} + +TEST_F(ReshardingMetricsTest, OnOplogFetchedIncrementsCumulativeMetricsFetchedCount) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onOplogEntriesFetched(1, Milliseconds{0}); }, + Section::kActive, + "oplogEntriesFetched"); +} + +TEST_F(ReshardingMetricsTest, OnOplogFetchedIncrementsCumulativeMetricsFetchedBatchCount) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onOplogEntriesFetched(0, Milliseconds{0}); }, + Section::kLatencies, + "oplogFetchingTotalRemoteBatchesRetrieved"); +} + +TEST_F(ReshardingMetricsTest, OnOplogFetchedIncrementsCumulativeMetricsFetchedBatchTime) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onOplogEntriesFetched(0, Milliseconds{1}); }, + Section::kLatencies, + "oplogFetchingTotalRemoteBatchRetrievalTimeMillis"); +} + +TEST_F(ReshardingMetricsTest, OnLocalFetchingInsertIncrementsCumulativeMetricsFetchedBatchCount) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onLocalInsertDuringOplogFetching(Milliseconds{0}); }, + Section::kLatencies, + "oplogFetchingTotalLocalInserts"); +} + +TEST_F(ReshardingMetricsTest, OnLocalFetchingInsertIncrementsCumulativeMetricsFetchedBatchTime) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onLocalInsertDuringOplogFetching(Milliseconds{1}); }, + Section::kLatencies, + "oplogFetchingTotalLocalInsertTimeMillis"); +} + +TEST_F(ReshardingMetricsTest, OnOplogAppliedIncrementsCumulativeMetricsAppliedCount) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onOplogEntriesApplied(1); }, + Section::kActive, + "oplogEntriesApplied"); +} + +TEST_F(ReshardingMetricsTest, OnApplyingBatchRetrievedIncrementsCumulativeMetricsBatchCount) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onBatchRetrievedDuringOplogApplying(Milliseconds{0}); }, + Section::kLatencies, + "oplogApplyingTotalLocalBatchesRetrieved"); +} + +TEST_F(ReshardingMetricsTest, OnApplyingBatchRetrievedIncrementsCumulativeMetricsBatchTime) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onBatchRetrievedDuringOplogApplying(Milliseconds{1}); }, + Section::kLatencies, + "oplogApplyingTotalLocalBatchRetrievalTimeMillis"); +} + +TEST_F(ReshardingMetricsTest, OnApplyingBatchAppliedIncrementsCumulativeMetricsBatchCount) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onOplogLocalBatchApplied(Milliseconds{0}); }, + Section::kLatencies, + "oplogApplyingTotalLocalBatchesApplied"); +} + +TEST_F(ReshardingMetricsTest, OnApplyingBatchAppliedIncrementsCumulativeMetricsBatchTime) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { metrics->onOplogLocalBatchApplied(Milliseconds{1}); }, + Section::kLatencies, + "oplogApplyingTotalLocalBatchApplyTimeMillis"); +} + +TEST_F(ReshardingMetricsTest, OnStateTransitionFromNoneInformsCumulativeMetrics) { + createMetricsAndAssertIncrementsCumulativeMetricsField( + [](auto metrics) { + metrics->onStateTransition( + boost::none, ReshardingMetrics::CoordinatorState{CoordinatorStateEnum::kApplying}); + }, + Section::kCurrentInSteps, + "countInstancesInCoordinatorState4Applying"); +} + +TEST_F(ReshardingMetricsTest, OnStateTransitionToNoneInformsCumulativeMetrics) { + auto metrics = createInstanceMetrics(getClockSource(), UUID::gen(), Role::kCoordinator); + auto state = ReshardingMetrics::CoordinatorState{CoordinatorStateEnum::kApplying}; + metrics->onStateTransition(boost::none, state); + assertDecrementsCumulativeMetricsField( + metrics.get(), + [=](auto base) { + auto reshardingMetrics = dynamic_cast<ReshardingMetrics*>(base); + reshardingMetrics->onStateTransition(state, boost::none); + }, + Section::kCurrentInSteps, + "countInstancesInCoordinatorState4Applying"); +} + +TEST_F(ReshardingMetricsTest, OnStateTransitionInformsCumulativeMetrics) { + auto metrics = createInstanceMetrics(getClockSource(), UUID::gen(), Role::kCoordinator); + auto initialState = ReshardingMetrics::CoordinatorState{CoordinatorStateEnum::kApplying}; + auto nextState = ReshardingMetrics::CoordinatorState{CoordinatorStateEnum::kBlockingWrites}; + metrics->onStateTransition(boost::none, initialState); + assertAltersCumulativeMetrics( + metrics.get(), + [=](auto base) { + auto reshardingMetrics = dynamic_cast<ReshardingMetrics*>(base); + reshardingMetrics->onStateTransition(initialState, nextState); + }, + [this](auto reportBefore, auto reportAfter) { + auto before = getReportSection(reportBefore, Section::kCurrentInSteps); + ASSERT_EQ(before.getIntField("countInstancesInCoordinatorState4Applying"), 1); + ASSERT_EQ(before.getIntField("countInstancesInCoordinatorState5BlockingWrites"), 0); + auto after = getReportSection(reportAfter, Section::kCurrentInSteps); + ASSERT_EQ(after.getIntField("countInstancesInCoordinatorState4Applying"), 0); + ASSERT_EQ(after.getIntField("countInstancesInCoordinatorState5BlockingWrites"), 1); + return true; + }); +} + } // namespace } // namespace mongo |