From 610e3ad8a5d4806dc4edb44c4e2d18bed61f8694 Mon Sep 17 00:00:00 2001 From: Travis Bischel Date: Thu, 20 Oct 2022 22:51:20 -0600 Subject: [PATCH] rpk cluster config get: avoid scientific notation 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 #6070. --- src/go/rpk/pkg/cli/cmd/cluster/config/export.go | 2 -- src/go/rpk/pkg/cli/cmd/cluster/config/get.go | 7 +++++++ tests/rptest/tests/cluster_config_test.py | 5 ----- tests/rptest/tests/rpk_start_test.py | 4 +--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/go/rpk/pkg/cli/cmd/cluster/config/export.go b/src/go/rpk/pkg/cli/cmd/cluster/config/export.go index adc747bd0c44b..7b45671fd8646 100644 --- a/src/go/rpk/pkg/cli/cmd/cluster/config/export.go +++ b/src/go/rpk/pkg/cli/cmd/cluster/config/export.go @@ -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: diff --git a/src/go/rpk/pkg/cli/cmd/cluster/config/get.go b/src/go/rpk/pkg/cli/cmd/cluster/config/get.go index bf79664077148..e098badca95f7 100644 --- a/src/go/rpk/pkg/cli/cmd/cluster/config/get.go +++ b/src/go/rpk/pkg/cli/cmd/cluster/config/get.go @@ -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) diff --git a/tests/rptest/tests/cluster_config_test.py b/tests/rptest/tests/cluster_config_test.py index 8e3ce71d2d6b5..f968db328d42e 100644 --- a/tests/rptest/tests/cluster_config_test.py +++ b/tests/rptest/tests/cluster_config_test.py @@ -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}'" ) diff --git a/tests/rptest/tests/rpk_start_test.py b/tests/rptest/tests/rpk_start_test.py index e978693e0b1af..f2c62cfaba86a 100644 --- a/tests/rptest/tests/rpk_start_test.py +++ b/tests/rptest/tests/rpk_start_test.py @@ -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" }