From 5550a17391f1a8765f7f56831c759ee862b6b434 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 26 Sep 2024 10:04:29 +0200 Subject: [PATCH] wgengine: make opts.Metrics mandatory Fixes #13582 Signed-off-by: Kristoffer Dalby --- wgengine/userspace.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wgengine/userspace.go b/wgengine/userspace.go index 1e28444cc..fc204736a 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -196,7 +196,8 @@ type Config struct { // HealthTracker, if non-nil, is the health tracker to use. HealthTracker *health.Tracker - // Metrics, if non-nil, is the usermetrics registry to use. + // Metrics is the usermetrics registry to use. + // Mandatory, if not set, an error is returned. Metrics *usermetric.Registry // Dialer is the dialer to use for outbound connections. @@ -273,6 +274,10 @@ func NewUserspaceEngine(logf logger.Logf, conf Config) (_ Engine, reterr error) panic("NewUserspaceEngine called without HealthTracker (being strict in tests)") } + if conf.Metrics == nil { + return nil, errors.New("NewUserspaceEngine: opts.Metrics is required, please pass a *usermetric.Registry") + } + if conf.Tun == nil { logf("[v1] using fake (no-op) tun device") conf.Tun = tstun.NewFake()