Skip to content

Commit 23c2f95

Browse files
committed
fix: fixed issue with filtering not functioning for start_time
1 parent cbae55a commit 23c2f95

File tree

7 files changed

+211
-105
lines changed

7 files changed

+211
-105
lines changed

internal/sql/manual.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

internal/sql/query.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,22 @@ WHERE spans.start_time < sqlc.arg(prune_before)::TIMESTAMP;
127127
-- name: GetSpansDiskSize :one
128128

129129
SELECT pg_total_relation_size('spans');
130+
131+
-- name: GetSpansCount :one
132+
133+
SELECT COUNT(*) FROM spans;
134+
135+
-- name: FindTraceIDs :many
136+
137+
SELECT DISTINCT spans.trace_id as trace_id
138+
FROM spans
139+
INNER JOIN operations ON (operations.id = spans.operation_id)
140+
INNER JOIN services ON (services.id = spans.service_id)
141+
WHERE
142+
(services.name = sqlc.arg(service_name)::VARCHAR OR sqlc.arg(service_name_enable_filter)::BOOLEAN = FALSE) AND
143+
(operations.name = sqlc.arg(operation_name)::VARCHAR OR sqlc.arg(operation_name_enable_filter)::BOOLEAN = FALSE) AND
144+
(start_time >= sqlc.arg(start_time_minimum)::TIMESTAMP OR sqlc.arg(start_time_minimum_enable_filter)::BOOLEAN = FALSE) AND
145+
(start_time <= sqlc.arg(start_time_maximum)::TIMESTAMP OR sqlc.arg(start_time_maximum_enable_filter)::BOOLEAN = FALSE) AND
146+
(duration >= sqlc.arg(duration_minimum)::INTERVAL OR sqlc.arg(duration_minimum_enable_filter)::BOOLEAN = FALSE) AND
147+
(duration <= sqlc.arg(duration_maximum)::INTERVAL OR sqlc.arg(duration_maximum_enable_filter)::BOOLEAN = FALSE)
148+
LIMIT sqlc.arg(num_traces);

