2021-01-27 00:56:50 +03:00
|
|
|
package victoriametrics
|
|
|
|
|
|
|
|
import (
|
2024-11-09 19:49:45 +03:00
|
|
|
"bytes"
|
2021-01-27 00:56:50 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuildName(t *testing.T) {
|
|
|
|
m := NewMeter()
|
|
|
|
im := m.(*victoriametricsMeter)
|
2021-10-31 14:46:40 +03:00
|
|
|
check := `micro_foo{micro_aaa="b",micro_bar="baz",micro_ccc="d"}`
|
2024-11-08 17:38:39 +03:00
|
|
|
name := im.buildName("micro_foo", "micro_bar", "baz", "micro_aaa", "b", "micro_ccc", "d")
|
2021-01-27 00:56:50 +03:00
|
|
|
if name != check {
|
|
|
|
t.Fatalf("metric name error: %s != %s", name, check)
|
|
|
|
}
|
|
|
|
|
2021-04-28 01:13:08 +03:00
|
|
|
cnt := m.Counter("counter", "key", "val")
|
2021-01-27 00:56:50 +03:00
|
|
|
cnt.Inc()
|
2021-02-18 16:01:13 +03:00
|
|
|
}
|
2024-11-09 19:49:45 +03:00
|
|
|
|
|
|
|
func TestPrometheusCompat(t *testing.T) {
|
|
|
|
m := NewMeter(PrometheusCompat(true))
|
|
|
|
m.Histogram("foo", "key", "val").Update(15)
|
|
|
|
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
|
|
|
|
_ = m.Write(buf)
|
|
|
|
t.Logf("\n%s", buf.Bytes())
|
|
|
|
}
|