use docker healthcheck result if possible

This commit is contained in:
yusing
2024-12-13 12:18:10 +08:00
parent b6c806a789
commit be81415a75
3 changed files with 73 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/rs/zerolog"
"github.com/yusing/go-proxy/internal/common"
"github.com/yusing/go-proxy/internal/docker"
"github.com/yusing/go-proxy/internal/docker/idlewatcher"
E "github.com/yusing/go-proxy/internal/error"
gphttp "github.com/yusing/go-proxy/internal/net/http"
@@ -92,7 +93,16 @@ func (r *HTTPRoute) Start(providerSubtask task.Task) E.Error {
r.handler = waker
r.HealthMon = waker
case entry.UseHealthCheck(r):
r.HealthMon = monitor.NewHTTPHealthMonitor(r.rp.TargetURL, r.HealthCheck)
if entry.IsDocker(r) {
client, err := docker.ConnectClient(r.Idlewatcher.DockerHost)
if err == nil {
fallback := monitor.NewHTTPHealthChecker(r.rp.TargetURL, r.HealthCheck)
r.HealthMon = monitor.NewDockerHealthMonitor(client, r.Idlewatcher.ContainerID, r.HealthCheck, fallback)
}
}
if r.HealthMon == nil {
r.HealthMon = monitor.NewHTTPHealthMonitor(r.rp.TargetURL, r.HealthCheck)
}
}
if r.handler == nil {