Skip to content

Commit 8d3623f

Browse files
Manik2708SoumyaRaikwar
authored andcommitted
[cassandra] Refactor TagFilter to accept dbmodel.Span (jaegertracing#7707)
## Which problem is this PR solving? - Fixes a part of: jaegertracing#6458 ## Description of the changes - This is a blocker of jaegertracing#7699, we need to refactor `TagFilter` to accept `dbmodel.Span` rather than `model.Span` ## How was this change tested? - Unit And Integration Tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Manik Mehta <mehtamanik96@gmail.com> Signed-off-by: SoumyaRaikwar <somuraik@gmail.com>
1 parent 6e49eb8 commit 8d3623f

File tree

11 files changed

+557
-113
lines changed

11 files changed

+557
-113
lines changed

internal/storage/v1/cassandra/spanstore/dbmodel/model.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ package dbmodel
77
import (
88
"bytes"
99
"encoding/binary"
10+
"encoding/hex"
11+
"sort"
12+
"strconv"
13+
"strings"
1014

1115
"github.com/jaegertracing/jaeger-idl/model/v1"
1216
)
@@ -53,6 +57,96 @@ type KeyValue struct {
5357
ValueBinary []byte `cql:"value_binary"`
5458
}
5559

60+
func (t *KeyValue) compareValues(that *KeyValue) int {
61+
switch t.ValueType {
62+
case stringType:
63+
return strings.Compare(t.ValueString, that.ValueString)
64+
case boolType:
65+
if t.ValueBool != that.ValueBool {
66+
if !t.ValueBool {
67+
return -1
68+
}
69+
return 1
70+
}
71+
case int64Type:
72+
return int(t.ValueInt64 - that.ValueInt64)
73+
case float64Type:
74+
if t.ValueFloat64 != that.ValueFloat64 {
75+
if t.ValueFloat64 < that.ValueFloat64 {
76+
return -1
77+
}
78+
return 1
79+
}
80+
case binaryType:
81+
return bytes.Compare(t.ValueBinary, that.ValueBinary)
82+
default:
83+
return -1 // theoretical case, not stating them equal but placing the base pointer before other
84+
}
85+
return 0
86+
}
87+
88+
func (t *KeyValue) Compare(that any) int {
89+
if that == nil {
90+
if t == nil {
91+
return 0
92+
}
93+
return 1
94+
}
95+
that1, ok := that.(*KeyValue)
96+
if !ok {
97+
that2, ok := that.(KeyValue)
98+
if !ok {
99+
return 1
100+
}
101+
that1 = &that2
102+
}
103+
if that1 == nil {
104+
if t == nil {
105+
return 0
106+
}
107+
return 1
108+
} else if t == nil {
109+
return -1
110+
}
111+
if cmp := strings.Compare(t.Key, that1.Key); cmp != 0 {
112+
return cmp
113+
}
114+
if cmp := strings.Compare(t.ValueType, that1.ValueType); cmp != 0 {
115+
return cmp
116+
}
117+
return t.compareValues(that1)
118+
}
119+
120+
func (t *KeyValue) Equal(that any) bool {
121+
return t.Compare(that) == 0
122+
}
123+
124+
func (t *KeyValue) AsString() string {
125+
switch t.ValueType {
126+
case stringType:
127+
return t.ValueString
128+
case boolType:
129+
if t.ValueBool {
130+
return "true"
131+
}
132+
return "false"
133+
case int64Type:
134+
return strconv.FormatInt(t.ValueInt64, 10)
135+
case float64Type:
136+
return strconv.FormatFloat(t.ValueFloat64, 'g', 10, 64)
137+
case binaryType:
138+
return hex.EncodeToString(t.ValueBinary)
139+
default:
140+
return "unknown type " + t.ValueType
141+
}
142+
}
143+
144+
func SortKVs(kvs []KeyValue) {
145+
sort.Slice(kvs, func(i, j int) bool {
146+
return kvs[i].Compare(kvs[j]) < 0
147+
})
148+
}
149+
56150
// Log is the UDT representation of a Jaeger Log.
57151
type Log struct {
58152
Timestamp int64 `cql:"ts"` // microseconds since epoch

0 commit comments

Comments
 (0)