Skip to content

Commit

Permalink
feat: trace tree support multi regions
Browse files Browse the repository at this point in the history
  • Loading branch information
taloric committed Sep 24, 2024
1 parent 7f42010 commit d6e8300
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion server/libs/tracetree/spantrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (
const SPAN_TRACE_VERSION = 0x12

type SpanTrace struct {
Time uint32 // not store, easy to use when calculating
Time uint32 // not store, easy to use when calculating
QuerierRegion string // not store, easy to use when calculating

EndTimeUsPart uint32 // The microsecond part less than 1 second

Expand Down
12 changes: 9 additions & 3 deletions server/libs/tracetree/tracetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
)

const TRACE_TREE_VERSION_0X12 = 0x12 // before 20240827
const TRACE_TREE_VERSION = 0x13
const TRACE_TREE_VERSION_0X13 = 0x13
const TRACE_TREE_VERSION = 0x14

func HashSearchIndex(key string) uint64 {
return utils.DJBHash(17, key)
Expand Down Expand Up @@ -80,7 +81,8 @@ type TreeNode struct {
Level uint8 // helps with calculations, no need to write to Clickhouse
UID string // helps with calculations, no need to write to Clickhouse

Topic string
Topic string
QuerierRegion string

ResponseDurationSum uint64
ResponseTotal uint32
Expand Down Expand Up @@ -174,6 +176,7 @@ func (t *TraceTree) Encode() {

encoder.WriteU8(node.PseudoLink)
encoder.WriteString255(node.Topic)
encoder.WriteString255(node.QuerierRegion)
encoder.WriteVarintU64(node.ResponseDurationSum)
encoder.WriteVarintU32(node.ResponseTotal)
encoder.WriteVarintU32(node.ResponseStatusServerErrorCount)
Expand All @@ -183,7 +186,7 @@ func (t *TraceTree) Encode() {

func (t *TraceTree) Decode(decoder *codec.SimpleDecoder) error {
version := decoder.ReadU8()
if version != TRACE_TREE_VERSION && version != TRACE_TREE_VERSION_0X12 {
if version != TRACE_TREE_VERSION && version != TRACE_TREE_VERSION_0X12 && version != TRACE_TREE_VERSION_0X13 {
return fmt.Errorf("trace tree data version is %d expect version is %d", version, TRACE_TREE_VERSION)
}
treeNodeCount := int(decoder.ReadU16())
Expand Down Expand Up @@ -239,6 +242,9 @@ func (t *TraceTree) Decode(decoder *codec.SimpleDecoder) error {
}
n.UID = ""
n.Topic = decoder.ReadString255()
if version >= TRACE_TREE_VERSION {
n.QuerierRegion = decoder.ReadString255()
}
n.ResponseDurationSum = decoder.ReadVarintU64()
n.ResponseTotal = decoder.ReadVarintU32()
n.ResponseStatusServerErrorCount = decoder.ReadVarintU32()
Expand Down

0 comments on commit d6e8300

Please sign in to comment.