Add CI pipelines, fix linting issues (#12)

This commit is contained in:
T. von Dein
2026-05-07 15:01:18 +02:00
parent 5e82a3706b
commit 38ed9de0b4
14 changed files with 257 additions and 97 deletions

View File

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