metrics: add a NewLabelMap helper to create and register label maps
Updates tailscale/corp#31174 Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
committed by
Anton Tolchanov
parent
76fb09c6bd
commit
17b0c7bfb3
@@ -99,18 +99,13 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tlsRequestVersion = &metrics.LabelMap{Label: "version"}
|
tlsRequestVersion = metrics.NewLabelMap("derper_tls_request_version", "version")
|
||||||
tlsActiveVersion = &metrics.LabelMap{Label: "version"}
|
tlsActiveVersion = metrics.NewLabelMap("gauge_derper_tls_active_version", "version")
|
||||||
)
|
)
|
||||||
|
|
||||||
const setecMeshKeyName = "meshkey"
|
const setecMeshKeyName = "meshkey"
|
||||||
const meshKeyEnvVar = "TAILSCALE_DERPER_MESH_KEY"
|
const meshKeyEnvVar = "TAILSCALE_DERPER_MESH_KEY"
|
||||||
|
|
||||||
func init() {
|
|
||||||
expvar.Publish("derper_tls_request_version", tlsRequestVersion)
|
|
||||||
expvar.Publish("gauge_derper_tls_active_version", tlsActiveVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
PrivateKey key.NodePrivate
|
PrivateKey key.NodePrivate
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ type LabelMap struct {
|
|||||||
shardedIntMu syncs.Mutex
|
shardedIntMu syncs.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewLabelMap creates and publishes a new LabelMap metric with the given
|
||||||
|
// metric name and label name.
|
||||||
|
func NewLabelMap(metric, label string) *LabelMap {
|
||||||
|
m := &LabelMap{Label: label}
|
||||||
|
expvar.Publish(metric, m)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
// SetInt64 sets the *Int value stored under the given map key.
|
// SetInt64 sets the *Int value stored under the given map key.
|
||||||
func (m *LabelMap) SetInt64(key string, v int64) {
|
func (m *LabelMap) SetInt64(key string, v int64) {
|
||||||
m.Get(key).Set(v)
|
m.Get(key).Set(v)
|
||||||
|
|||||||
Reference in New Issue
Block a user