Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed May 9, 2024
1 parent b580794 commit 7f27e66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions go/vt/discovery/topology_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion go/vt/discovery/topology_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}))
Expand Down

0 comments on commit 7f27e66

Please sign in to comment.