mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 01:38:50 +02:00
fix(health_monitor): fix UpdateURL behavior in Docker and AgentProxied health monitor
This commit is contained in:
@@ -5,12 +5,13 @@ import (
|
|||||||
|
|
||||||
agentPkg "github.com/yusing/godoxy/agent/pkg/agent"
|
agentPkg "github.com/yusing/godoxy/agent/pkg/agent"
|
||||||
"github.com/yusing/godoxy/internal/types"
|
"github.com/yusing/godoxy/internal/types"
|
||||||
|
"github.com/yusing/goutils/synk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
AgentProxiedMonitor struct {
|
AgentProxiedMonitor struct {
|
||||||
agent *agentPkg.AgentConfig
|
agent *agentPkg.AgentConfig
|
||||||
query string
|
query synk.Value[string]
|
||||||
*monitor
|
*monitor
|
||||||
}
|
}
|
||||||
AgentCheckHealthTarget struct {
|
AgentCheckHealthTarget struct {
|
||||||
@@ -47,14 +48,14 @@ func (target *AgentCheckHealthTarget) displayURL() *url.URL {
|
|||||||
func NewAgentProxiedMonitor(agent *agentPkg.AgentConfig, config *types.HealthCheckConfig, target *AgentCheckHealthTarget) *AgentProxiedMonitor {
|
func NewAgentProxiedMonitor(agent *agentPkg.AgentConfig, config *types.HealthCheckConfig, target *AgentCheckHealthTarget) *AgentProxiedMonitor {
|
||||||
mon := &AgentProxiedMonitor{
|
mon := &AgentProxiedMonitor{
|
||||||
agent: agent,
|
agent: agent,
|
||||||
query: target.buildQuery(),
|
|
||||||
}
|
}
|
||||||
mon.monitor = newMonitor(target.displayURL(), config, mon.CheckHealth)
|
mon.monitor = newMonitor(target.displayURL(), config, mon.CheckHealth)
|
||||||
|
mon.query.Store(target.buildQuery())
|
||||||
return mon
|
return mon
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mon *AgentProxiedMonitor) CheckHealth() (types.HealthCheckResult, error) {
|
func (mon *AgentProxiedMonitor) CheckHealth() (types.HealthCheckResult, error) {
|
||||||
resp, err := mon.agent.DoHealthCheck(mon.config.Timeout, mon.query)
|
resp, err := mon.agent.DoHealthCheck(mon.config.Timeout, mon.query.Load())
|
||||||
result := types.HealthCheckResult{
|
result := types.HealthCheckResult{
|
||||||
Healthy: resp.Healthy,
|
Healthy: resp.Healthy,
|
||||||
Detail: resp.Detail,
|
Detail: resp.Detail,
|
||||||
@@ -62,3 +63,9 @@ func (mon *AgentProxiedMonitor) CheckHealth() (types.HealthCheckResult, error) {
|
|||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mon *AgentProxiedMonitor) UpdateURL(url *url.URL) {
|
||||||
|
mon.monitor.UpdateURL(url)
|
||||||
|
newTarget := AgentTargetFromURL(url)
|
||||||
|
mon.query.Store(newTarget.buildQuery())
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package monitor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/bytedance/sonic"
|
"github.com/bytedance/sonic"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
@@ -49,6 +50,13 @@ func (mon *DockerHealthMonitor) Start(parent task.Parent) gperr.Error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mon *DockerHealthMonitor) UpdateURL(url *url.URL) {
|
||||||
|
mon.monitor.UpdateURL(url)
|
||||||
|
if mon.fallback != nil {
|
||||||
|
mon.fallback.UpdateURL(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (mon *DockerHealthMonitor) interceptInspectResponse(resp *http.Response) (intercepted bool, err error) {
|
func (mon *DockerHealthMonitor) interceptInspectResponse(resp *http.Response) (intercepted bool, err error) {
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|||||||
@@ -186,6 +186,10 @@ func (mon *monitor) Finish(reason any) {
|
|||||||
|
|
||||||
// UpdateURL implements HealthChecker.
|
// UpdateURL implements HealthChecker.
|
||||||
func (mon *monitor) UpdateURL(url *url.URL) {
|
func (mon *monitor) UpdateURL(url *url.URL) {
|
||||||
|
if url == nil {
|
||||||
|
log.Warn().Msg("attempting to update health monitor URL with nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
mon.url.Store(url)
|
mon.url.Store(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user