diff --git a/internal/storage/v2/clickhouse/factory.go b/internal/storage/v2/clickhouse/factory.go index 959cc0b6948..e67a1f9296f 100644 --- a/internal/storage/v2/clickhouse/factory.go +++ b/internal/storage/v2/clickhouse/factory.go @@ -73,6 +73,8 @@ func NewFactory(ctx context.Context, cfg Configuration, telset telemetry.Setting {"services materialized view", sql.CreateServicesMaterializedView}, {"operations table", sql.CreateOperationsTable}, {"operations materialized view", sql.CreateOperationsMaterializedView}, + {"trace id timestamps table", sql.CreateTraceIDTimestampsTable}, + {"trace id timestamps materialized view", sql.CreateTraceIDTimestampsMaterializedView}, } for _, schema := range schemas { diff --git a/internal/storage/v2/clickhouse/factory_test.go b/internal/storage/v2/clickhouse/factory_test.go index 43718702aa0..d2678d9a59b 100644 --- a/internal/storage/v2/clickhouse/factory_test.go +++ b/internal/storage/v2/clickhouse/factory_test.go @@ -125,6 +125,20 @@ func TestNewFactory_Errors(t *testing.T) { }, expectedError: "failed to create operations materialized view", }, + { + name: "trace id timestamps table creation error", + failureConfig: clickhousetest.FailureConfig{ + sql.CreateTraceIDTimestampsTable: errors.New("trace id timestamps table creation error"), + }, + expectedError: "failed to create trace id timestamps table", + }, + { + name: "trace id timestamps materialized view creation error", + failureConfig: clickhousetest.FailureConfig{ + sql.CreateTraceIDTimestampsMaterializedView: errors.New("trace id timestamps materialized view creation error"), + }, + expectedError: "failed to create trace id timestamps materialized view", + }, } for _, tt := range tests { diff --git a/internal/storage/v2/clickhouse/sql/create_services_mv.sql b/internal/storage/v2/clickhouse/sql/create_services_mv.sql index 8f96f16b8c3..6a55b1b2e6a 100644 --- a/internal/storage/v2/clickhouse/sql/create_services_mv.sql +++ b/internal/storage/v2/clickhouse/sql/create_services_mv.sql @@ -4,4 +4,4 @@ SELECT FROM spans GROUP BY - service_name \ No newline at end of file + service_name; \ No newline at end of file diff --git a/internal/storage/v2/clickhouse/sql/create_trace_id_timestamps_mv.sql b/internal/storage/v2/clickhouse/sql/create_trace_id_timestamps_mv.sql new file mode 100644 index 00000000000..a47463f0870 --- /dev/null +++ b/internal/storage/v2/clickhouse/sql/create_trace_id_timestamps_mv.sql @@ -0,0 +1,9 @@ +CREATE MATERIALIZED VIEW IF NOT EXISTS trace_id_timestamps_mv +TO trace_id_timestamps +AS +SELECT + trace_id, + min(start_time) AS start, + max(start_time) AS end +FROM spans +GROUP BY trace_id; \ No newline at end of file diff --git a/internal/storage/v2/clickhouse/sql/create_trace_id_timestamps_table.sql b/internal/storage/v2/clickhouse/sql/create_trace_id_timestamps_table.sql new file mode 100644 index 00000000000..bfb8a28032c --- /dev/null +++ b/internal/storage/v2/clickhouse/sql/create_trace_id_timestamps_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS trace_id_timestamps +( + trace_id String, + start DateTime64(9), + end DateTime64(9) +) +ENGINE = MergeTree() +ORDER BY (trace_id); \ No newline at end of file diff --git a/internal/storage/v2/clickhouse/sql/queries.go b/internal/storage/v2/clickhouse/sql/queries.go index 2dc05de21b6..fe7bce4ea88 100644 --- a/internal/storage/v2/clickhouse/sql/queries.go +++ b/internal/storage/v2/clickhouse/sql/queries.go @@ -254,3 +254,9 @@ var CreateOperationsTable string //go:embed create_operations_mv.sql var CreateOperationsMaterializedView string + +//go:embed create_trace_id_timestamps_table.sql +var CreateTraceIDTimestampsTable string + +//go:embed create_trace_id_timestamps_mv.sql +var CreateTraceIDTimestampsMaterializedView string