diff --git a/.changelog/9778.txt b/.changelog/9778.txt new file mode 100644 index 000000000000..29435f1c2b7c --- /dev/null +++ b/.changelog/9778.txt @@ -0,0 +1,3 @@ +```release-note:bug +streaming: return X-Consul-KnownLeader properly set when using streaming +``` diff --git a/agent/cache-types/streaming_health_services.go b/agent/cache-types/streaming_health_services.go index d150a43f48e3..c5bfe03e874c 100644 --- a/agent/cache-types/streaming_health_services.go +++ b/agent/cache-types/streaming_health_services.go @@ -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 { @@ -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 { @@ -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) } diff --git a/agent/cache-types/streaming_health_services_test.go b/agent/cache-types/streaming_health_services_test.go index 4c16bd12c44f..14b0691e586f 100644 --- a/agent/cache-types/streaming_health_services_test.go +++ b/agent/cache-types/streaming_health_services_test.go @@ -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, }, }