Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
300 changes: 300 additions & 0 deletions posthog/clickhouse/hcl/golden/prod-eu/apm.hcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,72 @@
database "posthog" {
table "kafka_logs_avro" {
settings = {
input_format_avro_allow_missing_fields = "1"
}
column "uuid" {
type = "String"
}
column "trace_id" {
type = "String"
}
column "span_id" {
type = "String"
}
column "trace_flags" {
type = "Int32"
}
column "timestamp" {
type = "DateTime64(6)"
}
column "observed_timestamp" {
type = "DateTime64(6)"
}
column "body" {
type = "String"
}
column "severity_text" {
type = "String"
}
column "severity_number" {
type = "Int32"
}
column "service_name" {
type = "String"
}
column "resource_attributes" {
type = "Map(LowCardinality(String), String)"
}
column "instrumentation_scope" {
type = "String"
}
column "event_name" {
type = "String"
}
column "attributes" {
type = "Map(LowCardinality(String), String)"
}
column "retention_days" {
type = "Nullable(Int32)"
}
column "pattern" {
type = "Nullable(String)"
}
column "pattern_version" {
type = "Nullable(Int32)"
}
engine "kafka" {
collection = "warpstream_logs"
topic_list = "clickhouse_logs"
group_name = "clickhouse-logs-avro-new"
format = "Avro"
num_consumers = 4
skip_broken_messages = 100
poll_timeout_ms = 3000
poll_max_batch_size = 1000
thread_per_consumer = true
}
}

table "kafka_metrics_avro4" {
settings = {
input_format_avro_allow_missing_fields = "1"
Expand Down Expand Up @@ -170,6 +238,126 @@ database "posthog" {
}
}

table "writable_logs34" {
settings = {
background_insert_batch = "1"
}
column "time_bucket" {
type = "DateTime"
materialized = "toStartOfDay(timestamp)"
}
column "original_expiry_timestamp" {
type = "DateTime64(6)"
}
column "uuid" {
type = "String"
}
column "team_id" {
type = "Int32"
}
column "trace_id" {
type = "String"
}
column "span_id" {
type = "String"
}
column "trace_flags" {
type = "Int32"
}
column "timestamp" {
type = "DateTime64(6)"
codec = "DoubleDelta"
}
column "observed_timestamp" {
type = "DateTime64(6)"
}
column "created_at" {
type = "DateTime64(6)"
materialized = "now()"
}
column "body" {
type = "String"
}
column "severity_text" {
type = "LowCardinality(String)"
}
column "severity_number" {
type = "Int32"
}
column "service_name" {
type = "LowCardinality(String)"
}
column "resource_attributes" {
type = "Map(LowCardinality(String), String)"
}
column "resource_fingerprint" {
type = "UInt64"
materialized = "cityHash64(resource_attributes)"
}
column "instrumentation_scope" {
type = "String"
}
column "event_name" {
type = "String"
}
column "attributes_map_str" {
type = "Map(LowCardinality(String), String)"
}
column "level" {
type = "String"
alias = "severity_text"
}
column "mat_body_ipv4_matches" {
type = "Array(String)"
alias = "extractAll(body, '(\\\\d\\\\.((25[0-5]|(2[0-4]|1(0, 1)[0-9])(0, 1)[0-9])\\\\.)(2, 2)([0-9]))')"
}
column "time_minute" {
type = "DateTime"
alias = "toStartOfMinute(timestamp)"
}
column "attributes" {
type = "Map(LowCardinality(String), String)"
alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"
}
column "attributes_map_float" {
type = "Map(LowCardinality(String), Float64)"
materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"
}
column "attributes_map_datetime" {
type = "Map(LowCardinality(String), DateTime64(6))"
materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"
}
column "_partition" {
type = "UInt32"
}
column "_topic" {
type = "String"
}
column "_offset" {
type = "UInt64"
}
column "_bytes_uncompressed" {
type = "UInt64"
}
column "_bytes_compressed" {
type = "UInt64"
}
column "_record_count" {
type = "UInt64"
}
column "pattern" {
type = "String"
}
column "pattern_version" {
type = "UInt8"
}
engine "distributed" {
cluster_name = "logs"
remote_database = "posthog"
remote_table = "logs34"
}
}

table "writable_metrics4_attributes" {
column "team_id" {
type = "Int32"
Expand Down Expand Up @@ -723,6 +911,118 @@ database "posthog" {
}
}

materialized_view "kafka_logs34_avro_mv" {
to_table = "posthog.writable_logs34"
query = <<SQL
SELECT
uuid,
trace_id,
span_id,
trace_flags,
timestamp,
observed_timestamp,
body,
severity_text,
severity_number,
service_name,
instrumentation_scope,
event_name,
mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,
mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,
toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,
timestamp
+ toIntervalDay(
if(
(retention_days IS NOT NULL) AND (retention_days > 0),
retention_days,
toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(15))
)
) AS original_expiry_timestamp,
_partition,
_topic,
_offset,
toInt64OrDefault(_headers.value[indexOf(_headers.name, 'record_count')], toInt64(1)) AS _record_count,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
ifNull(pattern, '') AS pattern,
toUInt8(ifNull(pattern_version, 0)) AS pattern_version
FROM posthog.kafka_logs_avro
SQL

column "uuid" {
type = "String"
}
column "trace_id" {
type = "String"
}
column "span_id" {
type = "String"
}
column "trace_flags" {
type = "Int32"
}
column "timestamp" {
type = "DateTime64(6)"
}
column "observed_timestamp" {
type = "DateTime64(6)"
}
column "body" {
type = "String"
}
column "severity_text" {
type = "String"
}
column "severity_number" {
type = "Int32"
}
column "service_name" {
type = "String"
}
column "instrumentation_scope" {
type = "String"
}
column "event_name" {
type = "String"
}
column "attributes_map_str" {
type = "Map(String, String)"
}
column "resource_attributes" {
type = "Map(String, String)"
}
column "team_id" {
type = "Int32"
}
column "original_expiry_timestamp" {
type = "DateTime64(6)"
}
column "_partition" {
type = "UInt64"
}
column "_topic" {
type = "LowCardinality(String)"
}
column "_offset" {
type = "UInt64"
}
column "_record_count" {
type = "Int64"
}
column "_bytes_uncompressed" {
type = "Nullable(Int64)"
}
column "_bytes_compressed" {
type = "Nullable(Int64)"
}
column "pattern" {
type = "String"
}
column "pattern_version" {
type = "UInt8"
}
}

materialized_view "kafka_metrics_avro4_mv" {
to_table = "posthog.metrics4_input"
query = <<SQL
Expand Down
Loading
Loading