Skip to content

Commit

Permalink
remove TimestampTime column
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres committed Sep 12, 2024
1 parent 58f33d3 commit 6978697
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion exporter/clickhouseexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ SELECT Timestamp as log_time,
toString(Links.TraceId)
FROM otel_traces
WHERE ServiceName = 'clickhouse-exporter'
AND StatusCode = 'STATUS_CODE_ERROR'
AND StatusCode = 'Error'
AND Timestamp >= NOW() - INTERVAL 1 HOUR
Limit 100;
```
Expand Down
13 changes: 6 additions & 7 deletions exporter/clickhouseexporter/example/default_ddl/traces.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

CREATE TABLE IF NOT EXISTS otel_traces (
Timestamp DateTime64(9) CODEC(Delta, ZSTD(1)),
TimestampTime DateTime DEFAULT toDateTime(Timestamp),
TraceId String CODEC(ZSTD(1)),
SpanId String CODEC(ZSTD(1)),
ParentSpanId String CODEC(ZSTD(1)),
Expand Down Expand Up @@ -35,10 +34,9 @@ CREATE TABLE IF NOT EXISTS otel_traces (
INDEX idx_span_attr_value mapValues(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_duration Duration TYPE minmax GRANULARITY 1
) ENGINE = MergeTree()
PARTITION BY toDate(TimestampTime)
PRIMARY KEY (ServiceName, SpanName, TimestampTime)
ORDER BY (ServiceName, SpanName, TimestampTime, Timestamp, TraceId)
TTL TimestampTime + toIntervalDay(180)
PARTITION BY toDate(Timestamp)
ORDER BY (ServiceName, SpanName, Timestamp)
TTL toDateTime(Timestamp) + toIntervalDay(180)
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1;


Expand All @@ -48,9 +46,10 @@ CREATE TABLE IF NOT EXISTS otel_traces_trace_id_ts (
End DateTime64(9) CODEC(Delta, ZSTD(1)),
INDEX idx_trace_id TraceId TYPE bloom_filter(0.01) GRANULARITY 1
) ENGINE = MergeTree()
ORDER BY (TraceId, toUnixTimestamp(Start))
PARTITION BY toDate(Start)
ORDER BY (Start)
TTL toDateTime(Start) + toIntervalDay(180)
SETTINGS index_granularity=8192;
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1;


CREATE MATERIALIZED VIEW IF NOT EXISTS otel_traces_trace_id_ts_mv
Expand Down
26 changes: 13 additions & 13 deletions exporter/clickhouseexporter/exporter_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ const (
createTracesTableSQL = `
CREATE TABLE IF NOT EXISTS %s %s (
Timestamp DateTime64(9) CODEC(Delta, ZSTD(1)),
TimestampTime DateTime DEFAULT toDateTime(Timestamp),
TraceId String CODEC(ZSTD(1)),
SpanId String CODEC(ZSTD(1)),
ParentSpanId String CODEC(ZSTD(1)),
Expand Down Expand Up @@ -197,9 +196,9 @@ CREATE TABLE IF NOT EXISTS %s %s (
INDEX idx_span_attr_value mapValues(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_duration Duration TYPE minmax GRANULARITY 1
) ENGINE = %s
PARTITION BY toDate(TimestampTime)
PRIMARY KEY (ServiceName, SpanName, TimestampTime)
ORDER BY (ServiceName, SpanName, TimestampTime, Timestamp, TraceId)
PARTITION BY toDate(Timestamp)
PRIMARY KEY (ServiceName, SpanName, Timestamp)
ORDER BY (ServiceName, SpanName, Timestamp)
%s
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1;
`
Expand Down Expand Up @@ -255,26 +254,27 @@ SETTINGS index_granularity=8192, ttl_only_drop_parts = 1;

const (
createTraceIDTsTableSQL = `
create table IF NOT EXISTS %s_trace_id_ts %s (
CREATE TABLE IF NOT EXISTS %s_trace_id_ts %s (
TraceId String CODEC(ZSTD(1)),
Start DateTime64(9) CODEC(Delta, ZSTD(1)),
End DateTime64(9) CODEC(Delta, ZSTD(1)),
INDEX idx_trace_id TraceId TYPE bloom_filter(0.01) GRANULARITY 1
) ENGINE = %s
PARTITION BY toDate(Start)
ORDER BY (TraceId, Start)
%s
ORDER BY (TraceId, toUnixTimestamp(Start))
SETTINGS index_granularity=8192;
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1;
`
createTraceIDTsMaterializedViewSQL = `
CREATE MATERIALIZED VIEW IF NOT EXISTS %s_trace_id_ts_mv %s
TO %s.%s_trace_id_ts
AS SELECT
TraceId,
min(Timestamp) as Start,
max(Timestamp) as End
TraceId,
min(Timestamp) as Start,
max(Timestamp) as End
FROM
%s.%s
WHERE TraceId!=''
WHERE TraceId != ''
GROUP BY TraceId;
`
)
Expand All @@ -284,10 +284,10 @@ func createTracesTable(ctx context.Context, cfg *Config, db *sql.DB) error {
return fmt.Errorf("exec create traces table sql: %w", err)
}
if _, err := db.ExecContext(ctx, renderCreateTraceIDTsTableSQL(cfg)); err != nil {
return fmt.Errorf("exec create traceIDTs table sql: %w", err)
return fmt.Errorf("exec create traceID timestamp table sql: %w", err)
}
if _, err := db.ExecContext(ctx, renderTraceIDTsMaterializedViewSQL(cfg)); err != nil {
return fmt.Errorf("exec create traceIDTs view sql: %w", err)
return fmt.Errorf("exec create traceID timestamp view sql: %w", err)
}
return nil
}
Expand Down

0 comments on commit 6978697

Please sign in to comment.