From bf180545a8eb6272ec21332f97db42ed097a3cb3 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Tue, 20 Jun 2023 14:08:36 +0400 Subject: [PATCH] pool: Add noop statistic Signed-off-by: Evgenii Baidakov --- pool/pool.go | 6 +++--- pool/status.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 pool/status.go diff --git a/pool/pool.go b/pool/pool.go index 3055946f..90c0b2de 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -1595,9 +1595,9 @@ func fillDefaultInitParams(params *InitParameters, cache *sessionCache) { return nil }) - var statistic ClientStatus - if params.statistic == nil { - // statistic is disabled by default. + // statistic is disabled by default. + var statistic = params.statistic + if statistic == nil { statistic = newNoOpClientStatusMonitor(prm.address) } diff --git a/pool/status.go b/pool/status.go new file mode 100644 index 00000000..2964690a --- /dev/null +++ b/pool/status.go @@ -0,0 +1,46 @@ +package pool + +import ( + "time" +) + +// noOpClientStatusMonitor is using by default for pool. +type noOpClientStatusMonitor struct { + addr string +} + +func newNoOpClientStatusMonitor(addr string) noOpClientStatusMonitor { + return noOpClientStatusMonitor{addr: addr} +} + +func (n noOpClientStatusMonitor) updateErrorRate(_ error) { +} + +func (n noOpClientStatusMonitor) incRequests(_ time.Duration, _ MethodIndex) { +} + +func (n noOpClientStatusMonitor) isHealthy() bool { + return true +} + +func (n noOpClientStatusMonitor) setUnhealthy() { +} + +func (n noOpClientStatusMonitor) setHealthy() { +} + +func (n noOpClientStatusMonitor) address() string { + return n.addr +} + +func (n noOpClientStatusMonitor) currentErrorRate() uint32 { + return 0 +} + +func (n noOpClientStatusMonitor) overallErrorRate() uint64 { + return 0 +} + +func (n noOpClientStatusMonitor) methodsStatus() []statusSnapshot { + return nil +}