-
Notifications
You must be signed in to change notification settings - Fork 510
/
req.go
126 lines (99 loc) · 2.81 KB
/
req.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package test
import (
"math/rand"
"github.com/gogo/protobuf/proto"
"github.com/grafana/tempo/pkg/tempopb"
v1_common "github.com/grafana/tempo/pkg/tempopb/common/v1"
v1_trace "github.com/grafana/tempo/pkg/tempopb/trace/v1"
)
func MakeRequest(spans int, traceID []byte) *tempopb.PushRequest {
if len(traceID) == 0 {
traceID = make([]byte, 16)
rand.Read(traceID)
}
req := &tempopb.PushRequest{
Batch: &v1_trace.ResourceSpans{},
}
var ils *v1_trace.InstrumentationLibrarySpans
for i := 0; i < spans; i++ {
// occasionally make a new ils
if ils == nil || rand.Int()%3 == 0 {
ils = &v1_trace.InstrumentationLibrarySpans{
InstrumentationLibrary: &v1_common.InstrumentationLibrary{
Name: "super library",
Version: "0.0.1",
},
}
req.Batch.InstrumentationLibrarySpans = append(req.Batch.InstrumentationLibrarySpans, ils)
}
sampleSpan := v1_trace.Span{
Name: "test",
TraceId: traceID,
SpanId: make([]byte, 8),
}
rand.Read(sampleSpan.SpanId)
ils.Spans = append(ils.Spans, &sampleSpan)
}
return req
}
func MakeTraceBytes(requests int, traceID []byte) *tempopb.TraceBytes {
trace := &tempopb.Trace{
Batches: make([]*v1_trace.ResourceSpans, 0),
}
for i := 0; i < requests; i++ {
trace.Batches = append(trace.Batches, MakeRequest(rand.Int()%20+1, traceID).Batch)
}
bytes, err := proto.Marshal(trace)
if err != nil {
panic(err)
}
traceBytes := &tempopb.TraceBytes{
Traces: [][]byte{bytes},
}
return traceBytes
}
func MakeTrace(requests int, traceID []byte) *tempopb.Trace {
trace := &tempopb.Trace{
Batches: make([]*v1_trace.ResourceSpans, 0),
}
for i := 0; i < requests; i++ {
trace.Batches = append(trace.Batches, MakeRequest(rand.Int()%20+1, traceID).Batch)
}
return trace
}
func MakeTraceWithSpanCount(requests int, spansEach int, traceID []byte) *tempopb.Trace {
trace := &tempopb.Trace{
Batches: make([]*v1_trace.ResourceSpans, 0),
}
for i := 0; i < requests; i++ {
trace.Batches = append(trace.Batches, MakeRequest(spansEach, traceID).Batch)
}
return trace
}
// Note that this fn will generate a request with size **close to** maxBytes
func MakeRequestWithByteLimit(maxBytes int, traceID []byte) *tempopb.PushRequest {
if len(traceID) == 0 {
traceID = make([]byte, 16)
rand.Read(traceID)
}
req := &tempopb.PushRequest{
Batch: &v1_trace.ResourceSpans{},
}
ils := &v1_trace.InstrumentationLibrarySpans{
InstrumentationLibrary: &v1_common.InstrumentationLibrary{
Name: "super library",
Version: "0.0.1",
},
}
req.Batch.InstrumentationLibrarySpans = append(req.Batch.InstrumentationLibrarySpans, ils)
for req.Size() < maxBytes {
sampleSpan := v1_trace.Span{
Name: "test",
TraceId: traceID,
SpanId: make([]byte, 8),
}
rand.Read(sampleSpan.SpanId)
ils.Spans = append(ils.Spans, &sampleSpan)
}
return req
}