forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
147 lines (131 loc) · 3.96 KB
/
main.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"time"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"
"github.com/jaegertracing/jaeger/model"
cascfg "github.com/jaegertracing/jaeger/pkg/cassandra/config"
cSpanStore "github.com/jaegertracing/jaeger/plugin/storage/cassandra/spanstore"
"github.com/jaegertracing/jaeger/storage/spanstore"
)
var logger, _ = zap.NewDevelopment()
// TODO: this is going morph into a load testing framework for cassandra 3.7
func main() {
noScope := metrics.NullFactory
cConfig := &cascfg.Configuration{
Servers: []string{"127.0.0.1"},
ConnectionsPerHost: 10,
Timeout: time.Millisecond * 750,
ProtoVersion: 4,
Keyspace: "jaeger_v1_test",
}
cqlSession, err := cConfig.NewSession()
if err != nil {
logger.Fatal("Cannot create Cassandra session", zap.Error(err))
}
spanStore := cSpanStore.NewSpanWriter(cqlSession, time.Hour*12, noScope, logger)
spanReader := cSpanStore.NewSpanReader(cqlSession, noScope, logger)
if err = spanStore.WriteSpan(getSomeSpan()); err != nil {
logger.Fatal("Failed to save", zap.Error(err))
} else {
logger.Info("Saved span", zap.String("spanID", getSomeSpan().SpanID.String()))
}
s := getSomeSpan()
trace, err := spanReader.GetTrace(s.TraceID)
if err != nil {
logger.Fatal("Failed to read", zap.Error(err))
} else {
logger.Info("Loaded trace", zap.Any("trace", trace))
}
tqp := &spanstore.TraceQueryParameters{
ServiceName: "someServiceName",
StartTimeMin: time.Now().Add(time.Hour * -1),
StartTimeMax: time.Now().Add(time.Hour),
}
logger.Info("Check main query")
queryAndPrint(spanReader, tqp)
tqp.OperationName = "opName"
logger.Info("Check query with operation")
queryAndPrint(spanReader, tqp)
tqp.Tags = map[string]string{
"someKey": "someVal",
}
logger.Info("Check query with operation name and tags")
queryAndPrint(spanReader, tqp)
tqp.DurationMin = 0
tqp.DurationMax = time.Hour
tqp.Tags = map[string]string{}
logger.Info("check query with duration")
queryAndPrint(spanReader, tqp)
}
func queryAndPrint(spanReader *cSpanStore.SpanReader, tqp *spanstore.TraceQueryParameters) {
traces, err := spanReader.FindTraces(tqp)
if err != nil {
logger.Fatal("Failed to query", zap.Error(err))
} else {
logger.Info("Found trace(s)", zap.Any("traces", traces))
}
}
func getSomeProcess() *model.Process {
processTagVal := "indexMe"
return &model.Process{
ServiceName: "someServiceName",
Tags: model.KeyValues{
model.String("processTagKey", processTagVal),
},
}
}
func getSomeSpan() *model.Span {
return &model.Span{
TraceID: model.TraceID{High: 1, Low: 2},
SpanID: model.SpanID(3),
ParentSpanID: model.SpanID(4),
OperationName: "opName",
References: getReferences(),
Flags: model.Flags(uint32(5)),
StartTime: time.Now(),
Duration: 50000 * time.Microsecond,
Tags: getTags(),
Logs: getLogs(),
Process: getSomeProcess(),
}
}
func getReferences() []model.SpanRef {
return []model.SpanRef{
{
RefType: model.ChildOf,
TraceID: model.TraceID{High: 1, Low: 1},
SpanID: model.SpanID(4),
},
}
}
func getTags() model.KeyValues {
someVal := "someVal"
return model.KeyValues{
model.String("someKey", someVal),
}
}
func getLogs() []model.Log {
logTag := "this is a msg"
return []model.Log{
{
Timestamp: time.Now(),
Fields: model.KeyValues{
model.String("event", logTag),
},
},
}
}