Fix resolution of service resolvers with subsets for external upstreams

pull/16499/head
Andrew Stucki 2 years ago
parent 21c30958cc
commit 892d389d9b

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

Loading…
Cancel
Save