-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[clickhouse] Update FindTraceIDs to populate start and end timestamps #7770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a83df4b
Update SearchTraceIDs Query To Join on trace_id_timestamps
mahadzaryab1 23105c1
Update Reader To Populate Start and End For TraceIDs
mahadzaryab1 4daaccd
Update Unit Tests
mahadzaryab1 578a631
Add Zero Times
mahadzaryab1 d4c11c1
Format
mahadzaryab1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,18 @@ var ( | |
| MaxSearchDepth: 1000, | ||
| } | ||
| testSearchTraceIDsQuery = sql.SearchTraceIDs + " LIMIT ?" | ||
| testTraceIDsData = [][]any{ | ||
| { | ||
| traceIDHex1, | ||
| now.Add(-1 * time.Hour), | ||
| now, | ||
| }, | ||
| { | ||
| traceIDHex2, | ||
| time.Time{}, | ||
| time.Time{}, | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| func scanSpanRowFn() func(dest any, src *dbmodel.SpanRow) error { | ||
|
|
@@ -118,22 +130,35 @@ func scanSpanRowFn() func(dest any, src *dbmodel.SpanRow) error { | |
| } | ||
| } | ||
|
|
||
| func scanTraceIDFn() func(dest any, src string) error { | ||
| return func(dest any, src string) error { | ||
| func scanTraceIDFn() func(dest any, src []any) error { | ||
| return func(dest any, src []any) error { | ||
| ptrs, ok := dest.([]any) | ||
| if !ok { | ||
| return fmt.Errorf("expected []any for dest, got %T", dest) | ||
| } | ||
| if len(ptrs) != 1 { | ||
| return fmt.Errorf("expected 1 destination argument, got %d", len(ptrs)) | ||
| if len(ptrs) != 3 { | ||
| fmt.Println(src) | ||
| return fmt.Errorf("expected 3 destination arguments, got %d", len(ptrs)) | ||
| } | ||
|
|
||
| ptr, ok := ptrs[0].(*string) | ||
| if !ok { | ||
| return fmt.Errorf("expected *string for dest[0], got %T", ptrs[0]) | ||
| } | ||
|
|
||
| *ptr = src | ||
| startPtr, ok := ptrs[1].(*time.Time) | ||
| if !ok { | ||
| return fmt.Errorf("expected *time.Time for dest[1], got %T", ptrs[1]) | ||
| } | ||
|
|
||
| endPtr, ok := ptrs[2].(*time.Time) | ||
| if !ok { | ||
| return fmt.Errorf("expected *time.Time for dest[2], got %T", ptrs[2]) | ||
| } | ||
|
|
||
| *ptr = src[0].(string) | ||
| *startPtr = src[1].(time.Time) | ||
| *endPtr = src[2].(time.Time) | ||
| return nil | ||
| } | ||
| } | ||
|
|
@@ -518,15 +543,16 @@ func TestFindTraces(t *testing.T) { | |
| func TestFindTraceIDs(t *testing.T) { | ||
| driver := &testDriver{ | ||
| t: t, | ||
| expectedQuery: `SELECT DISTINCT trace_id FROM spans WHERE 1=1 ` + | ||
| `AND service_name = ? AND name = ? ` + | ||
| `AND duration >= ? AND duration <= ? ` + | ||
| `LIMIT ?`, | ||
| rows: &testRows[string]{ | ||
| data: []string{ | ||
| "00000000000000000000000000000001", | ||
| "00000000000000000000000000000002", | ||
| }, | ||
| expectedQuery: ` | ||
| SELECT DISTINCT | ||
| s.trace_id, | ||
| t.start, | ||
| t.end | ||
| FROM spans s | ||
| LEFT JOIN trace_id_timestamps t ON s.trace_id = t.trace_id | ||
| WHERE 1=1 AND s.service_name = ? AND s.name = ? AND s.duration >= ? AND s.duration <= ? LIMIT ?`, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is it that you don't have time bounds on the search? Time range (lookback) is the mandatory query condition
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going to do this in the next PR |
||
| rows: &testRows[[]any]{ | ||
| data: testTraceIDsData, | ||
| scanFn: scanTraceIDFn(), | ||
| }, | ||
| } | ||
|
|
@@ -543,6 +569,8 @@ func TestFindTraceIDs(t *testing.T) { | |
| require.Equal(t, []tracestore.FoundTraceID{ | ||
| { | ||
| TraceID: pcommon.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), | ||
| Start: now.Add(-1 * time.Hour), | ||
| End: now, | ||
| }, | ||
| { | ||
| TraceID: pcommon.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}), | ||
|
|
@@ -554,10 +582,18 @@ func TestFindTraceIDs_SearchDepthExceedsMax(t *testing.T) { | |
| driver := &testDriver{ | ||
| t: t, | ||
| expectedQuery: testSearchTraceIDsQuery, | ||
| rows: &testRows[string]{ | ||
| data: []string{ | ||
| "00000000000000000000000000000001", | ||
| "00000000000000000000000000000002", | ||
| rows: &testRows[[]any]{ | ||
| data: [][]any{ | ||
| { | ||
| "00000000000000000000000000000001", | ||
| time.Now().Add(-1 * time.Hour), | ||
| time.Now().Add(-1 * time.Minute), | ||
| }, | ||
| { | ||
| "00000000000000000000000000000002", | ||
| time.Now().Add(-2 * time.Hour), | ||
| time.Now().Add(-2 * time.Minute), | ||
| }, | ||
| }, | ||
| scanFn: scanTraceIDFn(), | ||
| }, | ||
|
|
@@ -574,11 +610,8 @@ func TestFindTraceIDs_YieldFalseOnSuccessStopsIteration(t *testing.T) { | |
| conn := &testDriver{ | ||
| t: t, | ||
| expectedQuery: testSearchTraceIDsQuery, | ||
| rows: &testRows[string]{ | ||
| data: []string{ | ||
| "00000000000000000000000000000001", | ||
| "00000000000000000000000000000002", | ||
| }, | ||
| rows: &testRows[[]any]{ | ||
| data: testTraceIDsData, | ||
| scanFn: scanTraceIDFn(), | ||
| }, | ||
| } | ||
|
|
@@ -597,14 +630,16 @@ func TestFindTraceIDs_YieldFalseOnSuccessStopsIteration(t *testing.T) { | |
| require.Equal(t, []tracestore.FoundTraceID{ | ||
| { | ||
| TraceID: pcommon.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), | ||
| Start: now.Add(-1 * time.Hour), | ||
| End: now, | ||
| }, | ||
| }, gotTraceIDs) | ||
| } | ||
|
|
||
| func TestFindTraceIDs_ScanErrorContinues(t *testing.T) { | ||
| scanCalled := 0 | ||
|
|
||
| scanFn := func(dest any, src string) error { | ||
| scanFn := func(dest any, src []any) error { | ||
| scanCalled++ | ||
| if scanCalled == 1 { | ||
| return assert.AnError // simulate scan error on the first row | ||
|
|
@@ -615,11 +650,8 @@ func TestFindTraceIDs_ScanErrorContinues(t *testing.T) { | |
| conn := &testDriver{ | ||
| t: t, | ||
| expectedQuery: testSearchTraceIDsQuery, | ||
| rows: &testRows[string]{ | ||
| data: []string{ | ||
| "00000000000000000000000000000001", | ||
| "00000000000000000000000000000002", | ||
| }, | ||
| rows: &testRows[[]any]{ | ||
| data: testTraceIDsData, | ||
| scanFn: scanFn, | ||
| }, | ||
| } | ||
|
|
@@ -646,12 +678,20 @@ func TestFindTraceIDs_DecodeErrorContinues(t *testing.T) { | |
| conn := &testDriver{ | ||
| t: t, | ||
| expectedQuery: testSearchTraceIDsQuery, | ||
| rows: &testRows[string]{ | ||
| data: []string{ | ||
| "00000000000000000000000000000001", | ||
| "0x", | ||
| "invalid", | ||
| "00000000000000000000000000000002", | ||
| rows: &testRows[[]any]{ | ||
| data: [][]any{ | ||
| testTraceIDsData[0], | ||
| { | ||
| "0x", | ||
| time.Now().Add(-2 * time.Hour), | ||
| time.Now().Add(-2 * time.Minute), | ||
| }, | ||
| { | ||
| "invalid", | ||
| time.Now().Add(-3 * time.Hour), | ||
| time.Now().Add(-3 * time.Minute), | ||
| }, | ||
| testTraceIDsData[1], | ||
| }, | ||
| scanFn: scanTraceIDFn(), | ||
| }, | ||
|
|
@@ -663,6 +703,8 @@ func TestFindTraceIDs_DecodeErrorContinues(t *testing.T) { | |
| expectedValidTraceIDs := []tracestore.FoundTraceID{ | ||
| { | ||
| TraceID: pcommon.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), | ||
| Start: now.Add(-1 * time.Hour), | ||
| End: now, | ||
| }, | ||
| { | ||
| TraceID: pcommon.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}), | ||
|
|
@@ -705,8 +747,8 @@ func TestFindTraceIDs_ErrorCases(t *testing.T) { | |
| driver: &testDriver{ | ||
| t: t, | ||
| expectedQuery: testSearchTraceIDsQuery, | ||
| rows: &testRows[string]{ | ||
| data: []string{"0000000000000001", "0000000000000002"}, | ||
| rows: &testRows[[]any]{ | ||
| data: testTraceIDsData, | ||
| scanErr: assert.AnError, | ||
| }, | ||
| }, | ||
|
|
@@ -717,8 +759,14 @@ func TestFindTraceIDs_ErrorCases(t *testing.T) { | |
| driver: &testDriver{ | ||
| t: t, | ||
| expectedQuery: testSearchTraceIDsQuery, | ||
| rows: &testRows[string]{ | ||
| data: []string{"0x"}, | ||
| rows: &testRows[[]any]{ | ||
| data: [][]any{ | ||
| { | ||
| "0x", | ||
| time.Now().Add(-1 * time.Hour), | ||
| time.Now().Add(-1 * time.Minute), | ||
| }, | ||
| }, | ||
| scanFn: scanTraceIDFn(), | ||
| }, | ||
| }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yurishkuro Thoughts on a LEFT JOIN vs. an INNER JOIN? A LEFT JOIN could return some null timestamps in between updates whereas an INNER JOIN could result in some trace_ids not being returned in between updates.