mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
net/portmapper: avoid alloc in getUPnPErrorsMetric
Updates #cleanup Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: Iea558024c038face24cc46584421998d10f13a66
This commit is contained in:
parent
237b4b5a2a
commit
ef596aed9b
@ -1028,19 +1028,21 @@ func (c *Client) Probe(ctx context.Context) (res ProbeResult, err error) {
|
|||||||
|
|
||||||
// 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 (
|
||||||
metricUPnPErrorsByCode syncs.Map[string, *clientmetric.Metric]
|
metricUPnPErrorsByCode syncs.Map[int, *clientmetric.Metric]
|
||||||
)
|
)
|
||||||
|
|
||||||
func getUPnPErrorsMetric(code int) *clientmetric.Metric {
|
func getUPnPErrorsMetric(code int) *clientmetric.Metric {
|
||||||
// Metric names cannot contain a hyphen, so we handle negative numbers
|
mm, _ := metricUPnPErrorsByCode.LoadOrInit(code, func() *clientmetric.Metric {
|
||||||
// by prefixing the name with a "minus_".
|
// Metric names cannot contain a hyphen, so we handle negative
|
||||||
var codeStr string
|
// numbers by prefixing the name with a "minus_".
|
||||||
if code < 0 {
|
var codeStr string
|
||||||
codeStr = fmt.Sprintf("portmap_upnp_errors_with_code_minus_%d", -code)
|
if code < 0 {
|
||||||
} else {
|
codeStr = fmt.Sprintf("portmap_upnp_errors_with_code_minus_%d", -code)
|
||||||
codeStr = fmt.Sprintf("portmap_upnp_errors_with_code_%d", code)
|
} else {
|
||||||
}
|
codeStr = fmt.Sprintf("portmap_upnp_errors_with_code_%d", code)
|
||||||
|
}
|
||||||
|
|
||||||
mm, _ := metricUPnPErrorsByCode.LoadOrInit(codeStr, func() *clientmetric.Metric { return clientmetric.NewCounter(codeStr) })
|
return clientmetric.NewCounter(codeStr)
|
||||||
|
})
|
||||||
return mm
|
return mm
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user