mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 05:04:18 +02:00
get rid of getJsonPath, use flat_settings query flag instead (#66)
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
|
||||||
|
|
||||||
"codeberg.org/scip/esctl/pkg/cfg"
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
"codeberg.org/scip/esctl/pkg/printer"
|
"codeberg.org/scip/esctl/pkg/printer"
|
||||||
@@ -29,6 +28,7 @@ import (
|
|||||||
|
|
||||||
func ClusterSettingsList(conf *cfg.Config) error {
|
func ClusterSettingsList(conf *cfg.Config) error {
|
||||||
res, err := conf.DefaultCluster.ES().Cluster.GetSettings().
|
res, err := conf.DefaultCluster.ES().Cluster.GetSettings().
|
||||||
|
FlatSettings(true).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get cluster settings: %s", esErrorString(err))
|
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 {
|
for topic, val := range settingshash {
|
||||||
data := map[string]any{}
|
entries = append(entries, []string{topic, string(val)})
|
||||||
|
|
||||||
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)})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table.Entries = entries
|
table.Entries = entries
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"codeberg.org/scip/esctl/pkg/cfg"
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
@@ -330,44 +329,3 @@ func splitArg(arg string) (string, string) {
|
|||||||
return parts[0], parts[1]
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ type Tpl struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getIndexTemplateSettings(conf *cfg.Config, tplname string, table *printer.Table) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -52,11 +52,7 @@ func getIndexTemplateSettings(conf *cfg.Config, tplname string, table *printer.T
|
|||||||
|
|
||||||
tpl := data.IndexTemplates[0].IndexTemplate.Template.Settings
|
tpl := data.IndexTemplates[0].IndexTemplate.Template.Settings
|
||||||
for topic, val := range tpl {
|
for topic, val := range tpl {
|
||||||
paths := getJsonPath(map[string]string{}, val.(map[string]any), topic)
|
table.Entries = append(table.Entries, []string{topic, fmt.Sprintf("%v", val)})
|
||||||
|
|
||||||
for setting, value := range paths {
|
|
||||||
table.Entries = append(table.Entries, []string{setting, fmt.Sprintf("%v", value)})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ func (data *Table) PrintTSV() error {
|
|||||||
for idx, entry := range entries {
|
for idx, entry := range entries {
|
||||||
length := visibleLen(entry)
|
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
|
// text is too wide to be put into one line, wrap it
|
||||||
wrapper := wordwrap.Wrapper(data.maxwidth-currentWidth, false)
|
wrapper := wordwrap.Wrapper(data.maxwidth-currentWidth, false)
|
||||||
wrapped := wrapper(entry)
|
wrapped := wrapper(entry)
|
||||||
|
|||||||
Reference in New Issue
Block a user