Update view filter logic

pull/16499/head
Andrew Stucki 2023-03-03 11:17:06 -05:00
parent f56894fdc1
commit ced73fc2ce
2 changed files with 13 additions and 18 deletions

View File

@ -52,7 +52,7 @@ func NewHealthView(req structs.ServiceSpecificRequest) (*HealthView, error) {
return &HealthView{
state: make(map[string]structs.CheckServiceNode),
filter: fe,
name: req.ServiceName,
connect: req.Connect,
kind: req.ServiceKind,
}, nil
}
@ -63,7 +63,7 @@ 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
connect bool
kind structs.ServiceKind
state map[string]structs.CheckServiceNode
filter filterEvaluator
@ -112,14 +112,8 @@ func (s *HealthView) Update(events []*pbsubscribe.Event) error {
}
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
// we only do this for connect-enabled services that need to be routed through a terminating gateway
return s.kind == "" && s.connect && csn.Service.Kind == structs.ServiceKindTerminatingGateway
}
type filterEvaluator interface {

View File

@ -944,7 +944,8 @@ func TestNewFilterEvaluator(t *testing.T) {
func TestHealthView_SkipFilteringTerminatingGateways(t *testing.T) {
view, err := NewHealthView(structs.ServiceSpecificRequest{
ServiceName: "web",
ServiceName: "name",
Connect: true,
QueryOptions: structs.QueryOptions{
Filter: "Service.Meta.version == \"v1\"",
},
@ -959,7 +960,7 @@ func TestHealthView_SkipFilteringTerminatingGateways(t *testing.T) {
CheckServiceNode: &pbservice.CheckServiceNode{
Service: &pbservice.NodeService{
Kind: structs.TerminatingGateway,
Service: "gateway",
Service: "name",
Address: "127.0.0.1",
Port: 8443,
},