From 7f27e66642cdc9492bc651cad5a6646ccdf316b8 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Fri, 10 May 2024 01:21:28 +0200 Subject: [PATCH] cleanup Signed-off-by: Tim Vaillancourt --- go/vt/discovery/topology_watcher.go | 12 +++++++++--- go/vt/discovery/topology_watcher_test.go | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/go/vt/discovery/topology_watcher.go b/go/vt/discovery/topology_watcher.go index 0b8d87467ef..d53f8505ff2 100644 --- a/go/vt/discovery/topology_watcher.go +++ b/go/vt/discovery/topology_watcher.go @@ -386,18 +386,24 @@ func (fbk *FilterByKeyspace) IsIncluded(tablet *topodata.Tablet) bool { return exist } -// TODO: +// FilterByTabletTags is a filter that filters tablets by tablet tag key/values. type FilterByTabletTags struct { tags map[string]string } +// NewFilterByTabletTags creates a new FilterByTabletTags. All tablets that match +// all tablet tags will be forwarded to the TopologyWatcher's consumer. func NewFilterByTabletTags(tabletTags map[string]string) *FilterByTabletTags { - return &FilterByTabletTags{tags: tabletTags} + return &FilterByTabletTags{ + tags: tabletTags, + } } // IsIncluded returns true if the tablet's tags match what we expect. func (fbtg *FilterByTabletTags) IsIncluded(tablet *topodata.Tablet) bool { - if tablet.Tags == nil { + if fbtg.tags == nil { + return true + } else if tablet.Tags == nil { return false } for key, val := range fbtg.tags { diff --git a/go/vt/discovery/topology_watcher_test.go b/go/vt/discovery/topology_watcher_test.go index 8ffb9b73b44..e76e2ef894a 100644 --- a/go/vt/discovery/topology_watcher_test.go +++ b/go/vt/discovery/topology_watcher_test.go @@ -579,11 +579,16 @@ func TestFilterByKeyspaceSkipsIgnoredTablets(t *testing.T) { } func TestNewFilterByTabletTags(t *testing.T) { + // no required tags == true + filter := NewFilterByTabletTags(nil) + assert.True(t, filter.IsIncluded(&topodatapb.Tablet{})) + tags := map[string]string{ "instance_type": "i3.xlarge", "some_key": "some_value", } - filter := NewFilterByTabletTags(tags) + filter = NewFilterByTabletTags(tags) + assert.False(t, filter.IsIncluded(&topodatapb.Tablet{ Tags: nil, }))