mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-21 00:29:03 +01: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"
|
||||
"github.com/yusing/godoxy/internal/types"
|
||||
"github.com/yusing/goutils/synk"
|
||||
)
|
||||
|
||||
type (
|
||||
AgentProxiedMonitor struct {
|
||||
agent *agentPkg.AgentConfig
|
||||
query string
|
||||
query synk.Value[string]
|
||||
*monitor
|
||||
}
|
||||
AgentCheckHealthTarget struct {
|
||||
@@ -47,14 +48,14 @@ func (target *AgentCheckHealthTarget) displayURL() *url.URL {
|
||||
func NewAgentProxiedMonitor(agent *agentPkg.AgentConfig, config *types.HealthCheckConfig, target *AgentCheckHealthTarget) *AgentProxiedMonitor {
|
||||
mon := &AgentProxiedMonitor{
|
||||
agent: agent,
|
||||
query: target.buildQuery(),
|
||||
}
|
||||
mon.monitor = newMonitor(target.displayURL(), config, mon.CheckHealth)
|
||||
mon.query.Store(target.buildQuery())
|
||||
return mon
|
||||
}
|
||||
|
||||
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{
|
||||
Healthy: resp.Healthy,
|
||||
Detail: resp.Detail,
|
||||
@@ -62,3 +63,9 @@ func (mon *AgentProxiedMonitor) CheckHealth() (types.HealthCheckResult, error) {
|
||||
}
|
||||
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 (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
@@ -49,6 +50,13 @@ func (mon *DockerHealthMonitor) Start(parent task.Parent) gperr.Error {
|
||||
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) {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return false, nil
|
||||
|
||||
@@ -186,6 +186,10 @@ func (mon *monitor) Finish(reason any) {
|
||||
|
||||
// UpdateURL implements HealthChecker.
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user