From c9fb5729358d19792f6adc874954d970d266a6b4 Mon Sep 17 00:00:00 2001 From: "T. von Dein" Date: Fri, 3 Jul 2026 10:25:57 +0200 Subject: [PATCH] get rid of getJsonPath, use flat_settings query flag instead (#66) --- pkg/es/cluster_settings.go | 16 ++---------- pkg/es/cluster_util.go | 42 ------------------------------- pkg/es/index_template_settings.go | 8 ++---- pkg/printer/table.go | 2 +- 4 files changed, 5 insertions(+), 63 deletions(-) diff --git a/pkg/es/cluster_settings.go b/pkg/es/cluster_settings.go index 4d8878e..f37afa9 100644 --- a/pkg/es/cluster_settings.go +++ b/pkg/es/cluster_settings.go @@ -20,7 +20,6 @@ import ( "context" "encoding/json" "fmt" - "log/slog" "codeberg.org/scip/esctl/pkg/cfg" "codeberg.org/scip/esctl/pkg/printer" @@ -29,6 +28,7 @@ import ( func ClusterSettingsList(conf *cfg.Config) error { res, err := conf.DefaultCluster.ES().Cluster.GetSettings(). + FlatSettings(true). Do(context.Background()) if err != nil { return fmt.Errorf("failed to get cluster settings: %s", esErrorString(err)) @@ -48,19 +48,7 @@ func ClusterSettingsList(conf *cfg.Config) error { } for topic, val := range settingshash { - data := map[string]any{} - - err := json.Unmarshal(val, &data) - if err != nil { - return fmt.Errorf("failed to unmarshall setting for topic %s: %s", topic, err) - } - - paths := getJsonPath(map[string]string{}, data, topic) - slog.Debug("settings", topic, paths) - - for setting, value := range paths { - entries = append(entries, []string{setting, fmt.Sprintf("%v", value)}) - } + entries = append(entries, []string{topic, string(val)}) } table.Entries = entries diff --git a/pkg/es/cluster_util.go b/pkg/es/cluster_util.go index 57053d0..8800c92 100644 --- a/pkg/es/cluster_util.go +++ b/pkg/es/cluster_util.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "regexp" - "strconv" "strings" "codeberg.org/scip/esctl/pkg/cfg" @@ -330,44 +329,3 @@ func splitArg(arg string) (string, string) { return parts[0], parts[1] } } - -// recursively traverse the raw settings hash and build a flat map -// consisting of the translated path and its value. -// -// e.g. -// logger: -// -// org: -// elasticsearch: -// transport: -// OutboundHandler: "ERROR" -// -// gets: -// -// logger.org.elasticsearch.transport.OutboundHandler: "ERROR" -func getJsonPath(paths map[string]string, raw map[string]any, topic string) map[string]string { - for name, data := range raw { - path := topic + "." + name - - switch value := data.(type) { - case string: - paths[path] = value - case *string: - paths[path] = *value - case int: - paths[path] = strconv.Itoa(value) - case *int: - paths[path] = strconv.Itoa(*value) - case map[string]any: - paths = getJsonPath(paths, value, path) - case []any: - val := []string{} - for _, item := range value { - val = append(val, fmt.Sprintf("%v", item)) - } - paths[path] = strings.Join(val, ",") - } - } - - return paths -} diff --git a/pkg/es/index_template_settings.go b/pkg/es/index_template_settings.go index 983920f..92df17c 100644 --- a/pkg/es/index_template_settings.go +++ b/pkg/es/index_template_settings.go @@ -28,7 +28,7 @@ type Tpl struct { } func getIndexTemplateSettings(conf *cfg.Config, tplname string, table *printer.Table) error { - raw, err := CallAPI(conf, "GET", "/_index_template/"+tplname, "") + raw, err := CallAPI(conf, "GET", "/_index_template/"+tplname+"?flat_settings", "") if err != nil { return err } @@ -52,11 +52,7 @@ func getIndexTemplateSettings(conf *cfg.Config, tplname string, table *printer.T tpl := data.IndexTemplates[0].IndexTemplate.Template.Settings for topic, val := range tpl { - paths := getJsonPath(map[string]string{}, val.(map[string]any), topic) - - for setting, value := range paths { - table.Entries = append(table.Entries, []string{setting, fmt.Sprintf("%v", value)}) - } + table.Entries = append(table.Entries, []string{topic, fmt.Sprintf("%v", val)}) } return nil diff --git a/pkg/printer/table.go b/pkg/printer/table.go index 236ffc8..977a2f4 100644 --- a/pkg/printer/table.go +++ b/pkg/printer/table.go @@ -157,7 +157,7 @@ func (data *Table) PrintTSV() error { for idx, entry := range entries { length := visibleLen(entry) - if length+currentWidth > data.maxwidth { + if length+currentWidth > data.maxwidth && data.maxwidth-currentWidth > 1 { // text is too wide to be put into one line, wrap it wrapper := wordwrap.Wrapper(data.maxwidth-currentWidth, false) wrapped := wrapper(entry)