// Copyright (c) 2026, Pim van Pelt package prober import ( "context" "fmt" "net" "time" "git.ipng.ch/ipng/vpp-maglev/internal/config" "git.ipng.ch/ipng/vpp-maglev/internal/health" ) // ProbeFunc is the signature for a health check probe. type ProbeFunc func(ctx context.Context, cfg ProbeConfig) health.ProbeResult // ProbeConfig holds all parameters needed to execute a single probe. type ProbeConfig struct { Target net.IP // backend address to probe Port uint16 // destination port (used by TCP and HTTP probers) ProbeSrc net.IP // source address to bind; nil lets the OS choose HealthCheckNetns string // network namespace name; sockets are created inside it Timeout time.Duration HTTP *config.HTTPParams // non-nil for type http/https TCP *config.TCPParams // non-nil for type tcp } // ForType returns the ProbeFunc registered for the given healthcheck type. // Returns a failing stub for unknown types. func ForType(t string) ProbeFunc { switch t { case "icmp": return ICMPProbe case "tcp": return TCPProbe case "http": return HTTPProbe case "https": return HTTPSProbe default: return func(_ context.Context, _ ProbeConfig) health.ProbeResult { return health.ProbeResult{ OK: false, Layer: health.LayerUnknown, Code: "UNKNOWN", Detail: fmt.Sprintf("unknown probe type %q", t), } } } }