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 25, 2022
1 parent 122d3cd commit 610e3ad
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 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
4 changes: 1 addition & 3 deletions tests/rptest/tests/rpk_start_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def test_container_mode(self):
expected_cluster_properties = {
"auto_create_topics_enabled": "true",
"group_topic_partitions": "3",
# RPK returns scientific notation for large int values.
# https://github.com/redpanda-data/redpanda/issues/6070
"storage_min_free_bytes": "1.048576e+07",
"storage_min_free_bytes": "10485760",
"topic_partitions_per_shard": "1000"
}

Expand Down

0 comments on commit 610e3ad

Please sign in to comment.