From d22352da12820f5d77d226b9843afda59f3cae5c Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Mon, 11 May 2026 10:22:17 +0200 Subject: [PATCH] fix settings output, recursively determine the json path of settings --- pkg/es/cluster.go | 94 ------------------------------------------ pkg/es/cluster_util.go | 4 ++ 2 files changed, 4 insertions(+), 94 deletions(-) diff --git a/pkg/es/cluster.go b/pkg/es/cluster.go index 1f70269..86c19f2 100644 --- a/pkg/es/cluster.go +++ b/pkg/es/cluster.go @@ -18,7 +18,6 @@ package es import ( "context" - "encoding/json" "errors" "fmt" "log/slog" @@ -29,11 +28,6 @@ import ( "github.com/elastic/go-elasticsearch/v9/typedapi/cluster/health" "github.com/elastic/go-elasticsearch/v9/typedapi/core/info" "github.com/elastic/go-elasticsearch/v9/typedapi/types" - "github.com/urfave/cli/v3" -) - -const ( - DefaultExclude = `(part|monitoring|.internal|metrics-endpoint)` ) const ( @@ -204,91 +198,3 @@ func ClusterStatus(conf *cfg.Config) error { return nil } - -func ClusterSettingsList(conf *cfg.Config) error { - res, err := conf.DefaultCluster.ES.Cluster.GetSettings(). - Header("content-type", "application/json"). - Header("accept", "application/json"). - Do(context.Background()) - if err != nil { - return fmt.Errorf("failed to get cluster settings: %s", err) - } - - table := NewTable(2, 0) - table.Addheaders("setting", "value") - entries := [][]string{} - - settingshash := res.Persistent // == map[string]json.RawMessage - - switch { - case conf.Transient: - settingshash = res.Transient - case conf.Default: - settingshash = res.Defaults - } - - for topic, val := range settingshash { - data := map[string]map[string]any{} - - err := json.Unmarshal(val, &data) - - if err != nil { - return fmt.Errorf("failed to unmarshall setting for topic %s: %s", topic, err) - } - - for key, settings := range data { - for setting, value := range settings { - entries = append(entries, []string{ - fmt.Sprintf("%s.%s.%s", topic, key, setting), - fmt.Sprintf("%v", value), - }) - - } - } - } - - table.entries = entries - table.Sort() - - if err := table.PrintMarkdown(); err != nil { - return err - } - - return nil -} - -func ClusterSettingsSet(conf *cfg.Config, args cli.Args) error { - put := conf.Clusters[conf.CurrentCluster].ES.Cluster.PutSettings() - - for _, arg := range args.Slice() { - setting, value := splitArg(arg) - - switch { - case conf.Transient: - message, err := json.Marshal(value) - if err != nil { - return fmt.Errorf("failed to marshall transient value <%v> to valid JSON: %s", value, err) - } - put.AddTransient(setting, message) - case conf.Persistent: - fallthrough - default: - message, err := json.Marshal(value) - if err != nil { - return fmt.Errorf("failed to marshall persistent value <%v> to valid JSON: %s", value, err) - } - put.AddPersistent(setting, message) - } - } - - _, err := put. - Header("content-type", "application/json"). - Header("accept", "application/json"). - Do(context.Background()) - - if err != nil { - return fmt.Errorf("failed to set settings: %s", err) - } - - return nil -} diff --git a/pkg/es/cluster_util.go b/pkg/es/cluster_util.go index 1572187..1feca49 100644 --- a/pkg/es/cluster_util.go +++ b/pkg/es/cluster_util.go @@ -30,6 +30,10 @@ import ( "github.com/elastic/go-elasticsearch/v9/typedapi/types" ) +const ( + DefaultExclude = `(part|monitoring|.internal|metrics-endpoint)` +) + func checkClusterFollower(conf *cfg.Config, leader string) bool { stats, err := conf.Clusters[leader].ES.Ccr.Stats(). Header("content-type", "application/json").