Skip to content

Commit

Permalink
refactor: unexported variables in healthcheck.go
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
frouioui committed Mar 10, 2022
1 parent 1e59d83 commit 87fe76d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
33 changes: 16 additions & 17 deletions go/vt/discovery/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,28 @@ var (
TabletURLTemplateString = flag.String("tablet_url_template", "http://{{.GetTabletHostPort}}", "format string describing debug tablet url formatting. See the Go code for getTabletDebugURL() how to customize this.")
tabletURLTemplate *template.Template

//TODO(deepthi): change these vars back to unexported when discoveryGateway is removed

// AllowedTabletTypes is the list of allowed tablet types. e.g. {PRIMARY, REPLICA}
AllowedTabletTypes []topodata.TabletType
// TabletFilters are the keyspace|shard or keyrange filters to apply to the full set of tablets
TabletFilters flagutil.StringListValue
// KeyspacesToWatch - if provided this specifies which keyspaces should be
// visible to the healthcheck. By default the healthcheck will watch all keyspaces.
KeyspacesToWatch flagutil.StringListValue
// RefreshInterval is the interval at which healthcheck refreshes its list of tablets from topo
RefreshInterval = flag.Duration("tablet_refresh_interval", 1*time.Minute, "tablet refresh interval")
// RefreshKnownTablets tells us whether to process all tablets or only new tablets
RefreshKnownTablets = flag.Bool("tablet_refresh_known_tablets", true, "tablet refresh reloads the tablet address/port map from topo in case it changes")
// TopoReadConcurrency tells us how many topo reads are allowed in parallel
TopoReadConcurrency = flag.Int("topo_read_concurrency", 32, "concurrent topo reads")

// tabletFilters are the keyspace|shard or keyrange filters to apply to the full set of tablets
tabletFilters flagutil.StringListValue
// refreshInterval is the interval at which healthcheck refreshes its list of tablets from topo
refreshInterval = flag.Duration("tablet_refresh_interval", 1*time.Minute, "tablet refresh interval")
// refreshKnownTablets tells us whether to process all tablets or only new tablets
refreshKnownTablets = flag.Bool("tablet_refresh_known_tablets", true, "tablet refresh reloads the tablet address/port map from topo in case it changes")
// topoReadConcurrency tells us how many topo reads are allowed in parallel
topoReadConcurrency = flag.Int("topo_read_concurrency", 32, "concurrent topo reads")
)

