-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[exporter/clickhouse] Add create_schema
option to config
#32282
Changes from all commits
08728b3
6953271
30f5335
9a3728f
25e046e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: "Add `create_schema` option to ClickHouse exporter" | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [32282] | ||
|
||
# (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: The new create_schema option allows disabling default DDL to let the user manage their own schema. | ||
|
||
# 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: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- Default database DDL (uses "default" by default, but this is example for non-default database) | ||
|
||
CREATE DATABASE IF NOT EXISTS otel; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
-- Default Histogram metrics table DDL | ||
|
||
CREATE TABLE IF NOT EXISTS otel_metrics_histogram ( | ||
ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
ResourceSchemaUrl String CODEC(ZSTD(1)), | ||
ScopeName String CODEC(ZSTD(1)), | ||
ScopeVersion String CODEC(ZSTD(1)), | ||
ScopeAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
ScopeDroppedAttrCount UInt32 CODEC(ZSTD(1)), | ||
ScopeSchemaUrl String CODEC(ZSTD(1)), | ||
ServiceName LowCardinality(String) CODEC(ZSTD(1)), | ||
MetricName String CODEC(ZSTD(1)), | ||
MetricDescription String CODEC(ZSTD(1)), | ||
MetricUnit String CODEC(ZSTD(1)), | ||
Attributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
StartTimeUnix DateTime64(9) CODEC(Delta, ZSTD(1)), | ||
TimeUnix DateTime64(9) CODEC(Delta, ZSTD(1)), | ||
Count UInt64 CODEC(Delta, ZSTD(1)), | ||
Sum Float64 CODEC(ZSTD(1)), | ||
BucketCounts Array(UInt64) CODEC(ZSTD(1)), | ||
ExplicitBounds Array(Float64) CODEC(ZSTD(1)), | ||
Exemplars Nested ( | ||
FilteredAttributes Map(LowCardinality(String), String), | ||
TimeUnix DateTime64(9), | ||
Value Float64, | ||
SpanId String, | ||
TraceId String | ||
) CODEC(ZSTD(1)), | ||
Flags UInt32 CODEC(ZSTD(1)), | ||
Min Float64 CODEC(ZSTD(1)), | ||
Max Float64 CODEC(ZSTD(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_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1 | ||
) ENGINE = MergeTree() | ||
TTL toDateTime("TimeUnix") + toIntervalDay(180) | ||
PARTITION BY toDate(TimeUnix) | ||
ORDER BY (ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix)) | ||
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- Default Logs table DDL | ||
|
||
CREATE TABLE IF NOT EXISTS otel_logs ( | ||
Timestamp DateTime64(9) CODEC(Delta, ZSTD(1)), | ||
TraceId String CODEC(ZSTD(1)), | ||
SpanId String CODEC(ZSTD(1)), | ||
TraceFlags UInt32 CODEC(ZSTD(1)), | ||
SeverityText LowCardinality(String) CODEC(ZSTD(1)), | ||
SeverityNumber Int32 CODEC(ZSTD(1)), | ||
ServiceName LowCardinality(String) CODEC(ZSTD(1)), | ||
Body String CODEC(ZSTD(1)), | ||
ResourceSchemaUrl String CODEC(ZSTD(1)), | ||
ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
ScopeSchemaUrl String CODEC(ZSTD(1)), | ||
ScopeName String CODEC(ZSTD(1)), | ||
ScopeVersion String CODEC(ZSTD(1)), | ||
ScopeAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
LogAttributes 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_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 1 | ||
) ENGINE = MergeTree() | ||
TTL toDateTime("Timestamp") + toIntervalDay(180) | ||
PARTITION BY toDate(Timestamp) | ||
ORDER BY (ServiceName, SeverityText, toUnixTimestamp(Timestamp), TraceId) | ||
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-- Default Sum metrics table DDL | ||
|
||
CREATE TABLE IF NOT EXISTS otel_metrics_sum ( | ||
ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
ResourceSchemaUrl String CODEC(ZSTD(1)), | ||
ScopeName String CODEC(ZSTD(1)), | ||
ScopeVersion String CODEC(ZSTD(1)), | ||
ScopeAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
ScopeDroppedAttrCount UInt32 CODEC(ZSTD(1)), | ||
ScopeSchemaUrl String CODEC(ZSTD(1)), | ||
ServiceName LowCardinality(String) CODEC(ZSTD(1)), | ||
MetricName String CODEC(ZSTD(1)), | ||
MetricDescription String CODEC(ZSTD(1)), | ||
MetricUnit String CODEC(ZSTD(1)), | ||
Attributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
StartTimeUnix DateTime64(9) CODEC(Delta, ZSTD(1)), | ||
TimeUnix DateTime64(9) CODEC(Delta, ZSTD(1)), | ||
Value Float64 CODEC(ZSTD(1)), | ||
Flags UInt32 CODEC(ZSTD(1)), | ||
Exemplars Nested ( | ||
FilteredAttributes Map(LowCardinality(String), String), | ||
TimeUnix DateTime64(9), | ||
Value Float64, | ||
SpanId String, | ||
TraceId String | ||
) CODEC(ZSTD(1)), | ||
AggTemp Int32 CODEC(ZSTD(1)), | ||
IsMonotonic Boolean CODEC(Delta, ZSTD(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_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1 | ||
) ENGINE = MergeTree() | ||
TTL toDateTime("TimeUnix") + toIntervalDay(180) | ||
PARTITION BY toDate(TimeUnix) | ||
ORDER BY (ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix)) | ||
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-- Default Summary metrics DDL | ||
|
||
CREATE TABLE IF NOT EXISTS otel_metrics_summary ( | ||
ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
ResourceSchemaUrl String CODEC(ZSTD(1)), | ||
ScopeName String CODEC(ZSTD(1)), | ||
ScopeVersion String CODEC(ZSTD(1)), | ||
ScopeAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
ScopeDroppedAttrCount UInt32 CODEC(ZSTD(1)), | ||
ScopeSchemaUrl String CODEC(ZSTD(1)), | ||
ServiceName LowCardinality(String) CODEC(ZSTD(1)), | ||
MetricName String CODEC(ZSTD(1)), | ||
MetricDescription String CODEC(ZSTD(1)), | ||
MetricUnit String CODEC(ZSTD(1)), | ||
Attributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
StartTimeUnix DateTime64(9) CODEC(Delta, ZSTD(1)), | ||
TimeUnix DateTime64(9) CODEC(Delta, ZSTD(1)), | ||
Count UInt64 CODEC(Delta, ZSTD(1)), | ||
Sum Float64 CODEC(ZSTD(1)), | ||
ValueAtQuantiles Nested( | ||
Quantile Float64, | ||
Value Float64 | ||
) CODEC(ZSTD(1)), | ||
Flags UInt32 CODEC(ZSTD(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_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1 | ||
) ENGINE = MergeTree() | ||
TTL toDateTime("TimeUnix") + toIntervalDay(180) | ||
PARTITION BY toDate(TimeUnix) | ||
ORDER BY (ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix)) | ||
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-- 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 | ||
) ENGINE = MergeTree() | ||
TTL toDateTime("Timestamp") + toIntervalDay(180) | ||
PARTITION BY toDate(Timestamp) | ||
ORDER BY (ServiceName, SpanName, toUnixTimestamp(Timestamp), TraceId) | ||
SETTINGS index_granularity=8192, ttl_only_drop_parts = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,16 @@ func newMetricsExporter(logger *zap.Logger, cfg *Config) (*metricsExporter, erro | |
} | ||
|
||
func (e *metricsExporter) start(ctx context.Context, _ component.Host) error { | ||
internal.SetLogger(e.logger) | ||
|
||
if !e.cfg.ShouldCreateSchema() { | ||
return nil | ||
} | ||
|
||
if err := createDatabase(ctx, e.cfg); err != nil { | ||
return err | ||
} | ||
|
||
internal.SetLogger(e.logger) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to drop this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was moved to the top of the function so that it is called before the DDL statements (conditionally) run. I also considered extracting all of the DDL to its own function outside of |
||
|
||
ttlExpr := generateTTLExpr(e.cfg.TTLDays, e.cfg.TTL, "TimeUnix") | ||
return internal.NewMetricsTable(ctx, e.cfg.MetricsTableName, e.cfg.ClusterString(), e.cfg.TableEngineString(), ttlExpr, e.client) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a unit test to verify the table DDL gennerate by code is as same as the example ones.
it can prevent the example ones allway up-to-date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered reading the template strings from a file to avoid this completely, but ultimately this DDL is just an example.
As long as the column names and types are the same, the inserts should run correctly.
If we were to add unit tests then I would prefer to just read the SQL in from a file, or maybe embed it in the code at build time, or extract them into individual
.go
files. Let me know if any of this sounds like a better solution and I will update the PR. 👍