From 0b8c53ebc9b7dfced39df77e51610536d41b1724 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Wed, 13 Jul 2022 13:16:55 +0300 Subject: [PATCH] [#283] pool: Add number of requests to statistic Signed-off-by: Denis Kirillov --- pool/pool.go | 12 +++++++++++- pool/statistic.go | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pool/pool.go b/pool/pool.go index fa5d368..90b2ead 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -62,6 +62,7 @@ type clientStatus interface { overallErrorRate() uint64 resetErrorCounter() latency() time.Duration + requests() uint64 } type clientStatusMonitor struct { @@ -572,7 +573,15 @@ func (c *clientStatusMonitor) resetErrorCounter() { } func (c *clientStatusMonitor) latency() time.Duration { - return time.Duration(c.allTime.Load() / c.allRequests.Load()) + allRequests := c.requests() + if allRequests == 0 { + return 0 + } + return time.Duration(c.allTime.Load() / allRequests) +} + +func (c *clientStatusMonitor) requests() uint64 { + return c.allRequests.Load() } func (c *clientStatusMonitor) incRequests(elapsed time.Duration) { @@ -1909,6 +1918,7 @@ func (p Pool) Statistic() Statistic { node := &NodeStatistic{ address: cl.address(), latency: cl.latency(), + requests: cl.requests(), overallErrors: cl.overallErrorRate(), currentErrors: cl.currentErrorRate(), } diff --git a/pool/statistic.go b/pool/statistic.go index f7256a8..89e228e 100644 --- a/pool/statistic.go +++ b/pool/statistic.go @@ -40,6 +40,7 @@ func (s Statistic) Node(address string) (*NodeStatistic, error) { type NodeStatistic struct { address string latency time.Duration + requests uint64 overallErrors uint64 currentErrors uint32 } @@ -61,6 +62,11 @@ func (n NodeStatistic) Latency() time.Duration { return n.latency } +// Requests returns number of requests. +func (n NodeStatistic) Requests() uint64 { + return n.requests +} + // Address returns node endpoint address. func (n NodeStatistic) Address() string { return n.address