internal/sql/query.sql.go

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/sql/query_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ func TestGetOperations(t *testing.T) {
1717
conn, cleanup := sqltest.Harness(t)
1818
q := sql.New(conn)
1919

20+
defer conn.Close(context.Background())
21+
2022
t.Run("should return nothing when no operations exist", func(t *testing.T) {
2123
require.Nil(t, cleanup())
2224

@@ -79,6 +81,8 @@ func TestGetServices(t *testing.T) {
7981
conn, cleanup := sqltest.Harness(t)
8082
q := sql.New(conn)
8183

84+
defer conn.Close(context.Background())
85+
8286
t.Run("should return nothing when no services exist", func(t *testing.T) {
8387
require.Nil(t, cleanup())
8488

@@ -111,6 +115,8 @@ func TestSpans(t *testing.T) {
111115
conn, cleanup := sqltest.Harness(t)
112116
q := sql.New(conn)
113117

118+
defer conn.Close(context.Background())
119+
114120
t.Run("should be able to write a span", func(t *testing.T) {
115121
require.Nil(t, cleanup())
116122

@@ -186,4 +192,79 @@ func TestSpans(t *testing.T) {
186192
_ = queried
187193

188194
})
195+
196+
t.Run("should be able to write a span", func(t *testing.T) {
197+
require.Nil(t, cleanup())
198+
199+
err := q.UpsertService(ctx, "service-1")
200+
require.Nil(t, err)
201+
202+
serviceID, err := q.GetServiceID(ctx, "service-1")
203+
require.Nil(t, err)
204+
205+
err = q.UpsertOperation(ctx, sql.UpsertOperationParams{Name: "operation-1", ServiceID: serviceID, Kind: sql.SpankindClient})
206+
require.Nil(t, err)
207+
208+
operationID, err := q.GetOperationID(ctx, sql.GetOperationIDParams{Name: "operation-1", ServiceID: serviceID, Kind: sql.SpankindClient})
209+
require.Nil(t, err)
210+
211+
_, err = q.InsertSpan(ctx, sql.InsertSpanParams{
212+
SpanID: []byte{0, 0, 0, 1},
213+
TraceID: []byte{0, 0, 0, 0},
214+
OperationID: operationID,
215+
Flags: 0,
216+
StartTime: pgtype.Timestamp{Time: time.Now(), Valid: true},
217+
Duration: pgtype.Interval{Microseconds: 1000, Valid: true},
218+
Tags: []byte("[]"),
219+
ServiceID: serviceID,
220+
ProcessID: "",
221+
ProcessTags: []byte("[]"),
222+
Warnings: []string{},
223+
Kind: sql.SpankindClient,
224+
Logs: []byte("null"),
225+
Refs: []byte("[]"),
226+
})
227+
require.Nil(t, err)
228+
229+
_, err = q.InsertSpan(ctx, sql.InsertSpanParams{
230+
SpanID: []byte{0, 0, 0, 0},
231+
TraceID: []byte{0, 0, 0, 1},
232+
OperationID: operationID,
233+
Flags: 0,
234+
StartTime: pgtype.Timestamp{Time: time.Now(), Valid: true},
235+
Duration: pgtype.Interval{Microseconds: 1000, Valid: true},
236+
Tags: []byte("[]"),
237+
ServiceID: serviceID,
238+
ProcessID: "",
239+
ProcessTags: []byte("null"),
240+
Warnings: []string{},
241+
Kind: sql.SpankindClient,
242+
Logs: []byte("null"),
243+
Refs: []byte("[]"),
244+
})
245+
require.Nil(t, err)
246+
247+
_, err = q.InsertSpan(ctx, sql.InsertSpanParams{
248+
SpanID: []byte{0, 0, 0, 0},
249+
TraceID: []byte{0, 0, 0, 2},
250+
OperationID: operationID,
251+
Flags: 0,
252+
StartTime: pgtype.Timestamp{Time: time.Now(), Valid: true},
253+
Duration: pgtype.Interval{Microseconds: 1000, Valid: true},
254+
Tags: []byte("[]"),
255+
ServiceID: serviceID,
256+
ProcessID: "",
257+
ProcessTags: []byte("[]"),
258+
Warnings: []string{},
259+
Kind: sql.SpankindClient,
260+
Logs: []byte("null"),
261+
Refs: []byte("[]"),
262+
})
263+
require.Nil(t, err)
264+
265+
queried, err := q.FindTraceIDs(ctx, sql.FindTraceIDsParams{NumTraces: 1})
266+
require.Nil(t, err)
267+
268+
require.Len(t, queried, 1)
269+
})
189270
}

internal/sqltest/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func getDatabaseURL() string {
3838
return url
3939
}
4040

41-
return "postgres://postgres:password@localhost:5432/jaeger"
41+
return "postgres://postgres:password@localhost:5432/jaegertest"
4242
}
4343

4444
// Harness provides a test harness

internal/store/integration_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func TestJaegerStorageIntegration(t *testing.T) {
2020
conn, cleanup := sqltest.Harness(t)
2121
require.Nil(t, cleanup())
2222

23+
defer conn.Close(context.Background())
24+
2325
q := sql.New(conn)
2426

2527
logger := slog.Default()
@@ -34,6 +36,7 @@ func TestJaegerStorageIntegration(t *testing.T) {
3436
Refresh: func() error { return nil },
3537
SkipList: []string{},
3638
}
39+
3740
// Runs all storage integration tests.
3841
si.IntegrationTestAll(t)
3942
}
@@ -43,6 +46,9 @@ func TestSpans(t *testing.T) {
4346
require.Nil(t, cleanup())
4447

4548
ctx := context.Background()
49+
50+
defer conn.Close(ctx)
51+
4652
q := sql.New(conn)
4753

4854
require.Nil(t, cleanup())

0 commit comments

Comments
 (0)