forked from flachnetz/dd-zipkin-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-v2_test.go
79 lines (63 loc) · 1.45 KB
/
json-v2_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
77
78
79
package codec
import (
"bytes"
"github.com/flachnetz/dd-zipkin-proxy/proxy"
. "github.com/onsi/gomega"
"strings"
"testing"
"time"
)
func TestParseJsonV2(t *testing.T) {
g := NewGomegaWithT(t)
spans, err := ParseJsonV2(strings.NewReader(encodedJsonV2))
g.Expect(err).ToNot(HaveOccurred())
g.Expect(spans).To(HaveLen(1))
g.Expect(spans[0]).To(Equal(proxy.Span{
Id: 0xdead,
Trace: 0xbeaf,
Parent: 0xbeaf,
Name: "span name",
Service: "my-service",
Timestamp: proxy.Timestamp(1560276970 * time.Second),
Duration: 50 * time.Millisecond,
Tags: map[string]string{
"http.path": "/my/path",
"http.status": "404",
tagProtocolVersion: tagJsonV2,
},
Timings: proxy.Timings{
CS: proxy.Timestamp(1560276970 * time.Second),
CR: proxy.Timestamp(1560276970*time.Second + 50*time.Millisecond),
},
}))
}
func BenchmarkParseJsonV2(b *testing.B) {
data := jsonCompact([]byte(encodedJsonV2))
b.RunParallel(func(pb *testing.PB) {
var sum proxy.Id
for pb.Next() {
spans, _ := ParseJsonV2(bytes.NewReader(data))
for _, span := range spans {
sum += span.Id
}
}
})
}
const encodedJsonV2 = `[
{
"traceId": "beaf",
"id": "dead",
"parentId": "beaf",
"name": "span name",
"localEndpoint": {
"serviceName": "my-service"
},
"tags": {
"http.path": "/my/path",
"http.status": "404"
},
"kind": "CLIENT",
"timestamp": 1560276970000000,
"duration": 50000
}
]`