From 94aaec5c660a37db58661aa7130c35a95cc593b7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 19 Mar 2022 20:58:35 -0700 Subject: [PATCH] prober: rename Probe to ProbeFunc. Making way for a future Probe struct to encapsulate per-probe state. Signed-off-by: David Anderson --- prober/http.go | 4 ++-- prober/prober.go | 10 +++++----- prober/tcp.go | 4 ++-- prober/tls.go | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/prober/http.go b/prober/http.go index d79b2132e..1b06dca60 100644 --- a/prober/http.go +++ b/prober/http.go @@ -16,11 +16,11 @@ const maxHTTPBody = 4 << 20 // MiB // HTTP returns a Probe that healthchecks an HTTP URL. // -// The Probe sends a GET request for url, expects an HTTP 200 +// The ProbeFunc sends a GET request for url, expects an HTTP 200 // response, and verifies that want is present in the response // body. If the URL is HTTPS, the probe further checks that the TLS // certificate is good for at least the next 7 days. -func HTTP(url, wantText string) Probe { +func HTTP(url, wantText string) ProbeFunc { return func(ctx context.Context) error { return probeHTTP(ctx, url, []byte(wantText)) } diff --git a/prober/prober.go b/prober/prober.go index 0e053db0b..268a79dc0 100644 --- a/prober/prober.go +++ b/prober/prober.go @@ -18,10 +18,10 @@ import ( "tailscale.com/metrics" ) -// Probe is a function that probes something and reports whether the +// ProbeFunc is a function that probes something and reports whether the // probe succeeded. The provided context must be used to ensure timely // cancellation and timeout behavior. -type Probe func(context.Context) error +type ProbeFunc func(context.Context) error // a Prober manages a set of probes and keeps track of their results. type Prober struct { @@ -101,7 +101,7 @@ func (p *Prober) Expvar() *metrics.Set { // returns. // // Registering a probe under an already-registered name panics. -func (p *Prober) Run(name string, interval time.Duration, fun Probe) context.CancelFunc { +func (p *Prober) Run(name string, interval time.Duration, fun ProbeFunc) context.CancelFunc { p.mu.Lock() defer p.mu.Unlock() ticker := p.registerLocked(name, interval) @@ -120,7 +120,7 @@ func (p *Prober) Run(name string, interval time.Duration, fun Probe) context.Can // probeLoop invokes runProbe on fun every interval. The first probe // is run after interval. -func (p *Prober) probeLoop(ctx context.Context, name string, interval time.Duration, tick ticker, fun Probe) { +func (p *Prober) probeLoop(ctx context.Context, name string, interval time.Duration, tick ticker, fun ProbeFunc) { defer func() { p.unregister(name) tick.Stop() @@ -143,7 +143,7 @@ func (p *Prober) probeLoop(ctx context.Context, name string, interval time.Durat // fun is invoked with a timeout slightly less than interval, so that // the probe either succeeds or fails before the next cycle is // scheduled to start. -func (p *Prober) runProbe(ctx context.Context, name string, interval time.Duration, fun Probe) { +func (p *Prober) runProbe(ctx context.Context, name string, interval time.Duration, fun ProbeFunc) { start := p.start(name) defer func() { // Prevent a panic within one probe function from killing the diff --git a/prober/tcp.go b/prober/tcp.go index 84ff76037..c6f2a6f73 100644 --- a/prober/tcp.go +++ b/prober/tcp.go @@ -12,8 +12,8 @@ import ( // TCP returns a Probe that healthchecks a TCP endpoint. // -// The Probe reports whether it can successfully connect to addr. -func TCP(addr string) Probe { +// The ProbeFunc reports whether it can successfully connect to addr. +func TCP(addr string) ProbeFunc { return func(ctx context.Context) error { return probeTCP(ctx, addr) } diff --git a/prober/tls.go b/prober/tls.go index 285be6935..ea64bdf24 100644 --- a/prober/tls.go +++ b/prober/tls.go @@ -14,10 +14,10 @@ import ( // TLS returns a Probe that healthchecks a TLS endpoint. // -// The Probe connects to hostname, does a TLS handshake, verifies that -// the hostname matches the presented certificate, and that the +// The ProbeFunc connects to hostname, does a TLS handshake, verifies +// that the hostname matches the presented certificate, and that the // certificate expires in more than 7 days from the probe time. -func TLS(hostname string) Probe { +func TLS(hostname string) ProbeFunc { return func(ctx context.Context) error { return probeTLS(ctx, hostname) }