summaryrefslogtreecommitdiff
path: root/src/mongo/db/process_health/health_observer_base.h
diff options
context:
space:
mode:
authorLaMont Nelson <lamont.nelson@mongodb.com>2021-12-08 01:24:59 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-08 01:57:50 +0000
commit51eefdb2c89e0e2ad03a13e333447d0fc7971436 (patch)
treed0af8423151501808a1a1f6a2f5e08f0f9139ffb /src/mongo/db/process_health/health_observer_base.h
parent280b35dbc2f71e692df3e02e399e997575e00bf0 (diff)
downloadmongo-51eefdb2c89e0e2ad03a13e333447d0fc7971436.tar.gz
SERVER-59397 Add jitter when scheduling next health check
Diffstat (limited to 'src/mongo/db/process_health/health_observer_base.h')
-rw-r--r--src/mongo/db/process_health/health_observer_base.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/mongo/db/process_health/health_observer_base.h b/src/mongo/db/process_health/health_observer_base.h
index f415a8e034a..73f4e9346d8 100644
--- a/src/mongo/db/process_health/health_observer_base.h
+++ b/src/mongo/db/process_health/health_observer_base.h
@@ -57,12 +57,6 @@ public:
return _svcCtx;
}
- /**
- * @return Milliseconds the shortest interval it is safe to repeat this check on.
- */
- virtual Milliseconds minimalCheckInterval() const {
- return Milliseconds(10);
- }
// Implements the common logic for periodic checks.
// Every observer should implement periodicCheckImpl() for specific tests.
@@ -75,6 +69,7 @@ public:
HealthCheckStatus makeSimpleFailedStatus(double severity, std::vector<Status>&& failures) const;
HealthObserverLivenessStats getStats() const override;
+ Milliseconds healthCheckJitter() const override;
// Common params for every health check.
struct PeriodicHealthCheckContext {
@@ -94,6 +89,14 @@ protected:
HealthObserverLivenessStats getStatsLocked(WithLock) const;
+ template <typename T>
+ T randDuration(T upperBound) const {
+ auto upperCount = durationCount<T>(upperBound);
+ stdx::lock_guard lock(_mutex);
+ auto resultCount = _rand.nextInt64(upperCount);
+ return T(resultCount);
+ }
+
ServiceContext* const _svcCtx;
mutable Mutex _mutex =
@@ -107,6 +110,8 @@ protected:
Date_t _lastTimeCheckCompleted;
int _completedChecksCount = 0;
int _completedChecksWithFaultCount = 0;
+
+ mutable PseudoRandom _rand;
};
} // namespace process_health