From 0a5a5aae2a07c55681582157bf4296bdf6531483 Mon Sep 17 00:00:00 2001 From: Paschalis Tsilias Date: Fri, 13 Oct 2023 15:39:02 +0300 Subject: [PATCH] clustering: fix handling of empty join-addresses flag (#5454) Signed-off-by: Paschalis Tsilias --- CHANGELOG.md | 3 +++ cmd/internal/flowmode/cluster_builder_test.go | 18 ++++++++++++++++++ cmd/internal/flowmode/cmd_run.go | 9 ++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 cmd/internal/flowmode/cluster_builder_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index fa2f2432c2fe..60d0f8c46690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ Main (unreleased) - Fixed an issue where `loki.process` validation for stage `metric.counter` was allowing invalid combination of configuration options. (@thampiotr) + +- Fix the handling of the `--cluster.join-addresses` flag causing an invalid + comparison with the mutually-exclusive `--cluster.discover-peers`. (@tpaschalis) ### Enhancements diff --git a/cmd/internal/flowmode/cluster_builder_test.go b/cmd/internal/flowmode/cluster_builder_test.go new file mode 100644 index 000000000000..d8dad09a6f4e --- /dev/null +++ b/cmd/internal/flowmode/cluster_builder_test.go @@ -0,0 +1,18 @@ +package flowmode + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestBuildClusterService(t *testing.T) { + opts := clusterOptions{ + JoinPeers: []string{"foo", "bar"}, + DiscoverPeers: "provider=aws key1=val1 key2=val2", + } + + cs, err := buildClusterService(opts) + require.Nil(t, cs) + require.EqualError(t, err, "at most one of join peers and discover peers may be set") +} diff --git a/cmd/internal/flowmode/cmd_run.go b/cmd/internal/flowmode/cmd_run.go index 9b989a06dd66..6ef916470d85 100644 --- a/cmd/internal/flowmode/cmd_run.go +++ b/cmd/internal/flowmode/cmd_run.go @@ -210,7 +210,7 @@ func (fr *flowRun) Run(configPath string) error { NodeName: fr.clusterNodeName, AdvertiseAddress: fr.clusterAdvAddr, ListenAddress: fr.httpListenAddr, - JoinPeers: strings.Split(fr.clusterJoinAddr, ","), + JoinPeers: splitPeers(fr.clusterJoinAddr, ","), DiscoverPeers: fr.clusterDiscoverPeers, RejoinInterval: fr.clusterRejoinInterval, AdvertiseInterfaces: fr.clusterAdvInterfaces, @@ -430,3 +430,10 @@ func interruptContext() (context.Context, context.CancelFunc) { return ctx, cancel } + +func splitPeers(s, sep string) []string { + if len(s) == 0 { + return []string{} + } + return strings.Split(s, sep) +}