From 65e9d19f3c791b56a39679616e6a9c51d20ecc39 Mon Sep 17 00:00:00 2001 From: Zakhar Bessarab Date: Thu, 17 Oct 2024 14:05:47 +0400 Subject: [PATCH] lib/flagutil/dict: properly update default value in case there is no key value set (#7211) ### Describe Your Changes If a dict flag has only one value without a prefix it is supposed to replace default value. Previously, when flag was set to `-flag=2` and the default value in `NewDictInt` was set to 1 the resulting value for any `flag.Get()` call would be 1 which is not expected. This commit updates default value for the flag in case there is only one entry for flag and the entry is a number without a key. This affects cluster version and specifically `replicationFactor` flag usage with vmstorage [node groups](https://docs.victoriametrics.com/cluster-victoriametrics/#vmstorage-groups-at-vmselect). Previously, the following configuration would effectively be ignored: ``` /path/to/vmselect \ -replicationFactor=2 \ -storageNode=g1/host1,g1/host2,g1/host3 \ -storageNode=g2/host4,g2/host5,g2/host6 \ -storageNode=g3/host7,g3/host8,g3/host9 ``` Changes from this PR will force default value for `replicationFactor` flag to be set to `2` which is expected as the result of this configuration. --------- Signed-off-by: Zakhar Bessarab --- docs/changelog/CHANGELOG.md | 2 ++ lib/flagutil/dict.go | 1 + lib/flagutil/dict_test.go | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/changelog/CHANGELOG.md b/docs/changelog/CHANGELOG.md index b9a1e5b8c..80254a6fe 100644 --- a/docs/changelog/CHANGELOG.md +++ b/docs/changelog/CHANGELOG.md @@ -32,6 +32,8 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/). * BUGFIX: [vmalert-tool](https://docs.victoriametrics.com/vmalert-tool/): reduce the initial health check interval for datasource. This reduces the time spent on evaluating rules by vmalert-tool. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6970). * BUGFIX: [vmalert-tool](https://docs.victoriametrics.com/vmalert-tool/): allow specifying empty labels list `labels: '{}'` in the same way as promtool does. This improves compatibility between these tools. +* BUGFIX: [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): properly apply replication factor when storage node groups are used and replication factor is configured via global value such as `-replicationFactor=2`. Previously, global replication factor was ignored for storage node groups. See [these docs](https://docs.victoriametrics.com/cluster-victoriametrics/#vmstorage-groups-at-vmselect) for more information about storage groups configuration. + ## [v1.104.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.104.0) Released at 2024-10-02 diff --git a/lib/flagutil/dict.go b/lib/flagutil/dict.go index a7ae57393..25f5f09dd 100644 --- a/lib/flagutil/dict.go +++ b/lib/flagutil/dict.go @@ -56,6 +56,7 @@ func (di *DictInt) Set(value string) error { di.kvs = append(di.kvs, kIntValue{ v: v, }) + di.defaultValue = v return nil } for _, x := range values { diff --git a/lib/flagutil/dict_test.go b/lib/flagutil/dict_test.go index d1aebb1dc..2df07991a 100644 --- a/lib/flagutil/dict_test.go +++ b/lib/flagutil/dict_test.go @@ -109,5 +109,5 @@ func TestDictIntGet(t *testing.T) { f("foo:42", "", 123, 123) f("foo:42", "foo", 123, 42) f("532", "", 123, 532) - f("532", "foo", 123, 123) + f("532", "foo", 123, 532) }