[#51] Add current nodes as external statistics

Signed-off-by: Artem Tataurov <a.tataurov@yadro.com>
This commit is contained in:
Artem Tataurov 2023-08-15 09:51:13 +03:00
parent 0382785763
commit 0314b326d3
2 changed files with 14 additions and 0 deletions

View file

@ -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

View file

@ -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")