Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clustering: fix handling of empty join-addresses flag #5454

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have a test with JoinPeers empty string somewhere, or setting a flag to it?

Copy link
Member Author

@tpaschalis tpaschalis Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looking into it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sorry, didn't post the comment beforehand).

After taking a look we don't have a good place for putting tests related to flag parsing. I'd like to (sooner or later) move ahead with #4973 which would cover this. I'm merging this to move ahead with the patch release.

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)
}