From 6f9bb410f5d4e417dea63924ea1870adc2f5b7be Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 31 May 2025 07:39:01 +0800 Subject: [PATCH] fix(agent): use godoxy-to-agent latency for health check --- internal/watcher/health/monitor/agent_proxied.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/watcher/health/monitor/agent_proxied.go b/internal/watcher/health/monitor/agent_proxied.go index 67db85c..d28fbcb 100644 --- a/internal/watcher/health/monitor/agent_proxied.go +++ b/internal/watcher/health/monitor/agent_proxied.go @@ -5,6 +5,7 @@ import ( "errors" "net/http" "net/url" + "time" agentPkg "github.com/yusing/go-proxy/agent/pkg/agent" "github.com/yusing/go-proxy/internal/watcher/health" @@ -57,6 +58,7 @@ func NewAgentProxiedMonitor(agent *agentPkg.AgentConfig, config *health.HealthCh } func (mon *AgentProxiedMonitor) CheckHealth() (result *health.HealthCheckResult, err error) { + startTime := time.Now() result = new(health.HealthCheckResult) ctx, cancel := mon.ContextWithTimeout("timeout querying agent") defer cancel() @@ -64,11 +66,16 @@ func (mon *AgentProxiedMonitor) CheckHealth() (result *health.HealthCheckResult, if err != nil { return result, err } + endTime := time.Now() switch status { case http.StatusOK: err = json.Unmarshal(data, result) default: err = errors.New(string(data)) } + if err == nil && result.Latency != 0 { + // use godoxy to agent latency + result.Latency = endTime.Sub(startTime) + } return }