mirror of https://github.com/hashicorp/consul
Update view filter logic
parent
f56894fdc1
commit
ced73fc2ce
|
@ -52,7 +52,7 @@ func NewHealthView(req structs.ServiceSpecificRequest) (*HealthView, error) {
|
||||||
return &HealthView{
|
return &HealthView{
|
||||||
state: make(map[string]structs.CheckServiceNode),
|
state: make(map[string]structs.CheckServiceNode),
|
||||||
filter: fe,
|
filter: fe,
|
||||||
name: req.ServiceName,
|
connect: req.Connect,
|
||||||
kind: req.ServiceKind,
|
kind: req.ServiceKind,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func NewHealthView(req structs.ServiceSpecificRequest) (*HealthView, error) {
|
||||||
// (IndexedCheckServiceNodes) and update it in place for each event - that
|
// (IndexedCheckServiceNodes) and update it in place for each event - that
|
||||||
// involves re-sorting each time etc. though.
|
// involves re-sorting each time etc. though.
|
||||||
type HealthView struct {
|
type HealthView struct {
|
||||||
name string
|
connect bool
|
||||||
kind structs.ServiceKind
|
kind structs.ServiceKind
|
||||||
state map[string]structs.CheckServiceNode
|
state map[string]structs.CheckServiceNode
|
||||||
filter filterEvaluator
|
filter filterEvaluator
|
||||||
|
@ -112,14 +112,8 @@ func (s *HealthView) Update(events []*pbsubscribe.Event) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HealthView) skipFilter(csn *structs.CheckServiceNode) bool {
|
func (s *HealthView) skipFilter(csn *structs.CheckServiceNode) bool {
|
||||||
// we only do this for services that need to be routed through a gateway
|
// we only do this for connect-enabled services that need to be routed through a terminating gateway
|
||||||
if s.kind != "" {
|
return s.kind == "" && s.connect && csn.Service.Kind == structs.ServiceKindTerminatingGateway
|
||||||
return false
|
|
||||||
}
|
|
||||||
if s.name != csn.Service.Service && csn.Service.Kind == structs.ServiceKindTerminatingGateway {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type filterEvaluator interface {
|
type filterEvaluator interface {
|
||||||
|
|
|
@ -944,7 +944,8 @@ func TestNewFilterEvaluator(t *testing.T) {
|
||||||
|
|
||||||
func TestHealthView_SkipFilteringTerminatingGateways(t *testing.T) {
|
func TestHealthView_SkipFilteringTerminatingGateways(t *testing.T) {
|
||||||
view, err := NewHealthView(structs.ServiceSpecificRequest{
|
view, err := NewHealthView(structs.ServiceSpecificRequest{
|
||||||
ServiceName: "web",
|
ServiceName: "name",
|
||||||
|
Connect: true,
|
||||||
QueryOptions: structs.QueryOptions{
|
QueryOptions: structs.QueryOptions{
|
||||||
Filter: "Service.Meta.version == \"v1\"",
|
Filter: "Service.Meta.version == \"v1\"",
|
||||||
},
|
},
|
||||||
|
@ -959,7 +960,7 @@ func TestHealthView_SkipFilteringTerminatingGateways(t *testing.T) {
|
||||||
CheckServiceNode: &pbservice.CheckServiceNode{
|
CheckServiceNode: &pbservice.CheckServiceNode{
|
||||||
Service: &pbservice.NodeService{
|
Service: &pbservice.NodeService{
|
||||||
Kind: structs.TerminatingGateway,
|
Kind: structs.TerminatingGateway,
|
||||||
Service: "gateway",
|
Service: "name",
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Port: 8443,
|
Port: 8443,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue