mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:34:18 +02:00
Add CI pipelines, fix linting issues (#12)
This commit is contained in:
@@ -78,7 +78,7 @@ func ClusterCompare(conf *cfg.Config, leader, follower string) error {
|
||||
}
|
||||
|
||||
if !checkClusterStatus(conf, leader, follower) {
|
||||
return errors.New("One of the two clusters is in a failed state")
|
||||
return errors.New("one of the two clusters is in a failed state")
|
||||
}
|
||||
|
||||
findIlmErrors(conf, leader, follower)
|
||||
@@ -115,7 +115,9 @@ func ClusterList(conf *cfg.Config) error {
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -126,7 +128,7 @@ func ClusterStatus(conf *cfg.Config) error {
|
||||
clusters := []string{}
|
||||
|
||||
if conf.All {
|
||||
for key, _ := range conf.Clusters {
|
||||
for key := range conf.Clusters {
|
||||
clusters = append(clusters, key)
|
||||
}
|
||||
} else {
|
||||
@@ -186,8 +188,8 @@ func ClusterStatus(conf *cfg.Config) error {
|
||||
table.Addheaders(cluster, "status")
|
||||
|
||||
table.entries = [][]string{
|
||||
{"Cluster Name", Colorize(*&clusterhealth.Status.Name, clusterhealth.ClusterName)},
|
||||
{"ES Version", fmt.Sprintf("%s", info.Version.Int)},
|
||||
{"Cluster Name", Colorize(clusterhealth.Status.Name, clusterhealth.ClusterName)},
|
||||
{"ES Version", info.Version.Int},
|
||||
{"Active Shards", fmt.Sprintf("%d", clusterhealth.ActiveShards)},
|
||||
{"Active Primary Shards", fmt.Sprintf("%d", clusterhealth.ActivePrimaryShards)},
|
||||
{"Indicies", fmt.Sprintf("%d", len(clusterhealth.Indices))},
|
||||
@@ -195,7 +197,9 @@ func ClusterStatus(conf *cfg.Config) error {
|
||||
{"AutoFollow (success/failed indices)", ccrfollowing},
|
||||
}
|
||||
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -244,9 +248,11 @@ func ClusterSettingsList(conf *cfg.Config) error {
|
||||
}
|
||||
|
||||
table.entries = entries
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -30,68 +30,6 @@ import (
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types"
|
||||
)
|
||||
|
||||
// look for indicies only on leader
|
||||
func findIndicesOnlyOnMaster(conf *cfg.Config, indices ClusterIndices, leader, follower string) {
|
||||
exclude := regexp.MustCompile(DefaultExclude)
|
||||
if conf.Exclude != "" {
|
||||
exclude = regexp.MustCompile(conf.Exclude)
|
||||
}
|
||||
|
||||
indexOnlyOnLeader := map[string]*types.IndicesRecord{}
|
||||
for name, index := range indices[leader] {
|
||||
if exclude.MatchString(name) {
|
||||
continue
|
||||
}
|
||||
|
||||
_, followerHasIt := indices[follower][name]
|
||||
if !followerHasIt {
|
||||
// fetch index details
|
||||
res, err := conf.Clusters[leader].ES.Indices.Get(name).
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json").
|
||||
Do(context.Background())
|
||||
if err != nil {
|
||||
continue // ignore it then
|
||||
}
|
||||
|
||||
_, defined := res[name]
|
||||
if !defined {
|
||||
// json response map didn't contain the index
|
||||
continue
|
||||
}
|
||||
|
||||
isWritable := false
|
||||
for _, alias := range res[name].Aliases {
|
||||
if *alias.IsWriteIndex {
|
||||
isWritable = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isWritable {
|
||||
// ignore index if associated alias index is writing
|
||||
continue
|
||||
}
|
||||
|
||||
indexOnlyOnLeader[name] = index
|
||||
}
|
||||
}
|
||||
|
||||
idx := 0
|
||||
table := NewTable(3, len(indexOnlyOnLeader))
|
||||
table.Addheaders("index only on leader", "size", "docscount")
|
||||
|
||||
for name, index := range indexOnlyOnLeader {
|
||||
name := Colorize("red", name)
|
||||
|
||||
table.entries[idx] = []string{name, *index.DatasetSize, *index.DocsCount}
|
||||
idx++
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
}
|
||||
|
||||
func checkClusterFollower(conf *cfg.Config, leader string) bool {
|
||||
stats, err := conf.Clusters[leader].ES.Ccr.Stats().
|
||||
Header("content-type", "application/json").
|
||||
@@ -138,8 +76,8 @@ func checkClusterStatus(conf *cfg.Config, leader, follower string) bool {
|
||||
|
||||
table.entries = [][]string{
|
||||
{"Cluster Name",
|
||||
Colorize(*&status[leader].Status.Name, status[leader].ClusterName),
|
||||
Colorize(*&status[follower].Status.Name, status[follower].ClusterName),
|
||||
Colorize(status[leader].Status.Name, status[leader].ClusterName),
|
||||
Colorize(status[follower].Status.Name, status[follower].ClusterName),
|
||||
},
|
||||
{"Active Shards",
|
||||
fmt.Sprintf("%d", status[leader].ActiveShards),
|
||||
@@ -159,7 +97,10 @@ func checkClusterStatus(conf *cfg.Config, leader, follower string) bool {
|
||||
},
|
||||
}
|
||||
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
|
||||
if status[leader].Status.Name == "green" && status[follower].Status.Name == "green" {
|
||||
return true
|
||||
@@ -215,7 +156,11 @@ func findIlmErrors(conf *cfg.Config, leader, follower string) bool {
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +230,10 @@ func findIndicesOnlyOnLeader(conf *cfg.Config, indices ClusterIndices, leader, f
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -332,7 +280,10 @@ func findOrphanedIndices(conf *cfg.Config, indices ClusterIndices, leader, follo
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -363,7 +314,10 @@ func findFailedFollowerIndices(conf *cfg.Config, indices ClusterIndices, followe
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -28,12 +28,6 @@ import (
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/healthstatus"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
wait_for_active_shards string
|
||||
number_of_shards int
|
||||
number_of_replicas int
|
||||
}
|
||||
|
||||
// used for completion
|
||||
func IndexNames(conf *cfg.Config) ([]string, error) {
|
||||
res, err := conf.DefaultCluster.ES.Cat.Indices().
|
||||
@@ -42,7 +36,7 @@ func IndexNames(conf *cfg.Config) ([]string, error) {
|
||||
Do(context.Background())
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error getting indicies: %s", err)
|
||||
return nil, fmt.Errorf("failed to get indicies: %s", err)
|
||||
}
|
||||
|
||||
indices := make([]string, len(res))
|
||||
@@ -65,7 +59,7 @@ func IndexList(conf *cfg.Config) error {
|
||||
|
||||
res, err := cat.Do(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error getting indicies: %s", err)
|
||||
return fmt.Errorf("failed to get indicies: %s", err)
|
||||
}
|
||||
|
||||
slog.Debug("ES result", "indicies", res)
|
||||
@@ -92,7 +86,9 @@ func IndexList(conf *cfg.Config) error {
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -131,7 +127,9 @@ func IndexShow(conf *cfg.Config, index string) error {
|
||||
{"uuid", *res[index].Settings.Index.Uuid},
|
||||
}
|
||||
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func NodeList(conf *cfg.Config) error {
|
||||
// get nodes
|
||||
nodes, err := conf.DefaultCluster.ES.Cat.Nodes().Do(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error getting nodes: %s", err)
|
||||
return fmt.Errorf("failed to get nodes: %s", err)
|
||||
}
|
||||
|
||||
slog.Debug("ES result", "nodes", nodes)
|
||||
@@ -49,7 +49,9 @@ func NodeList(conf *cfg.Config) error {
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func Search(conf *cfg.Config, q string) error {
|
||||
}).
|
||||
Do(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error running search (esdsl): %s", err)
|
||||
return fmt.Errorf("failed to run search (esdsl): %s", err)
|
||||
}
|
||||
|
||||
slog.Debug("ES result", "search", res)
|
||||
|
||||
@@ -44,7 +44,7 @@ func SnapshotList(conf *cfg.Config) error {
|
||||
// get partial indicies
|
||||
ires, err := conf.DefaultCluster.ES.Cat.Indices().Do(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error getting indicies: %s", err)
|
||||
return fmt.Errorf("failed to get indicies: %s", err)
|
||||
}
|
||||
|
||||
indicies := map[string]int{}
|
||||
@@ -57,7 +57,7 @@ func SnapshotList(conf *cfg.Config) error {
|
||||
// get snapshots
|
||||
sres, err := conf.DefaultCluster.ES.Cat.Snapshots().Do(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error getting snapshots: %s", err)
|
||||
return fmt.Errorf("failed to get snapshots: %s", err)
|
||||
}
|
||||
|
||||
slog.Debug("ES result", "indicies", sres)
|
||||
@@ -97,7 +97,9 @@ func SnapshotList(conf *cfg.Config) error {
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -135,7 +137,9 @@ func SnapshotShow(conf *cfg.Config, snapshot string) error {
|
||||
{"shards-successful", fmt.Sprintf("%d", snap.Shards.Successful)},
|
||||
}
|
||||
|
||||
table.PrintMarkdown()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -84,11 +84,11 @@ func (data *Table) PrintMarkdown() error {
|
||||
table.Header(data.headers)
|
||||
|
||||
if err := table.Bulk(data.entries); err != nil {
|
||||
return fmt.Errorf("Failed to add data to table renderer: %s", err)
|
||||
return fmt.Errorf("failed to add data to table renderer: %s", err)
|
||||
}
|
||||
|
||||
if err := table.Render(); err != nil {
|
||||
fmt.Errorf("Failed to render table: %s", err)
|
||||
return fmt.Errorf("failed to render table: %s", err)
|
||||
}
|
||||
|
||||
fmt.Println(tableString.String())
|
||||
|
||||
Reference in New Issue
Block a user