mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-03 13:44:25 +02:00
fix(agent): use godoxy-to-agent latency for health check
This commit is contained in:
parent
e62e667b49
commit
6f9bb410f5
1 changed files with 7 additions and 0 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
agentPkg "github.com/yusing/go-proxy/agent/pkg/agent"
|
agentPkg "github.com/yusing/go-proxy/agent/pkg/agent"
|
||||||
"github.com/yusing/go-proxy/internal/watcher/health"
|
"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) {
|
func (mon *AgentProxiedMonitor) CheckHealth() (result *health.HealthCheckResult, err error) {
|
||||||
|
startTime := time.Now()
|
||||||
result = new(health.HealthCheckResult)
|
result = new(health.HealthCheckResult)
|
||||||
ctx, cancel := mon.ContextWithTimeout("timeout querying agent")
|
ctx, cancel := mon.ContextWithTimeout("timeout querying agent")
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -64,11 +66,16 @@ func (mon *AgentProxiedMonitor) CheckHealth() (result *health.HealthCheckResult,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
endTime := time.Now()
|
||||||
switch status {
|
switch status {
|
||||||
case http.StatusOK:
|
case http.StatusOK:
|
||||||
err = json.Unmarshal(data, result)
|
err = json.Unmarshal(data, result)
|
||||||
default:
|
default:
|
||||||
err = errors.New(string(data))
|
err = errors.New(string(data))
|
||||||
}
|
}
|
||||||
|
if err == nil && result.Latency != 0 {
|
||||||
|
// use godoxy to agent latency
|
||||||
|
result.Latency = endTime.Sub(startTime)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue