8 "golang.org/x/tools/internal/event"
9 "golang.org/x/tools/internal/event/keys"
12 func TestEncodeMetric(t *testing.T) {
13 exporter := registerExporter()
14 const prefix = testNodeStr + `
19 run func(ctx context.Context)
23 name: "HistogramFloat64, HistogramInt64",
24 run: func(ctx context.Context) {
25 ctx = event.Label(ctx, keyMethod.Of("godoc.ServeHTTP"))
26 event.Metric(ctx, latencyMs.Of(96.58))
27 ctx = event.Label(ctx, keys.Err.Of(errors.New("panic: fatal signal")))
28 event.Metric(ctx, bytesIn.Of(97e2))
32 "metric_descriptor": {
34 "description": "The latency of calls in milliseconds",
47 "start_timestamp": "1970-01-01T00:00:00Z",
50 "timestamp": "1970-01-01T00:00:40Z",
51 "distributionValue": {
79 "metric_descriptor": {
81 "description": "The latency of calls in milliseconds",
94 "start_timestamp": "1970-01-01T00:00:00Z",
97 "timestamp": "1970-01-01T00:00:40Z",
98 "distributionValue": {
132 ctx := context.TODO()
133 for _, tt := range tests {
134 t.Run(tt.name, func(t *testing.T) {
136 got := exporter.Output("/v1/metrics")
137 checkJSON(t, got, []byte(tt.want))