Skip to content

Commit b7c8cda

Browse files
committed
feat: add biz_response_code for trace_tree
- add biz_response_code - update endpoints data structs
1 parent 9ef5cb9 commit b7c8cda

3 files changed

Lines changed: 79 additions & 9 deletions

File tree

server/ingester/flow_log/dbwriter/span_writer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (t *SpanWithTraceID) Encode() {
108108
encoder.WriteString255(t.RequestResource)
109109
encoder.WriteString255(t.ResponseResult)
110110
encoder.WriteString255(t.BizProtocol)
111+
encoder.WriteString255(t.BizResponseCode)
111112
encoder.WriteString255(t.ResponseException)
112113
if t.RequestId != nil {
113114
encoder.WriteVarintU64(*t.RequestId)

server/libs/tracetree/spantrace.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const SPAN_TRACE_VERSION_0x13 = 0x13 // before 20251108
3131
const SPAN_TRACE_VERSION_0x14 = 0x14 // before 20251211
3232
const SPAN_TRACE_VERSION_0x15 = 0x15 // before 20251227
3333
const SPAN_TRACE_VERSION_0x16 = 0x16
34-
const SPAN_TRACE_VERSION = 0x17
34+
const SPAN_TRACE_VERSION_0x17 = 0x17 // before 20260507
35+
const SPAN_TRACE_VERSION = 0x18
3536

3637
type SpanTrace struct {
3738
QuerierRegion string // not store, easy to use when calculating
@@ -75,6 +76,7 @@ type SpanTrace struct {
7576
RequestResource string // notice: will be cut to 255 when write
7677
ResponseResult string
7778
BizProtocol string
79+
BizResponseCode string
7880
ResponseException string
7981
RequestId uint64
8082
SyscallTraceIDRequest uint64
@@ -137,6 +139,7 @@ func (t *SpanTrace) Decode(decoder *codec.SimpleDecoder) error {
137139
t.RequestResource = decoder.ReadString255()
138140
t.ResponseResult = decoder.ReadString255()
139141
t.BizProtocol = decoder.ReadString255()
142+
t.BizResponseCode = decoder.ReadString255()
140143
t.ResponseException = decoder.ReadString255()
141144
t.RequestId = decoder.ReadVarintU64()
142145

server/libs/tracetree/tracetree.go

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const TRACE_TREE_VERSION_0x19 = 0x19 // before 20260127
3737
const TRACE_TREE_VERSION_0x20 = 0x20 // before 20260129
3838
const TRACE_TREE_VERSION_0x21 = 0x21 // before 20260202
3939
const TRACE_TREE_VERSION_0x22 = 0x22 // before 20260317
40-
const TRACE_TREE_VERSION = 0x23
40+
const TRACE_TREE_VERSION_0x23 = 0x23 // before 20260507
41+
const TRACE_TREE_VERSION = 0x24
4142

4243
func HashSearchIndex(key string) uint64 {
4344
return utils.DJBHash(17, key)
@@ -56,6 +57,14 @@ type TraceTree struct {
5657
encodedTreeNodes []byte
5758
}
5859

60+
type EndpointStats struct {
61+
BizResponseCode string
62+
ResponseException string
63+
ResponseCode uint32
64+
Total uint32
65+
ResponseStatus uint8
66+
}
67+
5968
type SpanInfo struct {
6069
SignalSource uint8
6170
AutoServiceType0 uint8
@@ -66,6 +75,7 @@ type SpanInfo struct {
6675
AppService1 string
6776
ObservationPoint string
6877
Endpoints []string
78+
EndpointStat []EndpointStats
6979

7080
IsIPv4 bool
7181
IP40 uint32
@@ -82,6 +92,8 @@ type NodeInfo struct {
8292
ObservationPoint string
8393
Endpoints0 []string
8494
Endpoints1 []string
95+
EndpointStat0 []EndpointStats
96+
EndpointStat1 []EndpointStats
8597

8698
IsIPv4 bool
8799
IP4 uint32
@@ -102,6 +114,7 @@ type TreeNode struct {
102114
Topic string
103115
QuerierRegion string
104116

117+
BizResponseCode string
105118
ResponseException string
106119
ResponseDurationSum uint64
107120
ResponseCode uint32
@@ -176,6 +189,14 @@ func (t *TraceTree) Encode() {
176189
for _, e := range s.Endpoints {
177190
encoder.WriteString255(e)
178191
}
192+
encoder.WriteU16(uint16(len(s.EndpointStat)))
193+
for _, e := range s.EndpointStat {
194+
encoder.WriteString255(e.BizResponseCode)
195+
encoder.WriteString255(e.ResponseException)
196+
encoder.WriteVarintU32(e.ResponseCode)
197+
encoder.WriteVarintU32(e.Total)
198+
encoder.WriteU8(e.ResponseStatus)
199+
}
179200

180201
encoder.WriteBool(s.IsIPv4)
181202
if s.IsIPv4 {
@@ -209,6 +230,22 @@ func (t *TraceTree) Encode() {
209230
for _, e := range nodeInfo.Endpoints1 {
210231
encoder.WriteString255(e)
211232
}
233+
encoder.WriteU16(uint16(len(nodeInfo.EndpointStat0)))
234+
for _, e := range nodeInfo.EndpointStat0 {
235+
encoder.WriteString255(e.BizResponseCode)
236+
encoder.WriteString255(e.ResponseException)
237+
encoder.WriteVarintU32(e.ResponseCode)
238+
encoder.WriteVarintU32(e.Total)
239+
encoder.WriteU8(e.ResponseStatus)
240+
}
241+
encoder.WriteU16(uint16(len(nodeInfo.EndpointStat1)))
242+
for _, e := range nodeInfo.EndpointStat1 {
243+
encoder.WriteString255(e.BizResponseCode)
244+
encoder.WriteString255(e.ResponseException)
245+
encoder.WriteVarintU32(e.ResponseCode)
246+
encoder.WriteVarintU32(e.Total)
247+
encoder.WriteU8(e.ResponseStatus)
248+
}
212249

213250
encoder.WriteBool(nodeInfo.IsIPv4)
214251
if nodeInfo.IsIPv4 {
@@ -223,6 +260,7 @@ func (t *TraceTree) Encode() {
223260
encoder.WriteU8(node.PseudoLink)
224261
encoder.WriteString255(node.Topic)
225262
encoder.WriteString255(node.QuerierRegion)
263+
encoder.WriteString255(node.BizResponseCode)
226264
encoder.WriteString255(node.ResponseException)
227265
encoder.WriteVarintU64(node.ResponseDurationSum)
228266
encoder.WriteVarintU32(node.ResponseCode)
@@ -237,7 +275,7 @@ func (t *TraceTree) Encode() {
237275

238276
func (t *TraceTree) Decode(decoder *codec.SimpleDecoder) error {
239277
version := decoder.ReadU8()
240-
if version != TRACE_TREE_VERSION && version != TRACE_TREE_VERSION_0X12 && version != TRACE_TREE_VERSION_0X13 {
278+
if version != TRACE_TREE_VERSION {
241279
return fmt.Errorf("trace tree data version is %d expect version is %d", version, TRACE_TREE_VERSION)
242280
}
243281
t.UID = decoder.ReadU64()
@@ -268,6 +306,16 @@ func (t *TraceTree) Decode(decoder *codec.SimpleDecoder) error {
268306
for k := 0; k < endpointCount; k++ {
269307
s.Endpoints[k] = decoder.ReadString255()
270308
}
309+
endpointStatCount := int(decoder.ReadU16())
310+
s.EndpointStat = make([]EndpointStats, endpointStatCount)
311+
for k := 0; k < endpointStatCount; k++ {
312+
e := &s.EndpointStat[k]
313+
e.BizResponseCode = decoder.ReadString255()
314+
e.ResponseException = decoder.ReadString255()
315+
e.ResponseCode = decoder.ReadVarintU32()
316+
e.Total = decoder.ReadVarintU32()
317+
e.ResponseStatus = decoder.ReadU8()
318+
}
271319

272320
s.IsIPv4 = decoder.ReadBool()
273321
if s.IsIPv4 {
@@ -298,6 +346,27 @@ func (t *TraceTree) Decode(decoder *codec.SimpleDecoder) error {
298346
for j := 0; j < endpointCount; j++ {
299347
nodeInfo.Endpoints1[j] = decoder.ReadString255()
300348
}
349+
endpointStatCount := int(decoder.ReadU16())
350+
nodeInfo.EndpointStat0 = make([]EndpointStats, endpointStatCount)
351+
for j := 0; j < endpointStatCount; j++ {
352+
e := &nodeInfo.EndpointStat0[j]
353+
e.BizResponseCode = decoder.ReadString255()
354+
e.ResponseException = decoder.ReadString255()
355+
e.ResponseCode = decoder.ReadVarintU32()
356+
e.Total = decoder.ReadVarintU32()
357+
e.ResponseStatus = decoder.ReadU8()
358+
}
359+
endpointStatCount = int(decoder.ReadU16())
360+
nodeInfo.EndpointStat1 = make([]EndpointStats, endpointStatCount)
361+
for j := 0; j < endpointStatCount; j++ {
362+
e := &nodeInfo.EndpointStat1[j]
363+
e.BizResponseCode = decoder.ReadString255()
364+
e.ResponseException = decoder.ReadString255()
365+
e.ResponseCode = decoder.ReadVarintU32()
366+
e.Total = decoder.ReadVarintU32()
367+
e.ResponseStatus = decoder.ReadU8()
368+
}
369+
301370
nodeInfo.IsIPv4 = decoder.ReadBool()
302371
if nodeInfo.IsIPv4 {
303372
nodeInfo.IP4 = decoder.ReadU32()
@@ -307,15 +376,12 @@ func (t *TraceTree) Decode(decoder *codec.SimpleDecoder) error {
307376
}
308377
n.ChildIndices = n.ChildIndices[:0]
309378
n.Level = 0
310-
if version == TRACE_TREE_VERSION_0X12 {
311-
n.PseudoLink = 0
312-
} else {
313-
n.PseudoLink = decoder.ReadU8()
314-
}
379+
n.PseudoLink = decoder.ReadU8()
315380
n.UID = ""
316381
n.Topic = decoder.ReadString255()
382+
n.QuerierRegion = decoder.ReadString255()
317383
if version >= TRACE_TREE_VERSION {
318-
n.QuerierRegion = decoder.ReadString255()
384+
n.BizResponseCode = decoder.ReadString255()
319385
}
320386
n.ResponseException = decoder.ReadString255()
321387
n.ResponseDurationSum = decoder.ReadVarintU64()

0 commit comments

Comments
 (0)