|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +echo "=== OTEL DB Initialization Script Started ===" |
| 5 | + |
| 6 | +clickhouse client <<-EOSQL |
| 7 | + CREATE DATABASE IF NOT EXISTS otel; |
| 8 | +EOSQL |
| 9 | + |
| 10 | +# Create the null log table for incoming otel data |
| 11 | +clickhouse client <<-EOSQL |
| 12 | + CREATE TABLE IF NOT EXISTS otel.otel_sslo_logs_null |
| 13 | + ( |
| 14 | + Timestamp DateTime64(9) CODEC(Delta(8), ZSTD(1)), |
| 15 | + ObservedTimestamp DateTime64(9) CODEC(Delta(8), ZSTD(1)), |
| 16 | + TraceId String CODEC(ZSTD(1)), |
| 17 | + SpanId String CODEC(ZSTD(1)), |
| 18 | + TraceFlags UInt8, |
| 19 | + SeverityText LowCardinality(String) CODEC(ZSTD(1)), |
| 20 | + SeverityNumber UInt8, |
| 21 | + ServiceName LowCardinality(String) CODEC(ZSTD(1)), |
| 22 | + Body String CODEC(ZSTD(1)), |
| 23 | + ResourceSchemaUrl LowCardinality(String) CODEC(ZSTD(1)), |
| 24 | + ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), |
| 25 | + ScopeSchemaUrl LowCardinality(String) CODEC(ZSTD(1)), |
| 26 | + ScopeName String CODEC(ZSTD(1)), |
| 27 | + ScopeVersion LowCardinality(String) CODEC(ZSTD(1)), |
| 28 | + ScopeAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), |
| 29 | + LogAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)), |
| 30 | + ) |
| 31 | + ENGINE = Null; |
| 32 | +EOSQL |
| 33 | + |
| 34 | + |
| 35 | +# Create the actual table which logs will be stored in |
| 36 | +clickhouse client <<-EOSQL |
| 37 | +
|
| 38 | + CREATE TABLE IF NOT EXISTS otel.sslo_logs |
| 39 | + ( |
| 40 | + Timestamp DateTime, |
| 41 | + ObservedTimestamp DateTime, |
| 42 | + hostname String CODEC(ZSTD(1)), |
| 43 | + flow_id String CODEC(ZSTD(1)), |
| 44 | + vip String CODEC(ZSTD(1)), |
| 45 | + l4_protocol LowCardinality(String) CODEC(ZSTD(1)), |
| 46 | + src_ip String CODEC(ZSTD(1)), |
| 47 | + src_port UInt16, |
| 48 | + dst_ip String CODEC(ZSTD(1)), |
| 49 | + dst_port UInt16, |
| 50 | + client_ssl_protocol LowCardinality(String) CODEC(ZSTD(1)), |
| 51 | + client_ssl_cipher LowCardinality(String) CODEC(ZSTD(1)), |
| 52 | + server_ssl_protocol LowCardinality(String) CODEC(ZSTD(1)), |
| 53 | + server_ssl_cipher LowCardinality(String) CODEC(ZSTD(1)), |
| 54 | + l7_protocol LowCardinality(String) CODEC(ZSTD(1)), |
| 55 | + sslo_host String CODEC(ZSTD(1)), |
| 56 | + decryption_status LowCardinality(String) CODEC(ZSTD(1)), |
| 57 | + duration UInt64, |
| 58 | + service_path String CODEC(ZSTD(1)), |
| 59 | + client_bytes_in UInt64, |
| 60 | + client_bytes_out UInt64, |
| 61 | + server_bytes_in UInt64, |
| 62 | + server_bytes_out UInt64, |
| 63 | + client_tls_handshake LowCardinality(String) CODEC(ZSTD(1)), |
| 64 | + server_tls_handshake LowCardinality(String) CODEC(ZSTD(1)), |
| 65 | + reset_cause LowCardinality(String) CODEC(ZSTD(1)), |
| 66 | + policy_rule LowCardinality(String) CODEC(ZSTD(1)), |
| 67 | + url_category LowCardinality(String) CODEC(ZSTD(1)), |
| 68 | + ingress String CODEC(ZSTD(1)), |
| 69 | + egress String CODEC(ZSTD(1)), |
| 70 | + ) |
| 71 | + ENGINE = MergeTree |
| 72 | + ORDER BY (Timestamp) |
| 73 | + TTL Timestamp + INTERVAL 24 HOUR; |
| 74 | +EOSQL |
| 75 | + |
| 76 | +# Create the Materialized View that populates the access log table from incoming |
| 77 | +# null logs. |
| 78 | +clickhouse client <<-EOSQL |
| 79 | + CREATE MATERIALIZED VIEW IF NOT EXISTS otel.sslo_logs_mv TO otel.sslo_logs AS |
| 80 | + SELECT Timestamp::DateTime AS Timestamp, |
| 81 | + ObservedTimestamp::DateTime AS ObservedTimestamp, |
| 82 | + LogAttributes['hostname'] AS hostname, |
| 83 | + LogAttributes['flow_id'] AS flow_id, |
| 84 | + LogAttributes['vip'] AS vip, |
| 85 | + LogAttributes['l4_protocol'] AS l4_protocol, |
| 86 | + LogAttributes['src_ip'] AS src_ip, |
| 87 | + LogAttributes['src_port'] AS src_port, |
| 88 | + LogAttributes['dst_ip'] AS dst_ip, |
| 89 | + LogAttributes['dst_port'] AS dst_port, |
| 90 | + LogAttributes['client_ssl_protocol'] AS client_ssl_protocol, |
| 91 | + LogAttributes['client_ssl_cipher'] AS client_ssl_cipher, |
| 92 | + LogAttributes['server_ssl_protocol'] AS server_ssl_protocol, |
| 93 | + LogAttributes['server_ssl_cipher'] AS server_ssl_cipher, |
| 94 | + LogAttributes['l7_protocol'] AS l7_protocol, |
| 95 | + LogAttributes['sslo_host'] AS sslo_host, |
| 96 | + LogAttributes['decryption_status'] AS decryption_status, |
| 97 | + LogAttributes['duration'] AS duration, |
| 98 | + LogAttributes['service_path'] AS service_path, |
| 99 | + LogAttributes['client_bytes_in'] AS client_bytes_in, |
| 100 | + LogAttributes['client_bytes_out'] AS client_bytes_out, |
| 101 | + LogAttributes['server_bytes_in'] AS server_bytes_in, |
| 102 | + LogAttributes['server_bytes_out'] AS server_bytes_out, |
| 103 | + LogAttributes['client_tls_handshake'] AS client_tls_handshake, |
| 104 | + LogAttributes['server_tls_handshake'] AS server_tls_handshake, |
| 105 | + LogAttributes['reset_cause'] AS reset_cause, |
| 106 | + LogAttributes['policy_rule'] AS policy_rule, |
| 107 | + LogAttributes['url_category'] AS url_category, |
| 108 | + LogAttributes['ingress'] AS ingress, |
| 109 | + LogAttributes['egress'] AS egress |
| 110 | + FROM otel.otel_sslo_logs_null; |
| 111 | +EOSQL |
0 commit comments