Skip to content

Commit c8a1548

Browse files
authored
[v2][adjuster] Implement function to get standard adjusters to operate on otlp format (#6396)
## Which problem is this PR solving? - Towards #6344 ## Description of the changes - Implemented a function `StandardAdjusters` that returns a list of adjusters to be applied on ptrace.Traces - This will be used by the v2 query service in #6343 ## 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: Mahad Zaryab <[email protected]>
1 parent 4ecb086 commit c8a1548

16 files changed

+78
-30
lines changed

cmd/query/app/querysvc/adjuster/clockskew.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
warningSkewAdjustDisabled = "clock skew adjustment disabled; not applying calculated delta of %v"
2222
)
2323

24-
// ClockSkew returns an Adjuster that corrects span timestamps for clock skew.
24+
// CorrectClockSkew returns an Adjuster that corrects span timestamps for clock skew.
2525
//
2626
// This adjuster modifies the start and log timestamps of child spans that are
2727
// inconsistent with their parent spans due to clock differences between hosts.
@@ -36,7 +36,7 @@ const (
3636
// Parameters:
3737
// - maxDelta: The maximum allowable time adjustment. Adjustments exceeding
3838
// this value will be ignored.
39-
func ClockSkew(maxDelta time.Duration) Adjuster {
39+
func CorrectClockSkew(maxDelta time.Duration) Adjuster {
4040
return Func(func(traces ptrace.Traces) {
4141
adjuster := &clockSkewAdjuster{
4242
traces: traces,

cmd/query/app/querysvc/adjuster/clockskew_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func TestClockSkewAdjuster(t *testing.T) {
182182
testCase := tt // capture loop var
183183
t.Run(testCase.description, func(t *testing.T) {
184184
trace := makeTrace(testCase.trace)
185-
adjuster := ClockSkew(tt.maxAdjust)
185+
adjuster := CorrectClockSkew(tt.maxAdjust)
186186
adjuster.Adjust(trace)
187187

188188
var gotErr string

cmd/query/app/querysvc/adjuster/hash.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
var _ Adjuster = (*SpanHashDeduper)(nil)
1616

17-
// SpanHash creates an adjuster that deduplicates spans by removing all but one span
17+
// DeduplicateSpans creates an adjuster that deduplicates spans by removing all but one span
1818
// with the same hash code. This is particularly useful for scenarios where spans
1919
// may be duplicated during archival, such as with ElasticSearch archival.
2020
//
@@ -23,8 +23,8 @@ var _ Adjuster = (*SpanHashDeduper)(nil)
2323
//
2424
// To ensure consistent hash codes, this adjuster should be executed after
2525
// SortAttributesAndEvents, which normalizes the order of collections within the span.
26-
func SpanHash() SpanHashDeduper {
27-
return SpanHashDeduper{
26+
func DeduplicateSpans() *SpanHashDeduper {
27+
return &SpanHashDeduper{
2828
marshaler: &ptrace.ProtoMarshaler{},
2929
}
3030
}

cmd/query/app/querysvc/adjuster/hash_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313
)
1414

1515
func TestSpanHash_EmptySpans(t *testing.T) {
16-
adjuster := SpanHash()
16+
adjuster := DeduplicateSpans()
1717
input := ptrace.NewTraces()
1818
expected := ptrace.NewTraces()
1919
adjuster.Adjust(input)
2020
assert.Equal(t, expected, input)
2121
}
2222

2323
func TestSpanHash_RemovesDuplicateSpans(t *testing.T) {
24-
adjuster := SpanHash()
24+
adjuster := DeduplicateSpans()
2525
input := func() ptrace.Traces {
2626
traces := ptrace.NewTraces()
2727

@@ -126,7 +126,7 @@ func TestSpanHash_RemovesDuplicateSpans(t *testing.T) {
126126
}
127127

128128
func TestSpanHash_NoDuplicateSpans(t *testing.T) {
129-
adjuster := SpanHash()
129+
adjuster := DeduplicateSpans()
130130
input := func() ptrace.Traces {
131131
traces := ptrace.NewTraces()
132132
rs := traces.ResourceSpans().AppendEmpty()
@@ -180,7 +180,7 @@ func TestSpanHash_NoDuplicateSpans(t *testing.T) {
180180
}
181181

182182
func TestSpanHash_DuplicateSpansDifferentScopeAttributes(t *testing.T) {
183-
adjuster := SpanHash()
183+
adjuster := DeduplicateSpans()
184184
input := func() ptrace.Traces {
185185
traces := ptrace.NewTraces()
186186
rs := traces.ResourceSpans().AppendEmpty()
@@ -234,7 +234,7 @@ func TestSpanHash_DuplicateSpansDifferentScopeAttributes(t *testing.T) {
234234
}
235235

236236
func TestSpanHash_DuplicateSpansDifferentResourceAttributes(t *testing.T) {
237-
adjuster := SpanHash()
237+
adjuster := DeduplicateSpans()
238238
input := func() ptrace.Traces {
239239
traces := ptrace.NewTraces()
240240
rs := traces.ResourceSpans().AppendEmpty()

cmd/query/app/querysvc/adjuster/ipattribute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ var ipAttributesToCorrect = map[string]struct{}{
1919
"peer.ipv4": {},
2020
}
2121

22-
// IPAttribute returns an adjuster that replaces numeric "ip" attributes,
22+
// NormalizeIPAttributes returns an adjuster that replaces numeric "ip" attributes,
2323
// which usually contain IPv4 packed into uint32, with their string
2424
// representation (e.g. "8.8.8.8"").
25-
func IPAttribute() IPAttributeAdjuster {
25+
func NormalizeIPAttributes() IPAttributeAdjuster {
2626
return IPAttributeAdjuster{}
2727
}
2828

cmd/query/app/querysvc/adjuster/ipattribute_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestIPAttributeAdjuster(t *testing.T) {
5858
}
5959
}
6060

61-
IPAttribute().Adjust(traces)
61+
NormalizeIPAttributes().Adjust(traces)
6262

6363
resourceSpan := traces.ResourceSpans().At(0)
6464
assert.Equal(t, 3, resourceSpan.Resource().Attributes().Len())

cmd/query/app/querysvc/adjuster/resourceattributes.go renamed to cmd/query/app/querysvc/adjuster/libraryattributes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ var libraryKeys = map[string]struct{}{
2121
string(otelsemconv.TelemetryDistroVersionKey): {},
2222
}
2323

24-
// ResourceAttributes creates an adjuster that moves the OpenTelemetry library
24+
// MoveLibraryAttributes creates an adjuster that moves the OpenTelemetry library
2525
// attributes from spans to the parent resource so that the UI can
2626
// display them separately under Process.
2727
// https://github.com/jaegertracing/jaeger/issues/4534
28-
func ResourceAttributes() ResourceAttributesAdjuster {
28+
func MoveLibraryAttributes() ResourceAttributesAdjuster {
2929
return ResourceAttributesAdjuster{}
3030
}
3131

cmd/query/app/querysvc/adjuster/resourceattributes_test.go renamed to cmd/query/app/querysvc/adjuster/libraryattributes_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestResourceAttributesAdjuster_SpanWithLibraryAttributes(t *testing.T) {
2525
span.Attributes().PutStr(string(otelsemconv.TelemetryDistroVersionKey), "blah")
2626
span.Attributes().PutStr("another_key", "another_value")
2727

28-
adjuster := ResourceAttributes()
28+
adjuster := MoveLibraryAttributes()
2929
adjuster.Adjust(traces)
3030

3131
resultSpanAttributes := traces.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes()
@@ -67,7 +67,7 @@ func TestResourceAttributesAdjuster_SpanWithoutLibraryAttributes(t *testing.T) {
6767
span := rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty()
6868
span.Attributes().PutStr("random_key", "random_value")
6969

70-
adjuster := ResourceAttributes()
70+
adjuster := MoveLibraryAttributes()
7171
adjuster.Adjust(traces)
7272

7373
resultSpanAttributes := traces.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes()
@@ -85,7 +85,7 @@ func TestResourceAttributesAdjuster_SpanWithConflictingLibraryAttributes(t *test
8585
span.Attributes().PutStr("random_key", "random_value")
8686
span.Attributes().PutStr(string(otelsemconv.TelemetrySDKLanguageKey), "Java")
8787

88-
adjuster := ResourceAttributes()
88+
adjuster := MoveLibraryAttributes()
8989
adjuster.Adjust(traces)
9090

9191
resultSpan := traces.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0)
@@ -119,7 +119,7 @@ func TestResourceAttributesAdjuster_SpanWithNonConflictingLibraryAttributes(t *t
119119
span.Attributes().PutStr("random_key", "random_value")
120120
span.Attributes().PutStr(string(otelsemconv.TelemetrySDKLanguageKey), "Go")
121121

122-
adjuster := ResourceAttributes()
122+
adjuster := MoveLibraryAttributes()
123123
adjuster.Adjust(traces)
124124

125125
resultSpanAttributes := traces.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes()

cmd/query/app/querysvc/adjuster/sort.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212

1313
var _ Adjuster = (*SortAttributesAndEventsAdjuster)(nil)
1414

15-
// SortAttributesAndEvents creates an adjuster that standardizes trace data by sorting elements:
15+
// SortCollections creates an adjuster that standardizes trace data by sorting elements:
1616
// - Resource attributes are sorted lexicographically by their keys.
1717
// - Scope attributes are sorted lexicographically by their keys.
1818
// - Span attributes are sorted lexicographically by their keys.
1919
// - Span events are sorted lexicographically by their names.
2020
// - Attributes within each span event are sorted lexicographically by their keys.
2121
// - Attributes within each span link are sorted lexicographically by their keys.
22-
func SortAttributesAndEvents() SortAttributesAndEventsAdjuster {
22+
func SortCollections() SortAttributesAndEventsAdjuster {
2323
return SortAttributesAndEventsAdjuster{}
2424
}
2525

cmd/query/app/querysvc/adjuster/sort_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestSortAttributesAndEventsAdjuster(t *testing.T) {
14-
adjuster := SortAttributesAndEvents()
14+
adjuster := SortCollections()
1515
input := func() ptrace.Traces {
1616
traces := ptrace.NewTraces()
1717
rs := traces.ResourceSpans().AppendEmpty()

0 commit comments

Comments
 (0)