From 0314b326d31eb19d41bcb1dc59bc9215780ff654 Mon Sep 17 00:00:00 2001 From: Artem Tataurov Date: Tue, 15 Aug 2023 09:51:13 +0300 Subject: [PATCH] [#51] Add current nodes as external statistics Signed-off-by: Artem Tataurov --- pool/pool.go | 7 +++++++ pool/statistic.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/pool/pool.go b/pool/pool.go index 075ba7f..db3b298 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -2482,8 +2482,12 @@ func (p *Pool) Balance(ctx context.Context, prm PrmBalanceGet) (accounting.Decim func (p Pool) Statistic() Statistic { stat := Statistic{} for _, inner := range p.innerPools { + nodes := make([]string, 0, len(inner.clients)) inner.lock.RLock() for _, cl := range inner.clients { + if cl.isHealthy() { + nodes = append(nodes, cl.address()) + } node := NodeStatistic{ address: cl.address(), methods: cl.methodsStatus(), @@ -2494,6 +2498,9 @@ func (p Pool) Statistic() Statistic { stat.overallErrors += node.overallErrors } inner.lock.RUnlock() + if len(stat.currentNodes) == 0 { + stat.currentNodes = nodes + } } return stat diff --git a/pool/statistic.go b/pool/statistic.go index 3a4f424..5f1cfad 100644 --- a/pool/statistic.go +++ b/pool/statistic.go @@ -9,6 +9,7 @@ import ( type Statistic struct { overallErrors uint64 nodes []NodeStatistic + currentNodes []string } // OverallErrors returns sum of errors on all connections. It doesn't decrease. @@ -21,6 +22,12 @@ func (s Statistic) Nodes() []NodeStatistic { return s.nodes } +// CurrentNodes returns list of nodes of inner pool that has at least one healthy node. +// These nodes have the same and the highest priority among the other healthy nodes. +func (s Statistic) CurrentNodes() []string { + return s.currentNodes +} + // ErrUnknownNode indicate that node with current address is not found in list. var ErrUnknownNode = errors.New("unknown node")