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

[Streaming] Set KnownLeader by default when streaming is activated #9778

Closed
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/9778.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
streaming: return X-Consul-KnownLeader properly set when using streaming
```
10 changes: 8 additions & 2 deletions agent/cache-types/streaming_health_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ func newHealthView(filterExpr string) (*healthView, error) {
// (IndexedCheckServiceNodes) and update it in place for each event - that
// involves re-sorting each time etc. though.
type healthView struct {
state map[string]structs.CheckServiceNode
filter filterEvaluator
state map[string]structs.CheckServiceNode
filter filterEvaluator
knownLeader bool
}

// Update implements View
func (s *healthView) Update(events []*pbsubscribe.Event) error {
s.knownLeader = true
for _, event := range events {
serviceHealth := event.GetServiceHealth()
if serviceHealth == nil {
Expand Down Expand Up @@ -227,6 +229,9 @@ func (s *healthView) Result(index uint64) (interface{}, error) {
Nodes: make(structs.CheckServiceNodes, 0, len(s.state)),
QueryMeta: structs.QueryMeta{
Index: index,
// TODO: fill properly those fields, see https://github.com/hashicorp/consul/issues/9776
KnownLeader: s.knownLeader,
LastContact: 0,
},
}
for _, node := range s.state {
Expand All @@ -238,5 +243,6 @@ func (s *healthView) Result(index uint64) (interface{}, error) {
}

func (s *healthView) Reset() {
s.knownLeader = false
s.state = make(map[string]structs.CheckServiceNode)
}
3 changes: 2 additions & 1 deletion agent/cache-types/streaming_health_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func TestStreamingHealthServices_EmptySnapshot(t *testing.T) {
empty := &structs.IndexedCheckServiceNodes{
Nodes: structs.CheckServiceNodes{},
QueryMeta: structs.QueryMeta{
Index: 1,
Index: 1,
KnownLeader: true,
},
}

Expand Down