diff --git a/pkg/es/node.go b/pkg/es/node.go index 14609b8..5ece30a 100644 --- a/pkg/es/node.go +++ b/pkg/es/node.go @@ -113,13 +113,19 @@ func NodeShow(conf *cfg.Config, nodename string) error { } k8snode := info.Attributes["k8s_node_name"] + rank := "none" + + adsel, exists := stat.AdaptiveSelection[id] + if exists { + rank = *adsel.Rank + } table.Entries = [][]any{ {"Id", id}, {"Name", nodename}, {"Kubernetes node", k8snode}, {"Ip address", info.Ip}, - {"Node rank", *stat.AdaptiveSelection[id].Rank}, + {"Node rank", rank}, {"JVM", info.Jvm.VmName + " " + info.Jvm.Version}, {"JVM Started", time.UnixMilli(info.Jvm.StartTimeInMillis)}, {"OS", info.Os.PrettyName + " " + info.Os.Version}, diff --git a/pkg/es/shard.go b/pkg/es/shard.go index 8c93ab7..8052add 100644 --- a/pkg/es/shard.go +++ b/pkg/es/shard.go @@ -163,30 +163,37 @@ func ShardAllocation(conf *cfg.Config, index string) error { slog.Debug("ES result", "explain", res) - currentNode := res.CurrentNode - table := printer.NewTable(conf, 2, 10) 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{ {"Index", index}, {"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 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)) + + 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" { table.AddRow("Unassignment reason", res.UnassignedInfo.Reason.String()+" at "+res.UnassignedInfo.At.(string)) }