Skip to content

Commit

Permalink
[Streaming] Set KnownLeader by default when streaming is activated
Browse files Browse the repository at this point in the history
This is not a real fix but will avoid breaking clients relying on this header

Fix hashicorp#9776
  • Loading branch information
pierresouchay authored and PHBourquin committed Apr 22, 2021
1 parent d50f7c6 commit c4cb57d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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 @@ -163,12 +163,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 @@ -234,6 +236,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 @@ -245,5 +250,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 @@ -45,7 +45,8 @@ func TestStreamingHealthServices_EmptySnapshot(t *testing.T) {
empty := &structs.IndexedCheckServiceNodes{
Nodes: structs.CheckServiceNodes{},
QueryMeta: structs.QueryMeta{
Index: 1,
Index: 1,
KnownLeader: true,
},
}

Expand Down

0 comments on commit c4cb57d

Please sign in to comment.