mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-20 15:31:24 +02:00
fix: prevent panicking on misconfigurations
This commit is contained in:
@@ -179,13 +179,13 @@ func (r *ReveseProxyRoute) addToLoadBalancer(parent task.Parent) {
|
|||||||
_ = lb.Start(parent) // always return nil
|
_ = lb.Start(parent) // always return nil
|
||||||
linked = &ReveseProxyRoute{
|
linked = &ReveseProxyRoute{
|
||||||
Route: &Route{
|
Route: &Route{
|
||||||
Alias: cfg.Link,
|
Alias: cfg.Link,
|
||||||
Homepage: r.Homepage,
|
Homepage: r.Homepage,
|
||||||
HealthMon: lb,
|
|
||||||
},
|
},
|
||||||
loadBalancer: lb,
|
loadBalancer: lb,
|
||||||
handler: lb,
|
handler: lb,
|
||||||
}
|
}
|
||||||
|
linked.SetHealthMonitor(lb)
|
||||||
routes.HTTP.AddKey(cfg.Link, linked)
|
routes.HTTP.AddKey(cfg.Link, linked)
|
||||||
routes.All.AddKey(cfg.Link, linked)
|
routes.All.AddKey(cfg.Link, linked)
|
||||||
r.task.OnFinished("remove_loadbalancer_route", func() {
|
r.task.OnFinished("remove_loadbalancer_route", func() {
|
||||||
|
|||||||
@@ -51,9 +51,6 @@ type (
|
|||||||
Agent string `json:"agent,omitempty"`
|
Agent string `json:"agent,omitempty"`
|
||||||
|
|
||||||
Idlewatcher *types.IdlewatcherConfig `json:"idlewatcher,omitempty" extensions:"x-nullable"`
|
Idlewatcher *types.IdlewatcherConfig `json:"idlewatcher,omitempty" extensions:"x-nullable"`
|
||||||
HealthMon types.HealthMonitor `json:"health,omitempty" swaggerignore:"true"`
|
|
||||||
// for swagger
|
|
||||||
HealthJSON *types.HealthJSON `json:",omitempty" form:"health"`
|
|
||||||
|
|
||||||
Metadata `deserialize:"-"`
|
Metadata `deserialize:"-"`
|
||||||
}
|
}
|
||||||
@@ -70,6 +67,10 @@ type (
|
|||||||
|
|
||||||
Excluded *bool `json:"excluded"`
|
Excluded *bool `json:"excluded"`
|
||||||
|
|
||||||
|
HealthMon types.HealthMonitor `json:"health,omitempty" swaggerignore:"true"`
|
||||||
|
// for swagger
|
||||||
|
HealthJSON *types.HealthJSON `json:",omitempty" form:"health"`
|
||||||
|
|
||||||
impl types.Route
|
impl types.Route
|
||||||
task *task.Task
|
task *task.Task
|
||||||
|
|
||||||
@@ -466,7 +467,7 @@ func (r *Route) UseLoadBalance() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Route) UseIdleWatcher() bool {
|
func (r *Route) UseIdleWatcher() bool {
|
||||||
return r.Idlewatcher != nil && r.Idlewatcher.IdleTimeout > 0
|
return r.Idlewatcher != nil && r.Idlewatcher.IdleTimeout > 0 && r.Idlewatcher.ValErr() == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Route) UseHealthCheck() bool {
|
func (r *Route) UseHealthCheck() bool {
|
||||||
@@ -582,13 +583,11 @@ func (r *Route) Finalize() {
|
|||||||
r.HealthCheck = types.DefaultHealthConfig()
|
r.HealthCheck = types.DefaultHealthConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !r.HealthCheck.Disable {
|
if r.HealthCheck.Interval == 0 {
|
||||||
if r.HealthCheck.Interval == 0 {
|
r.HealthCheck.Interval = common.HealthCheckIntervalDefault
|
||||||
r.HealthCheck.Interval = common.HealthCheckIntervalDefault
|
}
|
||||||
}
|
if r.HealthCheck.Timeout == 0 {
|
||||||
if r.HealthCheck.Timeout == 0 {
|
r.HealthCheck.Timeout = common.HealthCheckTimeoutDefault
|
||||||
r.HealthCheck.Timeout = common.HealthCheckTimeoutDefault
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ type (
|
|||||||
|
|
||||||
StartEndpoint string `json:"start_endpoint,omitempty"` // Optional path that must be hit to start container
|
StartEndpoint string `json:"start_endpoint,omitempty"` // Optional path that must be hit to start container
|
||||||
DependsOn []string `json:"depends_on,omitempty"`
|
DependsOn []string `json:"depends_on,omitempty"`
|
||||||
|
|
||||||
|
valErr gperr.Error
|
||||||
} // @name IdlewatcherConfig
|
} // @name IdlewatcherConfig
|
||||||
ContainerStopMethod string // @name ContainerStopMethod
|
ContainerStopMethod string // @name ContainerStopMethod
|
||||||
ContainerSignal string // @name ContainerSignal
|
ContainerSignal string // @name ContainerSignal
|
||||||
@@ -70,9 +72,10 @@ func (c *IdlewatcherConfig) ContainerName() string {
|
|||||||
|
|
||||||
func (c *IdlewatcherConfig) Validate() gperr.Error {
|
func (c *IdlewatcherConfig) Validate() gperr.Error {
|
||||||
if c.IdleTimeout == 0 { // zero idle timeout means no idle watcher
|
if c.IdleTimeout == 0 { // zero idle timeout means no idle watcher
|
||||||
|
c.valErr = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
errs := gperr.NewBuilder("idlewatcher config validation error")
|
errs := gperr.NewBuilder()
|
||||||
errs.AddRange(
|
errs.AddRange(
|
||||||
c.validateProvider(),
|
c.validateProvider(),
|
||||||
c.validateTimeouts(),
|
c.validateTimeouts(),
|
||||||
@@ -80,7 +83,12 @@ func (c *IdlewatcherConfig) Validate() gperr.Error {
|
|||||||
c.validateStopSignal(),
|
c.validateStopSignal(),
|
||||||
c.validateStartEndpoint(),
|
c.validateStartEndpoint(),
|
||||||
)
|
)
|
||||||
return errs.Error()
|
c.valErr = errs.Error()
|
||||||
|
return c.valErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *IdlewatcherConfig) ValErr() gperr.Error {
|
||||||
|
return c.valErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *IdlewatcherConfig) validateProvider() error {
|
func (c *IdlewatcherConfig) validateProvider() error {
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ func NewMonitor(r types.Route) types.HealthMonCheck {
|
|||||||
|
|
||||||
func newMonitor(u *url.URL, config *types.HealthCheckConfig, healthCheckFunc HealthCheckFunc) *monitor {
|
func newMonitor(u *url.URL, config *types.HealthCheckConfig, healthCheckFunc HealthCheckFunc) *monitor {
|
||||||
if config.Retries == 0 {
|
if config.Retries == 0 {
|
||||||
|
if config.Interval == 0 {
|
||||||
|
config.Interval = common.HealthCheckIntervalDefault
|
||||||
|
}
|
||||||
config.Retries = int64(common.HealthCheckDownNotifyDelayDefault / config.Interval)
|
config.Retries = int64(common.HealthCheckDownNotifyDelayDefault / config.Interval)
|
||||||
}
|
}
|
||||||
mon := &monitor{
|
mon := &monitor{
|
||||||
|
|||||||
Reference in New Issue
Block a user