diff --git a/cluster/router/healthcheck/default_health_check.go b/cluster/router/healthcheck/default_health_check.go index fc9879798e938f499507017d372168758aaeab2c..a26f86ddac45aa6e999cd4453aa296d0786a02ba 100644 --- a/cluster/router/healthcheck/default_health_check.go +++ b/cluster/router/healthcheck/default_health_check.go @@ -37,11 +37,11 @@ func init() { // DefaultHealthChecker is the default implementation of HealthChecker, which determines the health status of // the invoker based on the number of successive bad request and the current active request. type DefaultHealthChecker struct { - // outStandingRequestConutLimit + // the limit of outstanding request outStandingRequestConutLimit int32 - // requestSuccessiveFailureThreshold + // the threshold of successive-failure-request requestSuccessiveFailureThreshold int32 - // requestSuccessiveFailureThreshold + // value of circuit-tripped timeout factor circuitTrippedTimeoutFactor int32 } diff --git a/cluster/router/healthcheck/health_check_route.go b/cluster/router/healthcheck/health_check_route.go index 481a85acb0d353ae9767b0c8a2d40be61d094a52..1ddc9ccb173881a87bc5351711326f02ab2da3f6 100644 --- a/cluster/router/healthcheck/health_check_route.go +++ b/cluster/router/healthcheck/health_check_route.go @@ -39,9 +39,10 @@ type HealthCheckRouter struct { // NewHealthCheckRouter construct an HealthCheckRouter via url func NewHealthCheckRouter(url *common.URL) (router.Router, error) { - r := &HealthCheckRouter{} - r.url = url - r.enabled = url.GetParamBool(HEALTH_ROUTE_ENABLED_KEY, false) + r := &HealthCheckRouter{ + url: url, + enabled: url.GetParamBool(HEALTH_ROUTE_ENABLED_KEY, false), + } if r.enabled { checkerName := url.GetParam(constant.HEALTH_CHECKER, constant.DEFAULT_HEALTH_CHECKER) r.checker = extension.GetHealthChecker(checkerName, url) @@ -54,7 +55,7 @@ func (r *HealthCheckRouter) Route(invokers []protocol.Invoker, url *common.URL, if !r.enabled { return invokers } - var healthyInvokers []protocol.Invoker + healthyInvokers := make([]protocol.Invoker, 0, len(invokers)) // Add healthy invoker to the list for _, invoker := range invokers { if r.checker.IsHealthy(invoker) { @@ -65,9 +66,8 @@ func (r *HealthCheckRouter) Route(invokers []protocol.Invoker, url *common.URL, if len(healthyInvokers) == 0 { logger.Warnf(" Now all invokers are unhealthy, so downgraded to all! Service: [%s]", url.ServiceKey()) return invokers - } else { - return healthyInvokers } + return healthyInvokers } // Priority diff --git a/common/constant/key.go b/common/constant/key.go index 0ecd4f752e193588f0e3b18208e78825957a4066..c8a03b3be9f0179bb5317640d38abef8d9cc2b3a 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -193,13 +193,22 @@ const ( // HealthCheck Router const ( - HEALTH_CHECKER = "health.checker" - DEFAULT_HEALTH_CHECKER = "default" - OUTSTANDING_REQUEST_COUNT_LIMIT_KEY = "outstanding.request.limit" - SUCCESSIVE_FAILED_REQUEST_THRESHOLD_KEY = "successive.failed.threshold" - DEFAULT_SUCCESSIVE_FAILED_THRESHOLD = 5 - CIRCUIT_TRIPPED_TIMEOUT_FACTOR_KEY = "circuit.tripped.timeout.factor" + // The key of HealthCheck SPI + HEALTH_CHECKER = "health.checker" + // The name of the default implementation of HealthChecker + DEFAULT_HEALTH_CHECKER = "default" + // The key of oustanding-request-limit + OUTSTANDING_REQUEST_COUNT_LIMIT_KEY = "outstanding.request.limit" + // The key of successive-failed-request's threshold + SUCCESSIVE_FAILED_REQUEST_THRESHOLD_KEY = "successive.failed.threshold" + // The key of circuit-tripped timeout factor + CIRCUIT_TRIPPED_TIMEOUT_FACTOR_KEY = "circuit.tripped.timeout.factor" + // The default threshold of successive-failed-request if not specfied + DEFAULT_SUCCESSIVE_FAILED_THRESHOLD = 5 + // The default maximum diff between successive-failed-request's threshold and actual successive-failed-request's count DEFAULT_SUCCESSIVE_FAILED_REQUEST_MAX_DIFF = 5 - DEFAULT_CIRCUIT_TRIPPED_TIMEOUT_FACTOR = 1000 - MAX_CIRCUIT_TRIPPED_TIMEOUT_IN_MS = 30000 + // The default factor of circuit-tripped timeout if not specfied + DEFAULT_CIRCUIT_TRIPPED_TIMEOUT_FACTOR = 1000 + // The default time window of circuit-tripped in millisecond if not specfied + MAX_CIRCUIT_TRIPPED_TIMEOUT_IN_MS = 30000 )