// See the documentation for NewHealthCheck below for an explanation of these parameters.
const (
DefaultHealthCheckRetryDelay = 5 * time.Second
DefaultHealthCheckTimeout = 1 * time.Minute
defaultHealthCheckRetryDelay = 5 * time.Second
defaultHealthCheckTimeout = 1 * time.Minute

// DefaultTopoReadConcurrency is used as the default value for the TopoReadConcurrency parameter of a TopologyWatcher.
// DefaultTopoReadConcurrency is used as the default value for the topoReadConcurrency parameter of a TopologyWatcher.
DefaultTopoReadConcurrency int = 5
// DefaultTopologyWatcherRefreshInterval is used as the default value for
// the refresh interval of a topology watcher.
Expand Down Expand Up @@ -141,7 +140,7 @@ func ParseTabletURLTemplateFromFlag() {
func init() {
// Flags are not parsed at this point and the default value of the flag (just the hostname) will be used.
ParseTabletURLTemplateFromFlag()
flag.Var(&TabletFilters, "tablet_filters", "Specifies a comma-separated list of 'keyspace|shard_name or keyrange' values to filter the tablets to watch")
flag.Var(&tabletFilters, "tablet_filters", "Specifies a comma-separated list of 'keyspace|shard_name or keyrange' values to filter the tablets to watch")
topoproto.TabletTypeListVar(&AllowedTabletTypes, "allowed_tablet_types", "Specifies the tablet types this vtgate is allowed to route queries to")
flag.Var(&KeyspacesToWatch, "keyspaces_to_watch", "Specifies which keyspaces this vtgate should have access to while routing queries or accessing the vschema")
}
Expand Down Expand Up @@ -283,20 +282,20 @@ func NewHealthCheck(ctx context.Context, retryDelay, healthCheckTimeout time.Dur
if c == "" {
continue
}
if len(TabletFilters) > 0 {
if len(tabletFilters) > 0 {
if len(KeyspacesToWatch) > 0 {
log.Exitf("Only one of -keyspaces_to_watch and -tablet_filters may be specified at a time")
}

fbs, err := NewFilterByShard(TabletFilters)
fbs, err := NewFilterByShard(tabletFilters)
if err != nil {
log.Exitf("Cannot parse tablet_filters parameter: %v", err)
}
filter = fbs
} else if len(KeyspacesToWatch) > 0 {
filter = NewFilterByKeyspace(KeyspacesToWatch)
}
topoWatchers = append(topoWatchers, NewCellTabletsWatcher(ctx, topoServer, hc, filter, c, *RefreshInterval, *RefreshKnownTablets, *TopoReadConcurrency))
topoWatchers = append(topoWatchers, NewCellTabletsWatcher(ctx, topoServer, hc, filter, c, *refreshInterval, *refreshKnownTablets, *topoReadConcurrency))
}

hc.topoWatchers = topoWatchers
Expand Down
2 changes: 1 addition & 1 deletion go/vt/discovery/legacy_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ type legacyTabletHealth struct {

// NewLegacyDefaultHealthCheck creates a new LegacyHealthCheck object with a default configuration.
func NewLegacyDefaultHealthCheck() LegacyHealthCheck {
return NewLegacyHealthCheck(DefaultHealthCheckRetryDelay, DefaultHealthCheckTimeout)
return NewLegacyHealthCheck(defaultHealthCheckRetryDelay, defaultHealthCheckTimeout)
}

// NewLegacyHealthCheck creates a new LegacyHealthCheck object.
Expand Down
2 changes: 1 addition & 1 deletion go/vt/discovery/legacy_topology_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewLegacyCellTabletsWatcher(ctx context.Context, topoServer *topo.Server, t
// NewLegacyShardReplicationWatcher returns a LegacyTopologyWatcher that
// monitors the tablets in a cell/keyspace/shard, and starts refreshing.
func NewLegacyShardReplicationWatcher(ctx context.Context, topoServer *topo.Server, tr LegacyTabletRecorder, cell, keyspace, shard string, refreshInterval time.Duration, topoReadConcurrency int) *LegacyTopologyWatcher {
return NewLegacyTopologyWatcher(ctx, topoServer, tr, cell, refreshInterval, true /* RefreshKnownTablets */, topoReadConcurrency, func(tw *LegacyTopologyWatcher) ([]*topodatapb.TabletAlias, error) {
return NewLegacyTopologyWatcher(ctx, topoServer, tr, cell, refreshInterval, true /* refreshKnownTablets */, topoReadConcurrency, func(tw *LegacyTopologyWatcher) ([]*topodatapb.TabletAlias, error) {
sri, err := tw.topoServer.GetShardReplication(ctx, tw.cell, keyspace, shard)
switch {
case err == nil:
Expand Down
8 changes: 4 additions & 4 deletions go/vt/discovery/legacy_topology_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func checkLegacyWatcher(t *testing.T, cellTablets, refreshKnownTablets bool) {
}
tw.loadTablets()

// If RefreshKnownTablets is disabled, only the new tablet is read
// If refreshKnownTablets is disabled, only the new tablet is read
// from the topo
if refreshKnownTablets {
counts = checkLegacyOpCounts(t, tw, counts, map[string]int64{"ListTablets": 1, "GetTablet": 2, "AddTablet": 1})
Expand All @@ -154,7 +154,7 @@ func checkLegacyWatcher(t *testing.T, cellTablets, refreshKnownTablets bool) {
t.Errorf("fhc.GetAllTablets() = %+v; want %+v", allTablets, tablet2)
}

// Load the tablets again to show that when RefreshKnownTablets is disabled,
// Load the tablets again to show that when refreshKnownTablets is disabled,
// only the list is read from the topo and the checksum doesn't change
tw.loadTablets()
if refreshKnownTablets {
Expand All @@ -167,7 +167,7 @@ func checkLegacyWatcher(t *testing.T, cellTablets, refreshKnownTablets bool) {
// same tablet, different port, should update (previous
// one should go away, new one be added)
//
// if RefreshKnownTablets is disabled, this case is *not*
// if refreshKnownTablets is disabled, this case is *not*
// detected and the tablet remains in the topo using the
// old key
origTablet := proto.Clone(tablet).(*topodatapb.Tablet)
Expand Down Expand Up @@ -209,7 +209,7 @@ func checkLegacyWatcher(t *testing.T, cellTablets, refreshKnownTablets bool) {
// trigger a ReplaceTablet in loadTablets because the uid does not
// match.
//
// This case *is* detected even if RefreshKnownTablets is false
// This case *is* detected even if refreshKnownTablets is false
// because the delete tablet / create tablet sequence causes the
// list of tablets to change and therefore the change is detected.
if err := ts.DeleteTablet(context.Background(), tablet2.Alias); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions go/vt/discovery/topology_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func checkWatcher(t *testing.T, refreshKnownTablets bool) {
}
tw.loadTablets()

// If RefreshKnownTablets is disabled, only the new tablet is read
// If refreshKnownTablets is disabled, only the new tablet is read
// from the topo
if refreshKnownTablets {
counts = checkOpCounts(t, counts, map[string]int64{"ListTablets": 1, "GetTablet": 2, "AddTablet": 1})
Expand All @@ -185,7 +185,7 @@ func checkWatcher(t *testing.T, refreshKnownTablets bool) {
t.Errorf("fhc.GetAllTablets() = %+v; want %+v", allTablets, tablet2)
}

// Load the tablets again to show that when RefreshKnownTablets is disabled,
// Load the tablets again to show that when refreshKnownTablets is disabled,
// only the list is read from the topo and the checksum doesn't change
tw.loadTablets()
if refreshKnownTablets {
Expand All @@ -198,7 +198,7 @@ func checkWatcher(t *testing.T, refreshKnownTablets bool) {
// same tablet, different port, should update (previous
// one should go away, new one be added)
//
// if RefreshKnownTablets is disabled, this case is *not*
// if refreshKnownTablets is disabled, this case is *not*
// detected and the tablet remains in the topo using the
// old key
origTablet := proto.Clone(tablet).(*topodatapb.Tablet)
Expand Down

0 comments on commit 87fe76d

Please sign in to comment.