From 892d389d9b177c90ffa886bf3bc5d17a87556cec Mon Sep 17 00:00:00 2001 From: Andrew Stucki Date: Wed, 1 Mar 2023 23:02:43 -0500 Subject: [PATCH] Fix resolution of service resolvers with subsets for external upstreams --- agent/rpcclient/health/view.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/agent/rpcclient/health/view.go b/agent/rpcclient/health/view.go index 1684382de7..1e81e13837 100644 --- a/agent/rpcclient/health/view.go +++ b/agent/rpcclient/health/view.go @@ -52,6 +52,8 @@ func NewHealthView(req structs.ServiceSpecificRequest) (*HealthView, error) { return &HealthView{ state: make(map[string]structs.CheckServiceNode), filter: fe, + name: req.ServiceName, + kind: req.ServiceKind, }, nil } @@ -61,6 +63,8 @@ func NewHealthView(req structs.ServiceSpecificRequest) (*HealthView, error) { // (IndexedCheckServiceNodes) and update it in place for each event - that // involves re-sorting each time etc. though. type HealthView struct { + name string + kind structs.ServiceKind state map[string]structs.CheckServiceNode filter filterEvaluator } @@ -84,6 +88,13 @@ func (s *HealthView) Update(events []*pbsubscribe.Event) error { if csn == nil { return errors.New("check service node was unexpectedly nil") } + + // check if we intentionally need to skip the filter + if s.skipFilter(csn) { + s.state[id] = *csn + continue + } + passed, err := s.filter.Evaluate(*csn) if err != nil { return err @@ -100,6 +111,17 @@ func (s *HealthView) Update(events []*pbsubscribe.Event) error { return nil } +func (s *HealthView) skipFilter(csn *structs.CheckServiceNode) bool { + // we only do this for services that need to be routed through a gateway + if s.kind != "" { + return false + } + if s.name != csn.Service.Service && csn.Service.Kind == structs.ServiceKindTerminatingGateway { + return true + } + return false +} + type filterEvaluator interface { Evaluate(datum interface{}) (bool, error) }