diff --git a/CHANGELOG.md b/CHANGELOG.md index f14513cc1174..c7fb3e8a1bf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,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) +}