-
Notifications
You must be signed in to change notification settings - Fork 382
feat(clickhouse): add service_logs migration for internal service logs #3455
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
Draft
rguliyev
wants to merge
2
commits into
main
Choose a base branch
from
feat/internal-loki-clickhouse
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
81 changes: 81 additions & 0 deletions
81
packages/clickhouse/migrations/20260730090000_add_service_logs.sql
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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| -- Creates the service_logs table for internal (platform service) logs written | ||
| -- by the OTel collectors' clickhouse exporter (terraform: | ||
| -- enable_clickhouse_logs, logs_table_name: service_logs). | ||
| -- | ||
| -- The column set, indexes, partitioning and sort key mirror the exporter's own | ||
| -- create_schema DDL for opentelemetry-collector-contrib v0.146.0 exactly | ||
| -- (exporter/clickhouseexporter/internal/sqltemplates/logs_table.sql), because | ||
| -- the exporter INSERTs a fixed column list against this table with | ||
| -- create_schema disabled. The exporter introspects optional columns (EventName) | ||
| -- at startup, so keeping the full set is both required and forward-compatible. | ||
| -- | ||
| -- On top of the upstream DDL this migration owns what create_schema never set: | ||
| -- a retention TTL and the Distributed wrapper (the cluster name is rewritten | ||
| -- by the migrator job on deployments that use a different cluster name). | ||
| -- | ||
| -- ClickHouse has no transactional DDL and goose records the version only after | ||
| -- every statement succeeds, so each statement is written to be safely | ||
| -- re-runnable. The DROPs remove any leftover plain MergeTree otel_logs (the | ||
| -- exporter's default table name) previously created by a collector running | ||
| -- with create_schema enabled (staging validation data, intentionally | ||
| -- discarded), plus any partially created service_logs from a failed attempt. | ||
|
|
||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
| DROP TABLE IF EXISTS otel_logs; | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose StatementBegin | ||
| DROP TABLE IF EXISTS service_logs; | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose StatementBegin | ||
| CREATE TABLE IF NOT EXISTS service_logs_local ( | ||
| `Timestamp` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `TimestampTime` DateTime DEFAULT toDateTime(Timestamp), | ||
| `TraceId` String CODEC(ZSTD(1)), | ||
| `SpanId` String CODEC(ZSTD(1)), | ||
| `TraceFlags` UInt8, | ||
| `SeverityText` LowCardinality(String) CODEC(ZSTD(1)), | ||
| `SeverityNumber` UInt8, | ||
| `ServiceName` LowCardinality(String) CODEC(ZSTD(1)), | ||
| `Body` String CODEC(ZSTD(1)), | ||
| `ResourceSchemaUrl` LowCardinality(String) CODEC(ZSTD(1)), | ||
| `ResourceAttributes` Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
| `ScopeSchemaUrl` LowCardinality(String) CODEC(ZSTD(1)), | ||
| `ScopeName` String CODEC(ZSTD(1)), | ||
| `ScopeVersion` LowCardinality(String) CODEC(ZSTD(1)), | ||
| `ScopeAttributes` Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
| `LogAttributes` Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
| `EventName` 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_scope_attr_key mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_scope_attr_value mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_log_attr_key mapKeys(LogAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_log_attr_value mapValues(LogAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_body Body TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 8 | ||
| ) ENGINE = MergeTree | ||
| PARTITION BY toDate(TimestampTime) | ||
| PRIMARY KEY (ServiceName, TimestampTime) | ||
| ORDER BY (ServiceName, TimestampTime, Timestamp) | ||
| TTL TimestampTime + toIntervalDay(30) | ||
| SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1; | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose StatementBegin | ||
| -- Internal logs carry no tenant key, so rows are spread randomly; queries | ||
| -- filter on ServiceName/time and fan out to all shards either way. | ||
| CREATE TABLE IF NOT EXISTS service_logs AS service_logs_local | ||
| ENGINE = Distributed('cluster', currentDatabase(), 'service_logs_local', rand()); | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
| DROP TABLE IF EXISTS service_logs; | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose StatementBegin | ||
| DROP TABLE IF EXISTS service_logs_local; | ||
| -- +goose StatementEnd | ||
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.
Uh oh!
There was an error while loading. Please reload this page.