Compare commits

...

3 Commits

6 changed files with 65 additions and 36 deletions

View File

@@ -67,10 +67,10 @@ test: clean buildlocal
testlint: test lint testlint: test lint
lint: lint-basic:
golangci-lint run --enable-only errcheck,govet,ineffassign,staticcheck,unused golangci-lint run --enable-only errcheck,govet,ineffassign,staticcheck,unused
lint-full: lint:
golangci-lint run --show-stats=false golangci-lint run --show-stats=false
testfuzzy: clean testfuzzy: clean

View File

@@ -91,6 +91,12 @@ 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 {

View File

@@ -101,7 +101,8 @@ type Config struct {
MaxDocs, MaxShardSize, MaxShardDocs int // roll over MaxDocs, MaxShardSize, MaxShardDocs int // roll over
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

View File

@@ -45,22 +45,25 @@ 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
@@ -143,7 +146,11 @@ 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))
} }
pageJsonOutput(conf, raw) if conf.HumanCat && strings.HasPrefix(parts[1], "/_cat") {
fmt.Println(string(raw))
} else {
pageJsonOutput(conf, raw)
}
} }
//nolint:nilerr //nolint:nilerr
@@ -216,8 +223,10 @@ func CallAPI(conf *cfg.Config, verb, path, data string) ([]byte, error) {
return nil, err return nil, err
} }
req.Header.Add("Content-Type", "application/json") if !conf.HumanCat && strings.HasPrefix(path, "/_cat") {
req.Header.Add("Accept", "application/json") req.Header.Add("Content-Type", "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 {

View File

@@ -113,13 +113,19 @@ 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", *stat.AdaptiveSelection[id].Rank}, {"Node rank", 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},

View File

@@ -163,30 +163,37 @@ 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")
roles := make([]string, len(currentNode.Roles))
for idx, role := range currentNode.Roles {
roles[idx] = role.Name
}
table.Entries = [][]any{ table.Entries = [][]any{
{"Index", index}, {"Index", index},
{"Current state", res.CurrentState}, {"Current state", res.CurrentState},
{"Current node", currentNode.Name},
{"Current k8s node", currentNode.Attributes["k8s_node_name"]},
{"Current node address", currentNode.TransportAddress},
{"Current node id", currentNode.Id},
{"Current node weight", currentNode.WeightRanking},
{"Current node roles", roles},
{"Can rebalance cluster", res.CanRebalanceCluster.Name}, {"Can rebalance cluster", res.CanRebalanceCluster.Name},
{"Can rebalance to another node", res.CanRebalanceToOtherNode.Name}, {"Can rebalance to another node", res.CanRebalanceToOtherNode.Name},
{"Can remain on current node", res.CanRemainOnCurrentNode.Name}, {"Can remain on current node", res.CanRemainOnCurrentNode.Name},
} }
if res.CurrentNode != nil {
currentNode := res.CurrentNode
roles := make([]string, len(currentNode.Roles))
for idx, role := range currentNode.Roles {
roles[idx] = role.Name
}
table.Entries = append(table.Entries, [][]any{
{"Current node", currentNode.Name},
{"Current k8s node", currentNode.Attributes["k8s_node_name"]},
{"Current node address", currentNode.TransportAddress},
{"Current node id", currentNode.Id},
{"Current node weight", currentNode.WeightRanking},
{"Current node roles", roles},
}...)
} else {
table.AddRow("Current node", "not currently assigned to any node")
}
if res.CurrentState == "unassigned" { if res.CurrentState == "unassigned" {
table.AddRow("Unassignment reason", res.UnassignedInfo.Reason.String()+" at "+res.UnassignedInfo.At.(string)) table.AddRow("Unassignment reason", res.UnassignedInfo.Reason.String()+" at "+res.UnassignedInfo.At.(string))
} }