mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 09:54:18 +02:00
tune cluster ls: parallized and use tcp connect instead of https (#63)
This commit is contained in:
@@ -31,44 +31,62 @@ import (
|
||||
|
||||
type ClusterIndices map[string]map[string]*types.IndicesRecord
|
||||
|
||||
func ClusterList(conf *cfg.Config) error {
|
||||
table := printer.NewTable(conf, 5, len(conf.Clusters))
|
||||
type clusterReachable struct {
|
||||
reachable bool
|
||||
err error
|
||||
}
|
||||
|
||||
func ClusterList(conf *cfg.Config) error {
|
||||
var mu sync.Mutex
|
||||
var wg sync.WaitGroup
|
||||
reachable := make(map[string]clusterReachable, len(conf.Clusters))
|
||||
|
||||
// check endpoints in parallel to speed things up
|
||||
for name, cluster := range conf.Clusters {
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
online, err := cluster.IsReachable()
|
||||
|
||||
mu.Lock()
|
||||
reachable[name] = clusterReachable{reachable: online, err: err}
|
||||
mu.Unlock()
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
table := printer.NewTable(conf, 5, len(conf.Clusters))
|
||||
table.Addheaders("cluster", "uri", "reachable", "current", "error")
|
||||
|
||||
idx := 0
|
||||
|
||||
for name, cluster := range conf.Clusters {
|
||||
reachable := "no"
|
||||
reachableStr := "no"
|
||||
current := "no"
|
||||
errmsg := ""
|
||||
|
||||
online, err := cluster.IsReachable()
|
||||
|
||||
if online {
|
||||
reachable = printer.Colorize(conf, "green", "reachable")
|
||||
if reachable[name].reachable {
|
||||
reachableStr = printer.Colorize(conf, "green", "reachable")
|
||||
}
|
||||
|
||||
if cluster.Default {
|
||||
current = printer.Colorize(conf, "green", "yes")
|
||||
|
||||
if !online {
|
||||
reachable = printer.Colorize(conf, "red", "no")
|
||||
errmsg = err.Error()
|
||||
if !reachable[name].reachable {
|
||||
reachableStr = printer.Colorize(conf, "red", "no")
|
||||
errmsg = reachable[name].err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
table.Entries[idx] = []string{name, cluster.Uri, reachable, current, errmsg}
|
||||
table.Entries[idx] = []string{name, cluster.Uri, reachableStr, current, errmsg}
|
||||
idx++
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
|
||||
if err := table.Print(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return table.Print()
|
||||
}
|
||||
|
||||
// We're using goroutines here to parallelize API requests, since we
|
||||
|
||||
Reference in New Issue
Block a user