forked from grafana/tempo
/
search_data_test.go
84 lines (78 loc) · 2.19 KB
/
search_data_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
80
81
82
83
84
package distributor
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/grafana/tempo/pkg/tempofb"
"github.com/grafana/tempo/pkg/tempopb"
v1_common "github.com/grafana/tempo/pkg/tempopb/common/v1"
v1_resource "github.com/grafana/tempo/pkg/tempopb/resource/v1"
v1 "github.com/grafana/tempo/pkg/tempopb/trace/v1"
"github.com/grafana/tempo/tempodb/search"
)
func TestExtractSearchData(t *testing.T) {
traceIDA := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}
testCases := []struct {
name string
trace *tempopb.Trace
id []byte
searchData *tempofb.SearchEntryMutable
}{
{
name: "trace with root span",
trace: &tempopb.Trace{
Batches: []*v1.ResourceSpans{
{
Resource: &v1_resource.Resource{
Attributes: []*v1_common.KeyValue{
{
Key: "foo",
Value: &v1_common.AnyValue{
Value: &v1_common.AnyValue_StringValue{StringValue: "bar"},
},
},
{
Key: "service.name",
Value: &v1_common.AnyValue{
Value: &v1_common.AnyValue_StringValue{StringValue: "baz"},
},
},
},
},
InstrumentationLibrarySpans: []*v1.InstrumentationLibrarySpans{
{
InstrumentationLibrary: &v1_common.InstrumentationLibrary{
Name: "test",
},
Spans: []*v1.Span{
{
TraceId: traceIDA,
Name: "firstSpan",
},
},
},
},
},
},
},
id: traceIDA,
searchData: &tempofb.SearchEntryMutable{
TraceID: traceIDA,
Tags: tempofb.SearchDataMap{
"foo": []string{"bar"},
search.RootSpanPrefix + "foo": []string{"bar"},
search.RootSpanNameTag: []string{"firstSpan"},
search.SpanNameTag: []string{"firstSpan"},
search.RootServiceNameTag: []string{"baz"},
search.ServiceNameTag: []string{"baz"},
},
StartTimeUnixNano: 0,
EndTimeUnixNano: 0,
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.searchData.ToBytes(), extractSearchData(tc.trace, tc.id))
})
}
}