Skip to content

Commit

Permalink
clustering: fix handling of empty join-addresses flag (grafana#5454)
Browse files Browse the repository at this point in the history
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
(cherry picked from commit 0a5a5aa)
  • Loading branch information
tpaschalis committed Oct 16, 2023
1 parent 5ecd1e7 commit 32f3b06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions cmd/internal/flowmode/cluster_builder_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
9 changes: 8 additions & 1 deletion cmd/internal/flowmode/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

0 comments on commit 32f3b06

Please sign in to comment.