mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 09:54:18 +02:00
feature add ilm-explain (#52)
This commit is contained in:
18
cmd/ilm.go
18
cmd/ilm.go
@@ -38,6 +38,7 @@ func Ilm(conf *cfg.Config) *cli.Command {
|
|||||||
IlmShow(conf),
|
IlmShow(conf),
|
||||||
IlmCreate(conf),
|
IlmCreate(conf),
|
||||||
IlmForecast(conf),
|
IlmForecast(conf),
|
||||||
|
IlmExplain(conf),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +55,23 @@ func IlmRetry(conf *cfg.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IlmExplain(conf *cfg.Config) *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "explain",
|
||||||
|
Usage: "explain ilm condition of an index",
|
||||||
|
UsageText: "explain <index>",
|
||||||
|
|
||||||
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
index := cmd.Args().Get(0)
|
||||||
|
if index == "" {
|
||||||
|
return errors.New("no index specified")
|
||||||
|
}
|
||||||
|
|
||||||
|
return es.IlmExplain(conf, index)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func IlmStatus(conf *cfg.Config) *cli.Command {
|
func IlmStatus(conf *cfg.Config) *cli.Command {
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
Name: "status",
|
Name: "status",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package es
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -26,6 +27,7 @@ import (
|
|||||||
"codeberg.org/scip/esctl/pkg/cfg"
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
"codeberg.org/scip/esctl/pkg/printer"
|
"codeberg.org/scip/esctl/pkg/printer"
|
||||||
"github.com/alecthomas/repr"
|
"github.com/alecthomas/repr"
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/elastic/go-elasticsearch/v9/typedapi/esdsl"
|
"github.com/elastic/go-elasticsearch/v9/typedapi/esdsl"
|
||||||
"github.com/elastic/go-elasticsearch/v9/typedapi/ilm/putlifecycle"
|
"github.com/elastic/go-elasticsearch/v9/typedapi/ilm/putlifecycle"
|
||||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types"
|
"github.com/elastic/go-elasticsearch/v9/typedapi/types"
|
||||||
@@ -183,18 +185,38 @@ func IlmExplain(conf *cfg.Config, index string) error {
|
|||||||
table := printer.NewTable(conf, 2, 0)
|
table := printer.NewTable(conf, 2, 0)
|
||||||
table.Addheaders("ilm status field", "value")
|
table.Addheaders("ilm status field", "value")
|
||||||
|
|
||||||
|
info := ""
|
||||||
|
err = json.Unmarshal(ilm.StepInfo["reason"], &info)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to unmarshal step info: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
table.Entries = [][]string{
|
table.Entries = [][]string{
|
||||||
{"index", ilm.Index},
|
{"index", ilm.Index},
|
||||||
{"ilm policy", *ilm.Policy},
|
{"ilm policy", *ilm.Policy},
|
||||||
{"action", *ilm.Action},
|
{"action", *ilm.Action},
|
||||||
{"step", *ilm.Step},
|
|
||||||
{"age", fmt.Sprintf("%s", ilm.Age)},
|
{"age", fmt.Sprintf("%s", ilm.Age)},
|
||||||
{"managed", fmt.Sprintf("%t", ilm.Managed)},
|
{"managed", fmt.Sprintf("%t", ilm.Managed)},
|
||||||
{"phase", *ilm.Phase},
|
{"phase", *ilm.Phase},
|
||||||
{"phase execution", ilmPhaseString(ilm.PhaseExecution.PhaseDefinition, false)},
|
{"phase execution", ilmPhaseString(ilm.PhaseExecution.PhaseDefinition, false)},
|
||||||
|
{"step", *ilm.Step},
|
||||||
|
{"failed step", *ilm.FailedStep},
|
||||||
|
{"failed step retry count", fmt.Sprintf("%d", ilm.FailedStepRetryCount)},
|
||||||
}
|
}
|
||||||
|
|
||||||
return table.Print()
|
if err := table.Print(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if info != "" {
|
||||||
|
var bold = lipgloss.NewStyle().Bold(true)
|
||||||
|
|
||||||
|
fmt.Printf("\n%s:\n%s\n",
|
||||||
|
bold.Render("Step Reason"),
|
||||||
|
info)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IlmCreate(conf *cfg.Config, policyname string) error {
|
func IlmCreate(conf *cfg.Config, policyname string) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user