Skip to content

Commit

Permalink
style: introduce an enum for NodeFilter types
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanVergiliev committed Sep 19, 2022
1 parent 18d02fe commit 7d2615c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions internal/route/node_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (f *IsAtMaxHeightForGroup) Apply(_ *RequestMetadata, upstreamConfig *config
}

func CreateNodeFilter(
filterNames []string,
filterNames []NodeFilterType,
manager checks.HealthCheckManager,
store *metadata.ChainMetadataStore,
) NodeFilter {
Expand All @@ -79,19 +79,19 @@ func CreateNodeFilter(
}

func CreateSingleNodeFilter(
filterName string,
filterName NodeFilterType,
manager checks.HealthCheckManager,
store *metadata.ChainMetadataStore,
) NodeFilter {
switch filterName {
case "healthy":
case IsHealthy:
return &IsHealthyFilter{manager}
case "globalMaxHeight":
case GlobalMaxHeight:
return &IsAtGlobalMaxHeight{
healthCheckManager: manager,
chainMetadataStore: store,
}
case "maxHeightForGroup":
case MaxHeightForGroup:
return &IsAtMaxHeightForGroup{
healthCheckManager: manager,
chainMetadataStore: store,
Expand All @@ -100,3 +100,11 @@ func CreateSingleNodeFilter(
panic("Unknown filter type " + filterName + "!")
}
}

type NodeFilterType string

const (
IsHealthy NodeFilterType = "healthy"
GlobalMaxHeight = "globalMaxHeight"
MaxHeightForGroup = "maxHeightForGroup"
)
2 changes: 1 addition & 1 deletion internal/server/web_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func wireRouter(config conf.Config) route.Router {
ticker := time.NewTicker(checks.PeriodicHealthCheckInterval)
healthCheckManager := checks.NewHealthCheckManager(client.NewEthClient, config.Upstreams, chainMetadataStore, ticker)

nodeFilter := route.CreateNodeFilter([]string{"healthy", "maxHeightForGroup"}, healthCheckManager, chainMetadataStore)
nodeFilter := route.CreateNodeFilter([]route.NodeFilterType{route.IsHealthy, route.MaxHeightForGroup}, healthCheckManager, chainMetadataStore)
routingStrategy := route.FilteringRoutingStrategy{
NodeFilter: nodeFilter,
BackingStrategy: route.NewPriorityRoundRobinStrategy(),
Expand Down

0 comments on commit 7d2615c

Please sign in to comment.