mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 16:34:18 +02:00
Compare commits
2 Commits
feature/ap
...
fix/es8-he
| Author | SHA1 | Date | |
|---|---|---|---|
| 734dea4dff | |||
| 5d7050018f |
@@ -16,6 +16,7 @@ builds:
|
|||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
- darwin
|
- darwin
|
||||||
|
tool: "go1.26.4"
|
||||||
|
|
||||||
changelog:
|
changelog:
|
||||||
sort: asc
|
sort: asc
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -67,10 +67,10 @@ test: clean buildlocal
|
|||||||
|
|
||||||
testlint: test lint
|
testlint: test lint
|
||||||
|
|
||||||
lint-basic:
|
lint:
|
||||||
golangci-lint run --enable-only errcheck,govet,ineffassign,staticcheck,unused
|
golangci-lint run --enable-only errcheck,govet,ineffassign,staticcheck,unused
|
||||||
|
|
||||||
lint:
|
lint-full:
|
||||||
golangci-lint run --show-stats=false
|
golangci-lint run --show-stats=false
|
||||||
|
|
||||||
testfuzzy: clean
|
testfuzzy: clean
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func ApiShow(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Capi)
|
complete(cmd, Capi)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,12 +91,6 @@ func ApiRepl(conf *cfg.Config) *cli.Command {
|
|||||||
Aliases: []string{"p"},
|
Aliases: []string{"p"},
|
||||||
Sources: cli.EnvVars("PAGER", "ES_JSON_PAGER"),
|
Sources: cli.EnvVars("PAGER", "ES_JSON_PAGER"),
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "human-readable-cat",
|
|
||||||
Usage: "enable human readable /_cat output",
|
|
||||||
Destination: &conf.HumanCat,
|
|
||||||
Aliases: []string{"H"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func CcrStatus(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Ccluster)
|
complete(cmd, Ccluster)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -115,7 +115,7 @@ func CcrRemoteInfo(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "info [options] [<index>]",
|
UsageText: "info [options] [<index>]",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func CcrFollowerRenew(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -82,7 +82,7 @@ func CcrFollowerResume(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "resume [options] <index>",
|
UsageText: "resume [options] <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -104,7 +104,7 @@ func CcrFollowerPause(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "pause [options] <index>",
|
UsageText: "pause [options] <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -126,7 +126,7 @@ func CcrFollowerUnfollow(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "unfollow [options] <index>",
|
UsageText: "unfollow [options] <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -158,7 +158,7 @@ func CcrFollowerAdd(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -181,7 +181,7 @@ func CcrFollowerDelete(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "delete <index>",
|
UsageText: "delete <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -205,7 +205,7 @@ func CcrFollowerShow(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "show <index>",
|
UsageText: "show <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func ClusterSwitch(conf *cfg.Config) *cli.Command {
|
|||||||
Aliases: []string{"ctx"},
|
Aliases: []string{"ctx"},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Ccluster)
|
complete(cmd, Ccluster)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func ClusterRerouteMove(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "move [options] <index>",
|
UsageText: "move [options] <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@@ -95,7 +95,7 @@ func ClusterRerouteAllocateReplica(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "allocate-replica [options] <index>",
|
UsageText: "allocate-replica [options] <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@@ -133,7 +133,7 @@ func ClusterRerouteCancel(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "cancel [options] <index>",
|
UsageText: "cancel [options] <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@@ -185,7 +185,7 @@ func ClusterRerouteAllocatePrimary(conf *cfg.Config, stale bool) *cli.Command {
|
|||||||
UsageText: name + " [options] <index>",
|
UsageText: name + " [options] <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func ClusterSettingsSet(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cclustersettings)
|
complete(cmd, Cclustersettings)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|||||||
@@ -36,11 +36,18 @@ const (
|
|||||||
Cclustersettings
|
Cclustersettings
|
||||||
)
|
)
|
||||||
|
|
||||||
func complete(conf *cfg.Config, cmd *cli.Command, what int) {
|
func complete(cmd *cli.Command, what int) {
|
||||||
if cmd.NArg() > 0 {
|
if cmd.NArg() > 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: config should load from root.Before(), see https://github.com/urfave/cli/issues/2348
|
||||||
|
// workaround: load it directly here
|
||||||
|
conf := cfg.NewConfig()
|
||||||
|
if err := conf.Init(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
list []string
|
list []string
|
||||||
err error
|
err error
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func DatastreamShow(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cdatastream)
|
complete(cmd, Cdatastream)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ func DatastreamCreate(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cdatastream)
|
complete(cmd, Cdatastream)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ func DatastreamDelete(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cdatastream)
|
complete(cmd, Cdatastream)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ func DatastreamRollover(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "rollover <data stream>",
|
UsageText: "rollover <data stream>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@@ -205,7 +205,7 @@ func DatastreamIlm(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "ds ilm <name>",
|
UsageText: "ds ilm <name>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cdatastream)
|
complete(cmd, Cdatastream)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ func IlmShow(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cilm)
|
complete(cmd, Cilm)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
cmd/index.go
36
cmd/index.go
@@ -41,7 +41,6 @@ func Index(conf *cfg.Config) *cli.Command {
|
|||||||
IndexClose(conf),
|
IndexClose(conf),
|
||||||
IndexFields(conf),
|
IndexFields(conf),
|
||||||
IndexIlm(conf),
|
IndexIlm(conf),
|
||||||
IndexDu(conf),
|
|
||||||
|
|
||||||
// sub commands
|
// sub commands
|
||||||
IndexAlias(conf),
|
IndexAlias(conf),
|
||||||
@@ -76,10 +75,10 @@ func IndexList(conf *cfg.Config) *cli.Command {
|
|||||||
Aliases: []string{"H"},
|
Aliases: []string{"H"},
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "failed",
|
Name: "reds",
|
||||||
Usage: "include only red failed indicies",
|
Usage: "include only red failed indicies",
|
||||||
Destination: &conf.Failed,
|
Destination: &conf.Failed,
|
||||||
Aliases: []string{"f"},
|
Aliases: []string{"r"},
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "filter",
|
Name: "filter",
|
||||||
@@ -111,7 +110,7 @@ func IndexShow(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +180,7 @@ func IndexDelete(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "delete <index>",
|
UsageText: "delete <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -202,7 +201,7 @@ func IndexClose(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "close <index>",
|
UsageText: "close <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -244,7 +243,7 @@ func IndexFields(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -265,7 +264,7 @@ func IndexIlm(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "index ilm <index>",
|
UsageText: "index ilm <index>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -278,24 +277,3 @@ func IndexIlm(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func IndexDu(conf *cfg.Config) *cli.Command {
|
|
||||||
return &cli.Command{
|
|
||||||
Name: "du",
|
|
||||||
Usage: "show index disk usage",
|
|
||||||
UsageText: "index du <index>",
|
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
|
||||||
complete(conf, cmd, Cindex)
|
|
||||||
},
|
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
||||||
index := cmd.Args().Get(0)
|
|
||||||
if index == "" {
|
|
||||||
return errors.New("no index specified")
|
|
||||||
}
|
|
||||||
|
|
||||||
return es.IndexDiskusage(conf, index)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func IndexAliasCreate(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "create <index> <alias>",
|
UsageText: "create <index> <alias>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -76,7 +76,7 @@ func IndexAliasDelete(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "delete <index> <alias>",
|
UsageText: "delete <index> <alias>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -100,7 +100,7 @@ func IndexAliasRollover(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "rollover <alias>",
|
UsageText: "rollover <alias>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
|
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func IndexTemplateShow(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ func IndexTemplateDelete(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindex)
|
complete(cmd, Cindex)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func NodeShow(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "show [options] <node>",
|
UsageText: "show [options] <node>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cnode)
|
complete(cmd, Cnode)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
@@ -90,7 +90,7 @@ func NodeClients(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cnode)
|
complete(cmd, Cnode)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func RoleShow(conf *cfg.Config) *cli.Command {
|
|||||||
UsageText: "show [options] <role>",
|
UsageText: "show [options] <role>",
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Crole)
|
complete(cmd, Crole)
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|||||||
@@ -82,9 +82,8 @@ type Config struct {
|
|||||||
SortBy string // sort: -k
|
SortBy string // sort: -k
|
||||||
Ascending bool // sort: -a
|
Ascending bool // sort: -a
|
||||||
|
|
||||||
All bool // doc + node ls: -a
|
|
||||||
Exclude string // cluster compare: -e (regexp)
|
Exclude string // cluster compare: -e (regexp)
|
||||||
Verbose bool // cluster status: -v
|
All, Verbose bool // cluster status: -a -v
|
||||||
Persistent, Transient, Default bool // cluster settings set: -p -t -D
|
Persistent, Transient, Default bool // cluster settings set: -p -t -D
|
||||||
|
|
||||||
Force bool // ccr follower renew: -f
|
Force bool // ccr follower renew: -f
|
||||||
@@ -102,7 +101,6 @@ type Config struct {
|
|||||||
DryRun bool // rollover: -n
|
DryRun bool // rollover: -n
|
||||||
|
|
||||||
Tag string // api ls: -t
|
Tag string // api ls: -t
|
||||||
HumanCat bool // api repl: -H
|
|
||||||
|
|
||||||
Ilm Ilm // ilm create
|
Ilm Ilm // ilm create
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ func (t *DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
contentline = buf.String()
|
contentline = buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
req = fixRequestHeaders(req)
|
if req.Header.Get("Accept") != "" {
|
||||||
|
req.Header.Del("Accept")
|
||||||
|
req.Header.Add("Accept", "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
slog.Info("req", "host", req.URL.Host, "uri", req.URL.Path,
|
slog.Info("req", "host", req.URL.Host, "uri", req.URL.Path,
|
||||||
"body", content, "bodyline", contentline,
|
"body", content, "bodyline", contentline,
|
||||||
@@ -63,31 +66,20 @@ func (t *DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
return t.Transport.RoundTrip(req)
|
return t.Transport.RoundTrip(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompatibilityTransport struct {
|
|
||||||
Transport http.RoundTripper
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *CompatibilityTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
||||||
req = fixRequestHeaders(req)
|
|
||||||
|
|
||||||
return t.Transport.RoundTrip(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fixes https://codeberg.org/scip/esctl/issues/79:
|
// Fixes https://codeberg.org/scip/esctl/issues/79:
|
||||||
// the API client has this Accept header hardcoded everywhere:
|
// the API client has this Accept header hardcoded everywhere:
|
||||||
// req.Header.Set("Accept", "application/vnd.elasticsearch+json;compatible-with=9")
|
// req.Header.Set("Accept", "application/vnd.elasticsearch+json;compatible-with=9")
|
||||||
// While this works pretty well with ES9, it doesn't with ES8. So, we replace
|
// While this works pretty well with ES9, it doesn't with ES8. So, we replace
|
||||||
// this header with a new one without the compatibility part.
|
// this header with a new one without the compatibility part.
|
||||||
func fixRequestHeaders(req *http.Request) *http.Request {
|
type CompatibilityTransport struct {
|
||||||
|
Transport http.RoundTripper
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *CompatibilityTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
if req.Header.Get("Accept") != "" {
|
if req.Header.Get("Accept") != "" {
|
||||||
req.Header.Del("Accept")
|
req.Header.Del("Accept")
|
||||||
req.Header.Add("Accept", "application/json")
|
req.Header.Add("Accept", "application/json")
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Header.Get("Content-Type") != "" {
|
return t.Transport.RoundTrip(req)
|
||||||
req.Header.Del("Content-Type")
|
|
||||||
req.Header.Add("Content-Type", "application/json")
|
|
||||||
}
|
|
||||||
|
|
||||||
return req
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,25 +45,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
intro = `# Input format: verb path [data]"
|
intro = `Input format: verb path [data]"
|
||||||
#
|
|
||||||
# Example:
|
Example:
|
||||||
#
|
|
||||||
# post /yourindex/_ccr/pause_follow
|
post /yourindex/_ccr/pause_follow
|
||||||
# put /yourindex/_settings {"number_of_replicas": 1}
|
put /yourindex/_settings {"number_of_replicas": 1}
|
||||||
#
|
|
||||||
# You can also put multiline JSON after the path like:
|
You can also put multiline JSON after the path like:
|
||||||
#
|
|
||||||
# put /yourindex/_settings
|
put /yourindex/_settings
|
||||||
# {
|
{
|
||||||
# "number_of_replicas": 1
|
"number_of_replicas": 1
|
||||||
# }
|
}
|
||||||
#
|
|
||||||
# If you do NOT supply a JSON in the first line, you need to hit ENTER
|
If you do NOT supply a JSON in the first line, you need to hit ENTER
|
||||||
# twice to complete.
|
twice to complete.`
|
||||||
#
|
|
||||||
# Supply the flag --human-readable-cat, -H to view /_cat API calls in
|
|
||||||
# human readable form.`
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// holds an API operation via go-openapi/spec
|
// holds an API operation via go-openapi/spec
|
||||||
@@ -146,12 +143,8 @@ func ApiRepl(conf *cfg.Config) error {
|
|||||||
fmt.Printf("failed to call API: %s\n", esErrorString(err))
|
fmt.Printf("failed to call API: %s\n", esErrorString(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.HumanCat && strings.HasPrefix(parts[1], "/_cat") {
|
|
||||||
fmt.Println(string(raw))
|
|
||||||
} else {
|
|
||||||
pageJsonOutput(conf, raw)
|
pageJsonOutput(conf, raw)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//nolint:nilerr
|
//nolint:nilerr
|
||||||
return nil
|
return nil
|
||||||
@@ -223,10 +216,8 @@ func CallAPI(conf *cfg.Config, verb, path, data string) ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !conf.HumanCat && strings.HasPrefix(path, "/_cat") {
|
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
req.Header.Add("Accept", "application/json")
|
req.Header.Add("Accept", "application/json")
|
||||||
}
|
|
||||||
|
|
||||||
// make sure we have got all we need
|
// make sure we have got all we need
|
||||||
if err := conf.DefaultCluster.CheckAuth(); err != nil {
|
if err := conf.DefaultCluster.CheckAuth(); err != nil {
|
||||||
|
|||||||
@@ -174,16 +174,11 @@ func ClusterStatus(conf *cfg.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// look for red indices, if any
|
// look for red indices, if any
|
||||||
failedIndices := 0
|
redindices := 0
|
||||||
greenIndices := 0
|
|
||||||
|
|
||||||
for _, index := range *res.indices {
|
for _, index := range *res.indices {
|
||||||
switch {
|
if *index.Health == "red" {
|
||||||
case *index.Health != "green":
|
redindices++
|
||||||
failedIndices++
|
|
||||||
case !strings.HasPrefix(*index.Index, "."):
|
|
||||||
// don't count internal indices
|
|
||||||
greenIndices++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,8 +205,7 @@ func ClusterStatus(conf *cfg.Config) error {
|
|||||||
{"Unassigned Primary Shards", res.health.UnassignedPrimaryShards},
|
{"Unassigned Primary Shards", res.health.UnassignedPrimaryShards},
|
||||||
{"Pending Tasks", res.health.NumberOfPendingTasks},
|
{"Pending Tasks", res.health.NumberOfPendingTasks},
|
||||||
{"Nodes", res.health.NumberOfNodes},
|
{"Nodes", res.health.NumberOfNodes},
|
||||||
{"Green Indices", greenIndices},
|
{"Red Indices", redindices},
|
||||||
{"Failed Indices", failedIndices},
|
|
||||||
{"Long Running Tasks", longtasks},
|
{"Long Running Tasks", longtasks},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,10 +233,6 @@ func ClusterStatus(conf *cfg.Config) error {
|
|||||||
for resource, items := range diag.AffectedResources {
|
for resource, items := range diag.AffectedResources {
|
||||||
table.Entries = append(table.Entries, []any{" -> affected " + resource, strings.Join(items, ",")})
|
table.Entries = append(table.Entries, []any{" -> affected " + resource, strings.Join(items, ",")})
|
||||||
}
|
}
|
||||||
|
|
||||||
if diag.Action != "" {
|
|
||||||
table.AddRow(" -> suggested action to fix", diag.Action)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ package es
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -30,7 +28,6 @@ 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/charmbracelet/lipgloss"
|
|
||||||
"github.com/elastic/go-elasticsearch/v9/typedapi/cat/indices"
|
"github.com/elastic/go-elasticsearch/v9/typedapi/cat/indices"
|
||||||
"github.com/elastic/go-elasticsearch/v9/typedapi/esdsl"
|
"github.com/elastic/go-elasticsearch/v9/typedapi/esdsl"
|
||||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/healthstatus"
|
"github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/healthstatus"
|
||||||
@@ -309,79 +306,3 @@ func IndexFields(conf *cfg.Config, index string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Diskusage struct {
|
|
||||||
Total int64 `json:"total_in_bytes"`
|
|
||||||
Points int64 `json:"points_in_bytes"`
|
|
||||||
Norms int64 `json:"norms_in_bytes"`
|
|
||||||
TermVectors int64 `json:"term_vectors_in_bytes"`
|
|
||||||
KnnVectors int64 `json:"knn_vectors_in_bytes"`
|
|
||||||
BloomFilter int64 `json:"bloom_filter_in_bytes"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IndexDiskUsage struct {
|
|
||||||
AllFields Diskusage `json:"all_fields"`
|
|
||||||
Fields map[string]Diskusage `json:"fields"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResIndexDiskUsage map[string]IndexDiskUsage
|
|
||||||
|
|
||||||
func IndexDiskusage(conf *cfg.Config, index string) error {
|
|
||||||
var bold = lipgloss.NewStyle().Bold(true)
|
|
||||||
|
|
||||||
res, err := conf.DefaultCluster.ES().Indices.DiskUsage(index).
|
|
||||||
RunExpensiveTasks(true).
|
|
||||||
Do(context.Background())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to retrieve index disk usage: %w", esErrorString(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
duRes := ResIndexDiskUsage{}
|
|
||||||
if err := json.Unmarshal(res, &duRes); err != nil {
|
|
||||||
return fmt.Errorf("failed to unmarshal disk usage response: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
diskusage, exists := duRes[index]
|
|
||||||
if !exists {
|
|
||||||
return errors.New("no disk usage reported for index")
|
|
||||||
}
|
|
||||||
|
|
||||||
table := printer.NewTableEmpty(conf).
|
|
||||||
WithHeaders("field", "bloom filter", "norms", "points", "term vectors", "knn vectors", "total")
|
|
||||||
|
|
||||||
for name, field := range diskusage.Fields {
|
|
||||||
if strings.HasPrefix(name, "_") || strings.HasSuffix(name, ".keyword") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
table.AddRow(
|
|
||||||
name,
|
|
||||||
printer.Bytes(field.BloomFilter),
|
|
||||||
printer.Bytes(field.Norms),
|
|
||||||
printer.Bytes(field.Points),
|
|
||||||
printer.Bytes(field.TermVectors),
|
|
||||||
printer.Bytes(field.KnnVectors),
|
|
||||||
printer.Bytes(field.Total),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
all := diskusage.AllFields
|
|
||||||
|
|
||||||
table.Sort()
|
|
||||||
|
|
||||||
table.AddRowLate(
|
|
||||||
bold.Render("Summary"),
|
|
||||||
printer.Bytes(all.BloomFilter),
|
|
||||||
printer.Bytes(all.Norms),
|
|
||||||
printer.Bytes(all.Points),
|
|
||||||
printer.Bytes(all.TermVectors),
|
|
||||||
printer.Bytes(all.KnnVectors),
|
|
||||||
printer.Bytes(all.Total),
|
|
||||||
)
|
|
||||||
|
|
||||||
if err := table.Print(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -26,6 +26,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/dustin/go-humanize"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NodeList(conf *cfg.Config) error {
|
func NodeList(conf *cfg.Config) error {
|
||||||
@@ -113,27 +114,18 @@ func NodeShow(conf *cfg.Config, nodename string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
k8snode := info.Attributes["k8s_node_name"]
|
k8snode := info.Attributes["k8s_node_name"]
|
||||||
rank := "none"
|
|
||||||
|
|
||||||
adsel, exists := stat.AdaptiveSelection[id]
|
|
||||||
if exists {
|
|
||||||
rank = *adsel.Rank
|
|
||||||
}
|
|
||||||
|
|
||||||
table.Entries = [][]any{
|
table.Entries = [][]any{
|
||||||
{"Id", id},
|
{"Id", id},
|
||||||
{"Name", nodename},
|
{"Name", nodename},
|
||||||
{"Kubernetes node", k8snode},
|
{"Kubernetes node", k8snode},
|
||||||
{"Ip address", info.Ip},
|
{"Ip address", info.Ip},
|
||||||
{"Node rank", rank},
|
{"Node rank", *stat.AdaptiveSelection[id].Rank},
|
||||||
{"JVM", info.Jvm.VmName + " " + info.Jvm.Version},
|
{"JVM", info.Jvm.VmName + " " + info.Jvm.Version},
|
||||||
{"JVM Started", time.UnixMilli(info.Jvm.StartTimeInMillis)},
|
{"JVM Started", time.UnixMilli(info.Jvm.StartTimeInMillis)},
|
||||||
{"OS", info.Os.PrettyName + " " + info.Os.Version},
|
{"OS", info.Os.PrettyName + " " + info.Os.Version},
|
||||||
{"Node roles", roles},
|
{"Node roles", roles},
|
||||||
{"Node version", info.Version},
|
{"Node version", info.Version},
|
||||||
// FIXME: not implemented upstream
|
|
||||||
// see: https://github.com/elastic/go-elasticsearch/issues/1526
|
|
||||||
// {"Allocated shards", stat.Allocations.XXX},
|
|
||||||
{"HTTP clients", *stat.Http.CurrentOpen},
|
{"HTTP clients", *stat.Http.CurrentOpen},
|
||||||
{"CPUs", *info.Os.AllocatedProcessors},
|
{"CPUs", *info.Os.AllocatedProcessors},
|
||||||
{"Load 15m/5m/1m", fmt.Sprintf("%.2f/%.2f/%.2f",
|
{"Load 15m/5m/1m", fmt.Sprintf("%.2f/%.2f/%.2f",
|
||||||
@@ -142,41 +134,18 @@ func NodeShow(conf *cfg.Config, nodename string) error {
|
|||||||
stat.Os.Cpu.LoadAverage["1m"],
|
stat.Os.Cpu.LoadAverage["1m"],
|
||||||
)},
|
)},
|
||||||
{"Open FD's", *stat.Process.OpenFileDescriptors},
|
{"Open FD's", *stat.Process.OpenFileDescriptors},
|
||||||
{"HTTP sesssions current/total", fmt.Sprintf("%d/%d",
|
{"Response time avg", fmt.Sprintf("%dns", *stat.AdaptiveSelection[id].AvgResponseTimeNs)},
|
||||||
*stat.Http.CurrentOpen,
|
|
||||||
*stat.Http.TotalOpened,
|
|
||||||
)},
|
|
||||||
{"Traffic rx/tx",
|
|
||||||
printer.ByteString(*stat.Transport.RxSizeInBytes) + " / " + printer.ByteString(*stat.Transport.TxSizeInBytes)},
|
|
||||||
{"Response time avg", time.Duration(*stat.AdaptiveSelection[id].AvgResponseTimeNs)},
|
|
||||||
{"Memory usage (used/avail)",
|
{"Memory usage (used/avail)",
|
||||||
printer.ByteString(*stat.Os.Mem.UsedInBytes) + " / " + printer.ByteString(*stat.Os.Mem.TotalInBytes)},
|
humanize.Bytes(uint64(*stat.Os.Mem.UsedInBytes)) + " / " + humanize.Bytes(uint64(*stat.Os.Mem.TotalInBytes))},
|
||||||
{"Search queries current/total", fmt.Sprintf("%d/%d",
|
|
||||||
stat.Indices.Search.QueryCurrent,
|
|
||||||
stat.Indices.Search.QueryTotal,
|
|
||||||
)},
|
|
||||||
{"Search efficiency", stat.Indices.Search.QueryTimeInMillis / stat.Indices.Search.QueryTotal},
|
|
||||||
{"Docs count", stat.Indices.Docs.Count},
|
|
||||||
{"Merges current/total", fmt.Sprintf("%d/%d",
|
|
||||||
stat.Indices.Merges.Current,
|
|
||||||
stat.Indices.Merges.Total,
|
|
||||||
)},
|
|
||||||
{"Merge docs count current/total", fmt.Sprintf("%d/%d",
|
|
||||||
stat.Indices.Merges.CurrentDocs,
|
|
||||||
stat.Indices.Merges.TotalDocs,
|
|
||||||
)},
|
|
||||||
{"Merge size current/total", fmt.Sprintf("%s/%s",
|
|
||||||
printer.ByteString(stat.Indices.Merges.CurrentSizeInBytes),
|
|
||||||
printer.ByteString(stat.Indices.Merges.TotalSizeInBytes),
|
|
||||||
)},
|
|
||||||
{"CircuitBreaker trip count", *stat.Breakers["fielddata"].Tripped},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(stat.Fs.Data) > 0 {
|
if len(stat.Fs.Data) > 0 {
|
||||||
fs := stat.Fs.Data[0]
|
fs := stat.Fs.Data[0]
|
||||||
table.AddRow("Storage usage (used/avail)",
|
table.Entries = append(table.Entries, [][]any{
|
||||||
printer.ByteString(*fs.AvailableInBytes)+" / "+printer.ByteString(*fs.TotalInBytes))
|
{"Storage usage (used/avail)",
|
||||||
table.AddRow("Storage mount", *fs.Mount)
|
humanize.Bytes(uint64(*fs.AvailableInBytes)) + " / " + humanize.Bytes(uint64(*fs.TotalInBytes))},
|
||||||
|
{"Storage mount", *fs.Mount},
|
||||||
|
}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := table.Print(); err != nil {
|
if err := table.Print(); err != nil {
|
||||||
|
|||||||
@@ -163,35 +163,28 @@ func ShardAllocation(conf *cfg.Config, index string) error {
|
|||||||
|
|
||||||
slog.Debug("ES result", "explain", res)
|
slog.Debug("ES result", "explain", res)
|
||||||
|
|
||||||
|
currentNode := res.CurrentNode
|
||||||
|
|
||||||
table := printer.NewTable(conf, 2, 10)
|
table := printer.NewTable(conf, 2, 10)
|
||||||
table.Addheaders("shard allocation setting", "value")
|
table.Addheaders("shard allocation setting", "value")
|
||||||
|
|
||||||
table.Entries = [][]any{
|
|
||||||
{"Index", index},
|
|
||||||
{"Current state", res.CurrentState},
|
|
||||||
{"Can rebalance cluster", res.CanRebalanceCluster.Name},
|
|
||||||
{"Can rebalance to another node", res.CanRebalanceToOtherNode.Name},
|
|
||||||
{"Can remain on current node", res.CanRemainOnCurrentNode.Name},
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.CurrentNode != nil {
|
|
||||||
currentNode := res.CurrentNode
|
|
||||||
roles := make([]string, len(currentNode.Roles))
|
roles := make([]string, len(currentNode.Roles))
|
||||||
|
|
||||||
for idx, role := range currentNode.Roles {
|
for idx, role := range currentNode.Roles {
|
||||||
roles[idx] = role.Name
|
roles[idx] = role.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
table.Entries = append(table.Entries, [][]any{
|
table.Entries = [][]any{
|
||||||
|
{"Index", index},
|
||||||
|
{"Current state", res.CurrentState},
|
||||||
{"Current node", currentNode.Name},
|
{"Current node", currentNode.Name},
|
||||||
{"Current k8s node", currentNode.Attributes["k8s_node_name"]},
|
{"Current k8s node", currentNode.Attributes["k8s_node_name"]},
|
||||||
{"Current node address", currentNode.TransportAddress},
|
{"Current node address", currentNode.TransportAddress},
|
||||||
{"Current node id", currentNode.Id},
|
{"Current node id", currentNode.Id},
|
||||||
{"Current node weight", currentNode.WeightRanking},
|
{"Current node weight", currentNode.WeightRanking},
|
||||||
{"Current node roles", roles},
|
{"Current node roles", roles},
|
||||||
}...)
|
{"Can rebalance cluster", res.CanRebalanceCluster.Name},
|
||||||
} else {
|
{"Can rebalance to another node", res.CanRebalanceToOtherNode.Name},
|
||||||
table.AddRow("Current node", "not currently assigned to any node")
|
{"Can remain on current node", res.CanRemainOnCurrentNode.Name},
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.CurrentState == "unassigned" {
|
if res.CurrentState == "unassigned" {
|
||||||
|
|||||||
@@ -22,16 +22,10 @@ type ByteSize struct {
|
|||||||
size uint64
|
size uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Bytes(size int64) ByteSize {
|
||||||
|
return ByteSize{size: uint64(size)}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *ByteSize) String() string {
|
func (b *ByteSize) String() string {
|
||||||
return humanize.Bytes(b.size)
|
return humanize.Bytes(b.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Bytes(size int64) *ByteSize {
|
|
||||||
return &ByteSize{size: uint64(size)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ByteString(size int64) string {
|
|
||||||
b := ByteSize{size: uint64(size)}
|
|
||||||
|
|
||||||
return b.String()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -38,18 +38,12 @@ func any2string(in any) string {
|
|||||||
return strconv.Itoa(val)
|
return strconv.Itoa(val)
|
||||||
case float64:
|
case float64:
|
||||||
return fmt.Sprintf("%.2f", val)
|
return fmt.Sprintf("%.2f", val)
|
||||||
case float32:
|
|
||||||
return fmt.Sprintf("%.2f", val)
|
|
||||||
case []string:
|
case []string:
|
||||||
return strings.Join(val, ",")
|
return strings.Join(val, ",")
|
||||||
case ByteSize:
|
case ByteSize:
|
||||||
return val.String()
|
return val.String()
|
||||||
case *ByteSize:
|
|
||||||
return val.String()
|
|
||||||
case time.Time:
|
case time.Time:
|
||||||
return val.Format("2006-01-02 15:04:05")
|
return val.Format("2006-01-02 15:04:05")
|
||||||
case time.Duration:
|
|
||||||
return val.String()
|
|
||||||
case []byte:
|
case []byte:
|
||||||
return string(val)
|
return string(val)
|
||||||
case nil:
|
case nil:
|
||||||
|
|||||||
@@ -206,22 +206,6 @@ func (table *Table) AddRow(fields ...any) {
|
|||||||
table.Entries = append(table.Entries, fields)
|
table.Entries = append(table.Entries, fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *Table) AddRowLate(fields ...any) {
|
|
||||||
table.AddRow(fields)
|
|
||||||
|
|
||||||
if !table.processed {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
row := make([]string, len(fields))
|
|
||||||
|
|
||||||
for idx, field := range fields {
|
|
||||||
row[idx] = any2string(field)
|
|
||||||
}
|
|
||||||
|
|
||||||
table.rows = append(table.rows, row)
|
|
||||||
}
|
|
||||||
|
|
||||||
// needed for json and yaml output
|
// needed for json and yaml output
|
||||||
func (table *Table) toMap() []map[string]any {
|
func (table *Table) toMap() []map[string]any {
|
||||||
raw := make([]map[string]any, len(table.Entries))
|
raw := make([]map[string]any, len(table.Entries))
|
||||||
|
|||||||
Reference in New Issue
Block a user