mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 08:48:32 +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:
@@ -9,6 +9,7 @@ import (
|
||||
gphttp "github.com/yusing/godoxy/internal/net/gphttp"
|
||||
"github.com/yusing/godoxy/internal/net/gphttp/middleware"
|
||||
"github.com/yusing/godoxy/internal/route/routes"
|
||||
"github.com/yusing/godoxy/internal/types"
|
||||
"github.com/yusing/godoxy/internal/watcher/health/monitor"
|
||||
gperr "github.com/yusing/goutils/errs"
|
||||
"github.com/yusing/goutils/task"
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/yusing/godoxy/agent/pkg/agent"
|
||||
config "github.com/yusing/godoxy/internal/config/types"
|
||||
"github.com/yusing/godoxy/internal/docker"
|
||||
"github.com/yusing/godoxy/internal/homepage"
|
||||
homepagecfg "github.com/yusing/godoxy/internal/homepage/types"
|
||||
@@ -49,7 +50,7 @@ type (
|
||||
PathPatterns []string `json:"path_patterns,omitempty" extensions:"x-nullable"`
|
||||
Rules rules.Rules `json:"rules,omitempty" extension:"x-nullable"`
|
||||
RuleFile string `json:"rule_file,omitempty" extensions:"x-nullable"`
|
||||
HealthCheck *types.HealthCheckConfig `json:"healthcheck,omitempty" extensions:"x-nullable"` // null on load-balancer routes
|
||||
HealthCheck types.HealthCheckConfig `json:"healthcheck,omitempty" extensions:"x-nullable"` // null on load-balancer routes
|
||||
LoadBalance *types.LoadBalancerConfig `json:"load_balance,omitempty" extensions:"x-nullable"`
|
||||
Middlewares map[string]types.LabelMap `json:"middlewares,omitempty" extensions:"x-nullable"`
|
||||
Homepage *homepage.ItemConfig `json:"homepage"`
|
||||
@@ -497,7 +498,7 @@ func (r *Route) IdlewatcherConfig() *types.IdlewatcherConfig {
|
||||
return r.Idlewatcher
|
||||
}
|
||||
|
||||
func (r *Route) HealthCheckConfig() *types.HealthCheckConfig {
|
||||
func (r *Route) HealthCheckConfig() types.HealthCheckConfig {
|
||||
return r.HealthCheck
|
||||
}
|
||||
|
||||
@@ -771,17 +772,7 @@ func (r *Route) Finalize() {
|
||||
}
|
||||
|
||||
r.Port.Listening, r.Port.Proxy = lp, pp
|
||||
|
||||
if r.HealthCheck == nil {
|
||||
r.HealthCheck = types.DefaultHealthConfig()
|
||||
}
|
||||
|
||||
if r.HealthCheck.Interval == 0 {
|
||||
r.HealthCheck.Interval = common.HealthCheckIntervalDefault
|
||||
}
|
||||
if r.HealthCheck.Timeout == 0 {
|
||||
r.HealthCheck.Timeout = common.HealthCheckTimeoutDefault
|
||||
}
|
||||
r.HealthCheck.ApplyDefaults(config.ActiveConfig.Load().Defaults.HealthCheck)
|
||||
}
|
||||
|
||||
func (r *Route) FinalizeHomepageConfig() {
|
||||
@@ -794,7 +785,6 @@ func (r *Route) FinalizeHomepageConfig() {
|
||||
if r.Homepage == nil {
|
||||
r.Homepage = &homepage.ItemConfig{
|
||||
Show: true,
|
||||
Name: r.Alias,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package route
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yusing/godoxy/internal/common"
|
||||
route "github.com/yusing/godoxy/internal/route/types"
|
||||
@@ -40,7 +41,7 @@ func TestRouteValidate(t *testing.T) {
|
||||
Scheme: route.SchemeHTTP,
|
||||
Host: "example.com",
|
||||
Port: route.Port{Proxy: 80},
|
||||
HealthCheck: &types.HealthCheckConfig{
|
||||
HealthCheck: types.HealthCheckConfig{
|
||||
Disable: true,
|
||||
},
|
||||
LoadBalance: &types.LoadBalancerConfig{
|
||||
@@ -179,3 +180,14 @@ func TestRouteAgent(t *testing.T) {
|
||||
expect.NoError(t, err, "Validate should not return error for valid route with agent")
|
||||
expect.NotNil(t, r.GetAgent(), "GetAgent should return agent")
|
||||
}
|
||||
|
||||
func TestRouteApplyingHealthCheckDefaults(t *testing.T) {
|
||||
hc := types.HealthCheckConfig{}
|
||||
hc.ApplyDefaults(types.HealthCheckConfig{
|
||||
Interval: 15 * time.Second,
|
||||
Timeout: 10 * time.Second,
|
||||
})
|
||||
|
||||
expect.Equal(t, hc.Interval, 15*time.Second)
|
||||
expect.Equal(t, hc.Timeout, 10*time.Second)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user