Validator agent: retry outbound HTTPS up to 3 times, traceroute on failure

A failed HTTPS check is retried (3 attempts, 2 s apart). If all attempts
fail, the agent runs traceroute -4 -n to the target's IPv4 address in a
separate process, polls it every 5 s (90 s limit) and posts the full
output as a traceroute_result event for the address. The agent waits for
traces before reporting completion, while the floating IP is attached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Opus 5.5 committed 2026-11-02 22:45:21 +03:00
1 parent 1536723196
commit 5c75ece8b1
15 files changed
+480 -25

No files matched your search

+46 -1
View File
@@ -19,6 +19,7 @@ import (
neturl "net/url"
"os"
"strings"
"sync"
"sync/atomic"
"time"
@@ -402,12 +403,16 @@ func fetchIPEcho(ctx context.Context, url string) (string, error) {
func (a *Agent) runChecks(ctx context.Context, assignment assignmentResp) {
var results []checkResultDTO
var traces sync.WaitGroup
for _, ct := range assignment.CheckConfig {
for _, target := range ct.Targets {
var fn func(context.Context) checkrunner.Result
switch ct.Type {
case "https":
fn = checkrunner.HTTPS(target, time.Duration(a.cfg.Checks.HTTPSTimeoutSeconds)*time.Second)
fn = checkrunner.HTTPSWithRetry(target,
time.Duration(a.cfg.Checks.HTTPSTimeoutSeconds)*time.Second,
a.cfg.Checks.HTTPSAttempts,
time.Duration(a.cfg.Checks.HTTPSRetryDelaySeconds)*time.Second)
case "icmp":
fn = checkrunner.ICMPEcho(hostOnly(target), a.cfg.Checks.ICMPCount, time.Duration(a.cfg.Checks.ICMPTimeoutSeconds)*time.Second)
case "ssh":
@@ -435,13 +440,53 @@ func (a *Agent) runChecks(ctx context.Context, assignment assignmentResp) {
// Report progressively rather than batching until the end, so
// a crash mid-run doesn't lose already-completed check results.
a.postResults(ctx, []checkResultDTO{results[len(results)-1]})
if ct.Type == "https" && !res.Success && a.cfg.Checks.Traceroute.IsEnabled() {
traces.Add(1)
go func(target string) {
defer traces.Done()
a.runTraceroute(ctx, assignment.IPID, target)
}(target)
}
}
}
// Wait for traces before complete: after complete the control-api
// detaches the floating IP and the trace would leave from another address.
traces.Wait()
a.postComplete(ctx, assignment.IPID)
a.lastHandledIPID = assignment.IPID
}
// runTraceroute traces the route to target's host and posts the outcome as a
// traceroute_result event. It never affects the verdict.
func (a *Agent) runTraceroute(ctx context.Context, ipID int64, target string) {
tc := a.cfg.Checks.Traceroute
a.log.Info("traceroute start", "target", target)
r := <-checkrunner.StartTraceroute(ctx, target, checkrunner.TraceConfig{
Timeout: time.Duration(tc.TimeoutSeconds) * time.Second,
MaxHops: tc.MaxHops,
PollInterval: time.Duration(tc.PollIntervalSeconds) * time.Second,
})
a.log.Info("traceroute finish", "target", target, "ip", r.IP, "status", r.Status, "duration_ms", r.DurationMS)
payload, err := json.Marshal(struct {
Target string `json:"target"`
Host string `json:"host"`
IP string `json:"ip"`
Status string `json:"status"`
DurationMS int64 `json:"duration_ms"`
Output string `json:"output"`
Error string `json:"error,omitempty"`
}{r.Target, r.Host, r.IP, r.Status, r.DurationMS, r.Output, r.Error})
if err != nil {
a.log.Error("marshal traceroute event", "err", err)
return
}
a.postEvent(ctx, ipID, "traceroute_result", string(payload))
}
type checkResultDTO struct {
IPID int64 `json:"ip_id"`
CheckType string `json:"check_type"`