incorporate changes in router implementation

This commit is contained in:
Shelikhoo
2021-09-04 11:12:32 +01:00
parent 24a5e34ce0
commit ea5bb04acf
16 changed files with 421 additions and 985 deletions
+10
View File
@@ -0,0 +1,10 @@
package routing
type BalancerOverrider interface {
SetOverrideTarget(tag, target string) error
GetOverrideTarget(tag string) (string, error)
}
type BalancerPrincipleTarget interface {
GetPrincipleTarget(tag string) ([]string, error)
}
-51
View File
@@ -1,51 +0,0 @@
package routing
import "time"
// HealthChecker is the interface for health checkers
type HealthChecker interface {
// StartScheduler starts the check scheduler
StartScheduler(selector func() ([]string, error))
// StopScheduler stops the check scheduler
StopScheduler()
// Check start the health checking for given tags.
Check(tags []string) error
}
// OutboundInfo holds information of an outbound
type OutboundInfo struct {
Tag string // Tag of the outbound
Values []string // Information of the outbound, which can be different between strategies, like health ping RTT
}
// StrategyInfo holds strategy running information, like selected handlers and others
type StrategyInfo struct {
Settings []string // Strategy settings
ValueTitles []string // Value titles of OutboundInfo.Values
Selects []*OutboundInfo // Selects of the strategy
Others []*OutboundInfo // Other outbounds
}
// BalancingOverrideInfo holds balancing override information
type BalancingOverrideInfo struct {
Until time.Time
Selects []string
}
// BalancerInfo holds information of a balancer
type BalancerInfo struct {
Tag string // Tag of the balancer
Override *BalancingOverrideInfo
Strategy *StrategyInfo // Strategy and its running information
}
// RouterChecker represents a router that is able to perform checks for its balancers, and get statistics.
type RouterChecker interface {
// CheckHanlders performs a health check for specified outbound hanlders.
CheckHanlders(tags []string) error
// CheckBalancers performs health checks for specified balancers,
// if not specified, check them all.
CheckBalancers(tags []string) error
// GetBalancersInfo get health info of specific balancer, if balancer not specified, get all
GetBalancersInfo(tags []string) ([]*BalancerInfo, error)
}
-22
View File
@@ -1,22 +0,0 @@
package routing
import "time"
// BalancingStrategy is the interface for balancing strategies
type BalancingStrategy interface {
// Pick pick one outbound from candidates. Unlike the SelectAndPick(),
// it skips the select procedure (select all & pick one).
Pick(candidates []string) string
// SelectAndPick selects qualified nodes from candidates then pick one.
SelectAndPick(candidates []string) string
// GetInformation gets information of the strategy
GetInformation(tags []string) *StrategyInfo
}
// BalancingOverrider is the interface of those who can override
// the selecting of its balancers
type BalancingOverrider interface {
// OverrideSelecting overrides the selects of specified balancer, for 'validity'
// duration of time.
OverrideSelecting(balancer string, selects []string, validity time.Duration) error
}