Skip to content

Commit

Permalink
rpk cluster config get: avoid scientific notation
Browse files Browse the repository at this point in the history
The scientific notation was from json unmarshal rules. We now convert to
int64 directly.

Note that edit, import, and export all handle this already.

We remove the one impossible branch in export, since we know we cannot
have an `int` in the config map, and we remove the hack in the test that
converted from scientific notation.

Closes redpanda-data#6070.
  • Loading branch information
twmb committed Oct 23, 2022
1 parent bf76626 commit ce3143b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/go/rpk/pkg/cli/cmd/cluster/config/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ func exportConfig(
} else {
scalarVal := ""
switch x := curValue.(type) {
case int:
scalarVal = strconv.Itoa(x)
case float64:
scalarVal = strconv.FormatFloat(x, 'f', -1, 64)
case string:
Expand Down
7 changes: 7 additions & 0 deletions src/go/rpk/pkg/cli/cmd/cluster/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ output, use the 'edit' and 'export' commands respectively.`,
if !exists {
out.Die("Property '%s' not found", key)
} else {
// currentConfig is the result of json.Unmarshal into a
// map[string]interface{}. Due to json rules, all numbers
// are float64. We do not want to print floats, especially
// for large numbers.
if f64, ok := val.(float64); ok {
val = int64(f64)
}
// Intentionally bare output, so that the output can be readily
// consumed in a script.
bytes, err := yaml.Marshal(val)
Expand Down
5 changes: 0 additions & 5 deletions tests/rptest/tests/cluster_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,11 +939,6 @@ def yamlize(input) -> str:

expect_cli_readback = yamlize(e.yamlval)

# Hack around scientific notation for large int values.
# This may be an RPK bug?
if cli_readback.find("e+") != -1:
cli_readback = str(int(float(cli_readback)))

self.logger.info(
f"CLI readback '{cli_readback}' expect '{expect_cli_readback}'"
)
Expand Down

0 comments on commit ce3143b

Please sign in to comment.