mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
0e0e53d3b3
this commit changes usermetrics to be non-global, this is a building block for correct metrics if a go process runs multiple tsnets or in tests. Updates #13420 Updates tailscale/corp#22075 Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
27 lines
494 B
Go
27 lines
494 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package usermetric
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestGauge(t *testing.T) {
|
|
var reg Registry
|
|
g := reg.NewGauge("test_gauge", "This is a test gauge")
|
|
g.Set(15)
|
|
|
|
var buf bytes.Buffer
|
|
g.WritePrometheus(&buf, "test_gauge")
|
|
const want = `# TYPE test_gauge gauge
|
|
# HELP test_gauge This is a test gauge
|
|
test_gauge 15
|
|
`
|
|
if got := buf.String(); got != want {
|
|
t.Errorf("got %q; want %q", got, want)
|
|
}
|
|
|
|
}
|