1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 "golang.org/x/tools/internal/event"
13 "golang.org/x/tools/internal/event/keys"
16 func TestEncodeMetric(t *testing.T) {
17 exporter := registerExporter()
18 const prefix = testNodeStr + `
23 run func(ctx context.Context)
27 name: "HistogramFloat64, HistogramInt64",
28 run: func(ctx context.Context) {
29 ctx = event.Label(ctx, keyMethod.Of("godoc.ServeHTTP"))
30 event.Metric(ctx, latencyMs.Of(96.58))
31 ctx = event.Label(ctx, keys.Err.Of(errors.New("panic: fatal signal")))
32 event.Metric(ctx, bytesIn.Of(97e2))
36 "metric_descriptor": {
38 "description": "The latency of calls in milliseconds",
51 "start_timestamp": "1970-01-01T00:00:00Z",
54 "timestamp": "1970-01-01T00:00:40Z",
55 "distributionValue": {
83 "metric_descriptor": {
85 "description": "The latency of calls in milliseconds",
98 "start_timestamp": "1970-01-01T00:00:00Z",
101 "timestamp": "1970-01-01T00:00:40Z",
102 "distributionValue": {
136 ctx := context.TODO()
137 for _, tt := range tests {
138 t.Run(tt.name, func(t *testing.T) {
140 got := exporter.Output("/v1/metrics")
141 checkJSON(t, got, []byte(tt.want))