-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/clickhouse] Upgrade trace table (#34245)
This PR updates the default `otel_traces` table schema. There are no breaking changes, this schema is compatible with the previous `INSERT` statement. This does not affect existing users, only new users that have `create_schema` enabled in the config. Notable changes: - Optimized ORDER BY to use a 32 bit DateTime without TraceId - Reduced DateTime64(9) to DateTime on the trace timestamp table - TTLs now use Date instead of DateTime since parts will only be dropped on the partition date No major column changes for now, but there were some small performance benefits observed with these changes. As always, it is best to edit these tables to fit your needs and query patterns. I expect further changes in the future as we continue to optimize this table for a generalized use case. **Testing:** Integration tests are disabled, but I enabled them locally to test that this change works as intended. Unit tests are passing as well. **Documentation:** - Updated README - Example DDL has been updated, and now includes the trace timestamp table and materialized view --------- Co-authored-by: Dmitrii Anoshin <[email protected]>
- Loading branch information
1 parent
e6274cd
commit 1620fc6
Showing
5 changed files
with
137 additions
and
88 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: clickhouseexporter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Updated the default trace table | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [34245] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: Reduced data types, improved partitioning and time range queries | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
This file contains 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
91 changes: 57 additions & 34 deletions
91
exporter/clickhouseexporter/example/default_ddl/traces.sql
This file contains 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 |
---|---|---|
@@ -1,40 +1,63 @@ | ||
-- Default Trace table DDL | ||
|
||
CREATE TABLE IF NOT EXISTS otel_traces ( | ||
Timestamp DateTime64(9) CODEC(Delta, ZSTD(1)), | ||
TraceId String CODEC(ZSTD(1)), | ||
SpanId String CODEC(ZSTD(1)), | ||
ParentSpanId String CODEC(ZSTD(1)), | ||
TraceState String CODEC(ZSTD(1)), | ||
SpanName LowCardinality(String) CODEC(ZSTD(1)), | ||
SpanKind LowCardinality(String) CODEC(ZSTD(1)), | ||
ServiceName LowCardinality(String) CODEC(ZSTD(1)), | ||
ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
ScopeName String CODEC(ZSTD(1)), | ||
ScopeVersion String CODEC(ZSTD(1)), | ||
SpanAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
Duration Int64 CODEC(ZSTD(1)), | ||
StatusCode LowCardinality(String) CODEC(ZSTD(1)), | ||
StatusMessage String CODEC(ZSTD(1)), | ||
Events Nested ( | ||
Timestamp DateTime64(9), | ||
Name LowCardinality(String), | ||
Attributes Map(LowCardinality(String), String) | ||
) CODEC(ZSTD(1)), | ||
Links Nested ( | ||
TraceId String, | ||
SpanId String, | ||
TraceState String, | ||
Attributes Map(LowCardinality(String), String) | ||
) CODEC(ZSTD(1)), | ||
INDEX idx_trace_id TraceId TYPE bloom_filter(0.001) GRANULARITY 1, | ||
INDEX idx_res_attr_key mapKeys(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_res_attr_value mapValues(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_span_attr_key mapKeys(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_span_attr_value mapValues(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_duration Duration TYPE minmax GRANULARITY 1 | ||
Timestamp DateTime64(9) CODEC(Delta, ZSTD(1)), | ||
TraceId String CODEC(ZSTD(1)), | ||
SpanId String CODEC(ZSTD(1)), | ||
ParentSpanId String CODEC(ZSTD(1)), | ||
TraceState String CODEC(ZSTD(1)), | ||
SpanName LowCardinality(String) CODEC(ZSTD(1)), | ||
SpanKind LowCardinality(String) CODEC(ZSTD(1)), | ||
ServiceName LowCardinality(String) CODEC(ZSTD(1)), | ||
ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
ScopeName String CODEC(ZSTD(1)), | ||
ScopeVersion String CODEC(ZSTD(1)), | ||
SpanAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
Duration UInt64 CODEC(ZSTD(1)), | ||
StatusCode LowCardinality(String) CODEC(ZSTD(1)), | ||
StatusMessage String CODEC(ZSTD(1)), | ||
Events Nested ( | ||
Timestamp DateTime64(9), | ||
Name LowCardinality(String), | ||
Attributes Map(LowCardinality(String), String) | ||
) CODEC(ZSTD(1)), | ||
Links Nested ( | ||
TraceId String, | ||
SpanId String, | ||
TraceState String, | ||
Attributes Map(LowCardinality(String), String) | ||
) CODEC(ZSTD(1)), | ||
INDEX idx_trace_id TraceId TYPE bloom_filter(0.001) GRANULARITY 1, | ||
INDEX idx_res_attr_key mapKeys(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_res_attr_value mapValues(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_span_attr_key mapKeys(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_span_attr_value mapValues(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_duration Duration TYPE minmax GRANULARITY 1 | ||
) ENGINE = MergeTree() | ||
TTL toDateTime("Timestamp") + toIntervalDay(180) | ||
PARTITION BY toDate(Timestamp) | ||
ORDER BY (ServiceName, SpanName, toUnixTimestamp(Timestamp), TraceId) | ||
ORDER BY (ServiceName, SpanName, toDateTime(Timestamp)) | ||
TTL toDate(Timestamp) + toIntervalDay(180) | ||
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1; | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS otel_traces_trace_id_ts ( | ||
TraceId String CODEC(ZSTD(1)), | ||
Start DateTime CODEC(Delta, ZSTD(1)), | ||
End DateTime CODEC(Delta, ZSTD(1)), | ||
INDEX idx_trace_id TraceId TYPE bloom_filter(0.01) GRANULARITY 1 | ||
) ENGINE = MergeTree() | ||
PARTITION BY toDate(Start) | ||
ORDER BY (TraceId, Start) | ||
TTL toDate(Start) + toIntervalDay(180) | ||
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1; | ||
|
||
|
||
CREATE MATERIALIZED VIEW IF NOT EXISTS otel_traces_trace_id_ts_mv | ||
TO otel_traces_trace_id_ts | ||
AS SELECT | ||
TraceId, | ||
min(Timestamp) as Start, | ||
max(Timestamp) as End | ||
FROM otel_traces | ||
WHERE TraceId != '' | ||
GROUP BY TraceId; |
This file contains 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 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