forked from trpc-ecosystem/go-metrics-prometheus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sink_test.go
76 lines (67 loc) · 2.31 KB
/
sink_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package prometheus
import (
"fmt"
"testing"
"github.com/prometheus/client_golang/prometheus/push"
"trpc.group/trpc-go/trpc-go/metrics"
runtime "trpc.group/trpc-go/trpc-metrics-runtime"
)
func TestSink(t *testing.T) {
setup(t)
s := Sink{
enablePush: true,
pusher: push.New("", ""),
}
i := float64(0)
for i <= 3 {
s.incrCounter("test_counter", 100*i)
s.addSample("test_sample", 200*i)
s.setGauge("test_gauge", 300*i)
_ = s.Report(metrics.NewSingleDimensionMetrics("test_counter_中文", 1, metrics.PolicySUM))
// Test multi-dimensional, multi-record reporting.
for _, policy := range []metrics.Policy{metrics.PolicySUM, metrics.PolicySET, metrics.PolicyHistogram} {
// report labels from 0 to 20
ms := make([]*metrics.Metrics, 0)
labels := make([]*metrics.Dimension, 0)
for j := 0; j < 20; j++ {
labels = append(labels, &metrics.Dimension{Name: fmt.Sprintf("test_labels_%d", j), Value: fmt.Sprintf("test_value_%d", int(i))})
ms = append(ms, metrics.NewMetrics(fmt.Sprintf("test_counter_%d", int(i)), float64(100*j), policy))
_ = s.Report(metrics.NewMultiDimensionMetricsX(fmt.Sprintf("test_name_%d_%d", j, policy), labels, ms))
_ = metrics.ReportMultiDimensionMetricsX(fmt.Sprintf("test_name_%d_%d", j, policy), labels, ms)
}
}
i++
}
// Test multi-dimensional, single-record reporting.
ms := make([]*metrics.Metrics, 0)
labels := make([]*metrics.Dimension, 0)
labels = append(labels, &metrics.Dimension{Name: fmt.Sprintf("test_labels_%d", 99), Value: fmt.Sprintf("test_value_%d", int(99))})
ms = append(ms, metrics.NewMetrics(fmt.Sprintf("test_counter_%d", int(99)), float64(100*99), metrics.PolicySUM))
_ = metrics.ReportMultiDimensionMetricsX("", labels, ms)
t.Log(getMetrics(t))
}
func TestMetrics(t *testing.T) {
setup(t)
s := Sink{
enablePush: true,
pusher: push.New("", ""),
}
bu := metrics.NewValueBounds(100, 500, 800)
metrics.RegisterMetricsSink(&s)
i := float64(0)
for i <= 10 {
metrics.AddSample("test_sample", bu, 100*i)
i++
}
t.Log(getMetrics(t))
}
func TestRuntime(t *testing.T) {
setup(t)
cfg := &Config{Namespace: "test", Subsystem: "testing", RawMode: false, EnablePush: true, PushInterval: 1}
initSink(cfg)
GetDefaultPusher()
GetDefaultPrometheusSink()
//metrics.RegisterMetricsSink(s)
runtime.RuntimeMetrics()
t.Log(getMetrics(t))
}