mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-20 07:21:26 +02:00
refactor(healthcheck): streamline health check configuration and defaults
- Moved health check constants from common package alongside type definition. - Updated health check configuration to use struct directly instead of pointers. - Introduced global default health check config
This commit is contained in:
@@ -3,25 +3,39 @@ package types
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/yusing/godoxy/internal/common"
|
||||
)
|
||||
|
||||
type HealthCheckConfig struct {
|
||||
Disable bool `json:"disable,omitempty" aliases:"disabled"`
|
||||
Path string `json:"path,omitempty" validate:"omitempty,uri,startswith=/"`
|
||||
UseGet bool `json:"use_get,omitempty"`
|
||||
Path string `json:"path,omitempty" validate:"omitempty,uri,startswith=/"`
|
||||
Interval time.Duration `json:"interval" validate:"omitempty,min=1s" swaggertype:"primitive,integer"`
|
||||
Timeout time.Duration `json:"timeout" validate:"omitempty,min=1s" swaggertype:"primitive,integer"`
|
||||
Retries int64 `json:"retries"` // <0: immediate, >=0: threshold
|
||||
Retries int64 `json:"retries"` // <0: immediate, 0: default, >0: threshold
|
||||
|
||||
BaseContext func() context.Context `json:"-"`
|
||||
} // @name HealthCheckConfig
|
||||
|
||||
func DefaultHealthConfig() *HealthCheckConfig {
|
||||
return &HealthCheckConfig{
|
||||
Interval: common.HealthCheckIntervalDefault,
|
||||
Timeout: common.HealthCheckTimeoutDefault,
|
||||
Retries: int64(common.HealthCheckDownNotifyDelayDefault / common.HealthCheckIntervalDefault),
|
||||
const (
|
||||
HealthCheckIntervalDefault = 5 * time.Second
|
||||
HealthCheckTimeoutDefault = 5 * time.Second
|
||||
HealthCheckDownNotifyDelayDefault = 15 * time.Second
|
||||
)
|
||||
|
||||
func (hc *HealthCheckConfig) ApplyDefaults(defaults HealthCheckConfig) {
|
||||
if hc.Interval == 0 {
|
||||
hc.Interval = defaults.Interval
|
||||
if hc.Interval == 0 {
|
||||
hc.Interval = HealthCheckIntervalDefault
|
||||
}
|
||||
}
|
||||
if hc.Timeout == 0 {
|
||||
hc.Timeout = defaults.Timeout
|
||||
if hc.Timeout == 0 {
|
||||
hc.Timeout = HealthCheckTimeoutDefault
|
||||
}
|
||||
}
|
||||
if hc.Retries == 0 {
|
||||
hc.Retries = int64(HealthCheckDownNotifyDelayDefault / hc.Interval)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ type (
|
||||
Started() <-chan struct{}
|
||||
|
||||
IdlewatcherConfig() *IdlewatcherConfig
|
||||
HealthCheckConfig() *HealthCheckConfig
|
||||
HealthCheckConfig() HealthCheckConfig
|
||||
LoadBalanceConfig() *LoadBalancerConfig
|
||||
HomepageItem() homepage.Item
|
||||
DisplayName() string
|
||||
|
||||
Reference in New Issue
Block a user