diff --git a/prober/derp.go b/prober/derp.go index 01a7d3086..02cfb0043 100644 --- a/prober/derp.go +++ b/prober/derp.go @@ -157,7 +157,7 @@ func DERP(p *Prober, derpMapURL string, opts ...DERPOpt) (*derpProber, error) { } d.ProbeMap = ProbeClass{ Probe: d.probeMapFn, - Class: "derp_map", + Class: ClassDERPMap, } for _, o := range opts { o(d) @@ -286,7 +286,7 @@ func (d *derpProber) probeMesh(from, to string) ProbeClass { dm := d.lastDERPMap return derpProbeNodePair(ctx, dm, fromN, toN) }, - Class: "derp_mesh", + Class: ClassDERPMesh, Labels: Labels{"derp_path": derpPath}, } } @@ -310,7 +310,7 @@ func (d *derpProber) probeBandwidth(from, to string, size int64) ProbeClass { } return derpProbeBandwidth(ctx, d.lastDERPMap, fromN, toN, size, &transferTimeSeconds, &totalBytesTransferred, d.bwTUNIPv4Prefix) }, - Class: "derp_bw", + Class: ClassBandwidth, Labels: Labels{ "derp_path": derpPath, "tcp_in_tcp": strconv.FormatBool(d.bwTUNIPv4Prefix != nil), @@ -351,7 +351,7 @@ func (d *derpProber) probeQueuingDelay(from, to string, packetsPerSecond int, pa } return derpProbeQueuingDelay(ctx, d.lastDERPMap, fromN, toN, packetsPerSecond, packetTimeout, &packetsDropped, qdh) }, - Class: "derp_qd", + Class: ClassQueueDepth, Labels: Labels{"derp_path": derpPath}, Metrics: func(l prometheus.Labels) []prometheus.Metric { qdh.mx.Lock() @@ -600,7 +600,7 @@ func (d *derpProber) ProbeUDP(ipaddr string, port int) ProbeClass { Probe: func(ctx context.Context) error { return derpProbeUDP(ctx, ipaddr, port) }, - Class: "derp_udp", + Class: ClassDERPUDP, } } diff --git a/prober/prober.go b/prober/prober.go index d80db773a..5d8c1fc6b 100644 --- a/prober/prober.go +++ b/prober/prober.go @@ -17,6 +17,7 @@ import ( "maps" "math/rand" "net/http" + "strings" "sync" "time" @@ -29,6 +30,17 @@ import ( // in memory. const recentHistSize = 10 +type ClassType string + +var ( + ClassDERPUDP ClassType = "derp_udp" + ClassDERPMesh ClassType = "derp_mesh" + ClassDERPMap ClassType = "derp_map" + ClassTLS ClassType = "tls" + ClassQueueDepth ClassType = "derp_qd" + ClassBandwidth ClassType = "derp_bw" +) + // ProbeClass defines a probe of a specific type: a probing function that will // be regularly ran, and metric labels that will be added automatically to all // probes using this class. @@ -40,7 +52,7 @@ type ProbeClass struct { // Class defines a user-facing name of the probe class that will be used // in the `class` metric label. - Class string + Class ClassType // Labels defines a set of metric labels that will be added to all metrics // exposed by this probe class. @@ -117,7 +129,14 @@ func (p *Prober) Run(name string, interval time.Duration, labels Labels, pc Prob l := prometheus.Labels{ "name": name, - "class": pc.Class, + "class": string(pc.Class), + } + if pc.Class == ClassDERPUDP { + if strings.Contains(name, "udp6") { + l["af"] = "udp6" + } else { + l["af"] = "udp" + } } for k, v := range pc.Labels { l[k] = v @@ -404,10 +423,14 @@ func (p *Probe) recordEndLocked(err error) { p.mSeconds.WithLabelValues("ok").Add(latency.Seconds()) p.latencyHist.Value = latency p.latencyHist = p.latencyHist.Next() + p.mAttempts.WithLabelValues("fail").Add(0) + p.mSeconds.WithLabelValues("fail").Add(0) } else { p.latency = 0 p.mAttempts.WithLabelValues("fail").Inc() p.mSeconds.WithLabelValues("fail").Add(latency.Seconds()) + p.mAttempts.WithLabelValues("ok").Add(0) + p.mSeconds.WithLabelValues("ok").Add(0) } p.successHist.Value = p.succeeded p.successHist = p.successHist.Next() @@ -486,7 +509,7 @@ func (p *Prober) ProbeInfo() map[string]ProbeInfo { func (probe *Probe) probeInfoLocked() ProbeInfo { inf := ProbeInfo{ Name: probe.name, - Class: probe.probeClass.Class, + Class: string(probe.probeClass.Class), Interval: probe.interval, Labels: probe.metricLabels, Start: probe.start, diff --git a/prober/tls.go b/prober/tls.go index 787df05c2..6c90c23cb 100644 --- a/prober/tls.go +++ b/prober/tls.go @@ -36,7 +36,7 @@ func TLS(hostPort string) ProbeClass { } return probeTLS(ctx, certDomain, hostPort) }, - Class: "tls", + Class: ClassTLS, } } @@ -48,7 +48,7 @@ func TLSWithIP(certDomain string, dialAddr netip.AddrPort) ProbeClass { Probe: func(ctx context.Context) error { return probeTLS(ctx, certDomain, dialAddr.String()) }, - Class: "tls", + Class: ClassTLS, } }