mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-16 18:08:40 +00:00
net/portmapper: convert UPnP metrics to new syncs.Map.LoadOrInit method
Simplify UPnP error metrics by using the new syncs.Map.LoadOrInit method. Updates #cleanup Signed-off-by: Val <valerie@tailscale.com>
This commit is contained in:
parent
8326fdd60f
commit
19e5f242e0
@ -25,10 +25,10 @@ import (
|
|||||||
"tailscale.com/net/netmon"
|
"tailscale.com/net/netmon"
|
||||||
"tailscale.com/net/netns"
|
"tailscale.com/net/netns"
|
||||||
"tailscale.com/net/sockstats"
|
"tailscale.com/net/sockstats"
|
||||||
|
"tailscale.com/syncs"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
"tailscale.com/types/nettype"
|
"tailscale.com/types/nettype"
|
||||||
"tailscale.com/util/clientmetric"
|
"tailscale.com/util/clientmetric"
|
||||||
"tailscale.com/util/mak"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// DebugKnobs contains debug configuration that can be provided when creating a
|
// DebugKnobs contains debug configuration that can be provided when creating a
|
||||||
@ -1028,18 +1028,10 @@ var (
|
|||||||
|
|
||||||
// UPnP error metric that's keyed by code; lazily registered on first read
|
// UPnP error metric that's keyed by code; lazily registered on first read
|
||||||
var (
|
var (
|
||||||
metricUPnPErrorsByCodeMu sync.Mutex
|
metricUPnPErrorsByCode syncs.Map[string, *clientmetric.Metric]
|
||||||
metricUPnPErrorsByCode map[int]*clientmetric.Metric
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getUPnPErrorsMetric(code int) *clientmetric.Metric {
|
func getUPnPErrorsMetric(code int) *clientmetric.Metric {
|
||||||
metricUPnPErrorsByCodeMu.Lock()
|
|
||||||
defer metricUPnPErrorsByCodeMu.Unlock()
|
|
||||||
mm := metricUPnPErrorsByCode[code]
|
|
||||||
if mm != nil {
|
|
||||||
return mm
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metric names cannot contain a hyphen, so we handle negative numbers
|
// Metric names cannot contain a hyphen, so we handle negative numbers
|
||||||
// by prefixing the name with a "minus_".
|
// by prefixing the name with a "minus_".
|
||||||
var codeStr string
|
var codeStr string
|
||||||
@ -1049,7 +1041,6 @@ func getUPnPErrorsMetric(code int) *clientmetric.Metric {
|
|||||||
codeStr = fmt.Sprintf("portmap_upnp_errors_with_code_%d", code)
|
codeStr = fmt.Sprintf("portmap_upnp_errors_with_code_%d", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
mm = clientmetric.NewCounter(codeStr)
|
mm, _ := metricUPnPErrorsByCode.LoadOrInit(codeStr, func() *clientmetric.Metric { return clientmetric.NewCounter(codeStr) })
|
||||||
mak.Set(&metricUPnPErrorsByCode, code, mm)
|
|
||||||
return mm
|
return mm
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user