From 6aa0f3e0da58138058c39fd39d285d6d5161e902 Mon Sep 17 00:00:00 2001 From: hoenn Date: Fri, 14 Oct 2022 11:22:37 -0400 Subject: [PATCH 1/6] Add get index mappings --- pkg/cli/mappings.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pkg/cli/mappings.go diff --git a/pkg/cli/mappings.go b/pkg/cli/mappings.go new file mode 100644 index 0000000..7008857 --- /dev/null +++ b/pkg/cli/mappings.go @@ -0,0 +1,38 @@ +package cli + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var indexToGetMappings string + +func init() { + cmdIndexMappings.Flags().StringVarP(&indexToGetMappings, "index", "i", "", "Elasticsearch index to retrieve mappings from (required)") + err := cmdIndexMappings.MarkFlagRequired("index") + if err != nil { + fmt.Printf("Error binding name configuration flag: %s \n", err) + os.Exit(1) + } + rootCmd.AddCommand(cmdIndexMappings) +} + +var cmdIndexMappings = &cobra.Command{ + Use: "mappings", + Short: "Display the mappings of the specified index.", + Long: `Show the mappings of the specified index within the cluster.`, + Run: func(cmd *cobra.Command, args []string) { + + v := getClient() + + mappings, err := v.GetPrettyIndexMappings(indexToGetMappings) + + if err != nil { + fmt.Printf("Error getting mappings: %s\n", err) + os.Exit(1) + } + fmt.Println(mappings) + }, +} From 2111da6a37b4df65bfdad84eb1e7cc1beeb1112c Mon Sep 17 00:00:00 2001 From: hoenn Date: Fri, 14 Oct 2022 11:46:32 -0400 Subject: [PATCH 2/6] Add recovery cmd to cli --- pkg/cli/recovery.go | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 pkg/cli/recovery.go diff --git a/pkg/cli/recovery.go b/pkg/cli/recovery.go new file mode 100644 index 0000000..ae5403b --- /dev/null +++ b/pkg/cli/recovery.go @@ -0,0 +1,51 @@ +package cli + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var nodesToCheckRecovery []string + +func init() { + cmdShardRecovery.Flags().StringArrayVarP(&nodesToCheckRecovery, "nodes", "n", []string{}, "Elasticsearch nodes to view shard recovery progress (optional, omitted will include all nodes)") + rootCmd.AddCommand(cmdShardRecovery) +} + +var cmdShardRecovery = &cobra.Command{ + Use: "recovery", + Short: "Display the recovery progress of shards.", + Long: `Show the details regarding shard recovery operations across a set of cluster nodes.`, + Run: func(cmd *cobra.Command, args []string) { + v := getClient() + + recovery, err := v.GetShardRecovery(nodesToCheckRecovery, true) + + if err != nil { + fmt.Printf("Error getting shard recovery details: %s\n", err) + os.Exit(1) + } + header := []string{"Index", "Shard", "Time", "Source", "Target", "Bytes %", "Est Remaining"} + var rows [][]string + + for _, shard := range recovery { + remaining, _ := shard.TimeRemaining() + row := []string{ + shard.Index, + shard.Shard, + shard.Time, + shard.SourceNode, + shard.TargetNode, + shard.BytesPercent, + remaining.String(), + } + rows = append(rows, row) + } + + table := renderTable(rows, header) + + fmt.Println(table) + }, +} From a586335329d68e5976ccea8678a618082a99541a Mon Sep 17 00:00:00 2001 From: hoenn Date: Fri, 14 Oct 2022 11:46:39 -0400 Subject: [PATCH 3/6] Add hotthreads cmd to cli --- pkg/cli/hotthreads.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pkg/cli/hotthreads.go diff --git a/pkg/cli/hotthreads.go b/pkg/cli/hotthreads.go new file mode 100644 index 0000000..894b244 --- /dev/null +++ b/pkg/cli/hotthreads.go @@ -0,0 +1,42 @@ +package cli + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var nodesToGetHotThreads []string + +func init() { + cmdHotThreads.Flags().StringArrayVarP(&nodesToGetHotThreads, "nodes", "n", []string{}, "Elasticsearch nodes to get hot threads for. (optional, omitted means all nodes)") + rootCmd.AddCommand(cmdHotThreads) +} + +var cmdHotThreads = &cobra.Command{ + Use: "hotthreads", + Short: "Display the current hot threads by node in the cluster.", + Long: `Show the current hot threads across a set of nodes within the cluster.`, + Run: func(cmd *cobra.Command, args []string) { + + v := getClient() + + if len(nodesToGetHotThreads) == 0 { + threads, err := v.GetHotThreads() + if err != nil { + fmt.Printf("Error getting hot threads: %s\n", err) + os.Exit(1) + } + fmt.Println(threads) + return + } + + threads, err := v.GetNodesHotThreads(nodesToGetHotThreads) + if err != nil { + fmt.Printf("Error getting mappings: %s\n", err) + os.Exit(1) + } + fmt.Println(threads) + }, +} From dca3b7b5691d5557e33400a24a76e57e5140ce7d Mon Sep 17 00:00:00 2001 From: hoenn Date: Fri, 14 Oct 2022 11:50:16 -0400 Subject: [PATCH 4/6] Standardize optional help text in new commands --- pkg/cli/hotthreads.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/hotthreads.go b/pkg/cli/hotthreads.go index 894b244..bfcba1c 100644 --- a/pkg/cli/hotthreads.go +++ b/pkg/cli/hotthreads.go @@ -10,7 +10,7 @@ import ( var nodesToGetHotThreads []string func init() { - cmdHotThreads.Flags().StringArrayVarP(&nodesToGetHotThreads, "nodes", "n", []string{}, "Elasticsearch nodes to get hot threads for. (optional, omitted means all nodes)") + cmdHotThreads.Flags().StringArrayVarP(&nodesToGetHotThreads, "nodes", "n", []string{}, "Elasticsearch nodes to get hot threads for. (optional, omitted will include all nodes)") rootCmd.AddCommand(cmdHotThreads) } From 4058dbb332d09eef3a641f8a5dcb6c780558a9e3 Mon Sep 17 00:00:00 2001 From: hoenn Date: Fri, 14 Oct 2022 11:52:00 -0400 Subject: [PATCH 5/6] Remove unnecessary recovery cmd, shards has a subcmd for this --- pkg/cli/recovery.go | 51 --------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 pkg/cli/recovery.go diff --git a/pkg/cli/recovery.go b/pkg/cli/recovery.go deleted file mode 100644 index ae5403b..0000000 --- a/pkg/cli/recovery.go +++ /dev/null @@ -1,51 +0,0 @@ -package cli - -import ( - "fmt" - "os" - - "github.com/spf13/cobra" -) - -var nodesToCheckRecovery []string - -func init() { - cmdShardRecovery.Flags().StringArrayVarP(&nodesToCheckRecovery, "nodes", "n", []string{}, "Elasticsearch nodes to view shard recovery progress (optional, omitted will include all nodes)") - rootCmd.AddCommand(cmdShardRecovery) -} - -var cmdShardRecovery = &cobra.Command{ - Use: "recovery", - Short: "Display the recovery progress of shards.", - Long: `Show the details regarding shard recovery operations across a set of cluster nodes.`, - Run: func(cmd *cobra.Command, args []string) { - v := getClient() - - recovery, err := v.GetShardRecovery(nodesToCheckRecovery, true) - - if err != nil { - fmt.Printf("Error getting shard recovery details: %s\n", err) - os.Exit(1) - } - header := []string{"Index", "Shard", "Time", "Source", "Target", "Bytes %", "Est Remaining"} - var rows [][]string - - for _, shard := range recovery { - remaining, _ := shard.TimeRemaining() - row := []string{ - shard.Index, - shard.Shard, - shard.Time, - shard.SourceNode, - shard.TargetNode, - shard.BytesPercent, - remaining.String(), - } - rows = append(rows, row) - } - - table := renderTable(rows, header) - - fmt.Println(table) - }, -} From cdef137c68722b0635a438da4cc7291c287adacf Mon Sep 17 00:00:00 2001 From: hoenn Date: Mon, 17 Oct 2022 14:14:03 -0400 Subject: [PATCH 6/6] Update README with new usage --- README.md | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 2e5de85..7f8a1eb 100644 --- a/README.md +++ b/README.md @@ -29,26 +29,33 @@ Usage: vulcanizer [command] Available Commands: - aliases Interact with aliases of the cluster. - allocation Set shard allocation on the cluster. - analyze Analyze text given an analyzer or a field and index. - drain Drain a server or see what servers are draining. - fill Fill servers with data, removing shard allocation exclusion rules. - health Display the health of the cluster. - help Help about any command - indices Display the indices of the cluster. - nodes Display the nodes of the cluster. - repository Interact with the configured snapshot repositories. - setting Interact with cluster settings. - settings Display all the settings of the cluster. - shards Get shard data by cluster node(s). - snapshot Interact with a specific snapshot. + aliases Interact with aliases of the cluster. + allocation Set shard allocation on the cluster. + analyze Analyze text given an analyzer or a field and index. + drain Drain a server or see what servers are draining. + fill Fill servers with data, removing shard allocation exclusion rules. + health Display the health of the cluster. + heap Display the node heap stats. + help Help about any command + hotthreads Display the current hot threads by node in the cluster. + indices Display the indices of the cluster. + mappings Display the mappings of the specified index. + nodeallocations Display the nodes of the cluster and their disk usage/allocation. + nodes Display the nodes of the cluster. + repository Interact with the configured snapshot repositories. + setting Interact with cluster settings. + settings Display all the settings of the cluster. + shards Get shard data by cluster node(s). + snapshot Interact with a specific snapshot. Flags: + --cacert string Path to the certificate to check the cluster certificates against + --cert string Path to the certificate to use for client certificate authentication -c, --cluster string Cluster to connect to defined in config file -f, --configFile string Configuration file to read in (default to "~/.vulcanizer.yaml") -h, --help help for vulcanizer --host string Host to connect to (default "localhost") + --key string Path to the key to use for client certificate authentication --password string Password to use during authentication --path string Path to prepend to queries, in case Elasticsearch is behind a reverse proxy -p, --port int Port to connect to (default 9200)