ClickHouse
Server-side event storage in ClickHouse. Raw walkerOS events are written in bulk as JSONEachRow inserts into a table you own, with a bounded retry made safe by an explicit insert_deduplication_token. The destination issues INSERT and nothing else: it never queries, never runs DDL, and never reads system.*, so the table's schema, sorting key, partitioning and retention stay entirely yours.
An insert into a table that does not exist fails with 60 UNKNOWN_TABLE, so read Create the table and Preconditions before sending the first event.
ClickHouse is a server destination in the walkerOS flow:
Receives events server-side from the collector, converts each one into a row of JSON-encoded payload columns, and inserts a flushed batch as a single JSONEachRow statement for analytics and reporting.
Installation
npm install @walkeros/collector @walkeros/server-destination-clickhouse- Integrated
- Bundled
import { startFlow } from '@walkeros/collector';
import destinationClickhouse from '@walkeros/server-destination-clickhouse';
await startFlow({
destinations: {
clickhouse: {
code: destinationClickhouse,
config: {
settings: {
url: 'https://clickhouse.example.com:8443',
},
},
},
},
});
A complete flow.json with this destination:
{
"version": 4,
"flows": {
"default": {
"config": {
"platform": "server"
},
"destinations": {
"clickhouse": {
"package": "@walkeros/server-destination-clickhouse",
"config": {
"settings": {
"url": "https://clickhouse.example.com:8443"
}
}
}
}
}
}
}Configuration
This destination uses the standard destination config wrapper (consent, data, env, id, ...). For the shared fields see destination configuration. Package-specific fields live under config.settings and are listed below.
Settings
| Property | Type | Description | More |
|---|---|---|---|
url | string | ClickHouse HTTP endpoint | |
database | string | Database holding the events table | |
table | string | Table every event is inserted into | |
maxRetries | integer | Retries added on top of the first attempt, so total attempts = 1 + maxRetries | |
clickhouse | Record<string, any> | Raw @clickhouse/client options merged into the created client | |
clickhouseSettings | Record<string, any> | ClickHouse settings applied to every insert | |
signed | boolean | Sign each insert with the host instead of a credential: true for a paired runner writing to walkerOS hosted ingest (like https://ingest.walkeros.io/events); leave unset for any other ClickHouse |
Mapping
This package does not define custom rule-level settings. For the standard rule fields (consent, condition, data, batch, name, policy) see mapping.
Examples
Initialization
Init creates a single ClickHouse client for the configured endpoint, database and credentials. The client is held on the resolved config and reused by every insert. Its request timeout is derived from the collector timeout so a retried insert cannot outlive the delivery it belongs to, and request compression is enabled.
{
"settings": {
"url": "https://clickhouse.example.com:8443",
"database": "analytics",
"table": "events"
},
"credentials": {
"username": "walkeros_writer",
"password": "$secret.CLICKHOUSE_PASSWORD"
}
}createClient({
"url": "https://clickhouse.example.com:8443",
"database": "analytics",
"username": "walkeros_writer",
"password": "$secret.CLICKHOUSE_PASSWORD",
"request_timeout": 4812,
"compression": {
"request": true
},
"log": {
"level": 127
}
})Endpoint path with a token
An endpoint with a path, like https://clickhouse-proxy.example.com/events, sends every insert to that path, and the database stays the configured one. A token in credentials replaces the username and password and travels as an Authorization: Bearer header.
{
"settings": {
"url": "https://clickhouse-proxy.example.com/events"
},
"credentials": {
"token": "$secret.CLICKHOUSE_TOKEN"
}
}createClient({
"url": "https://clickhouse-proxy.example.com",
"pathname": "/events",
"database": "default",
"access_token": "$secret.CLICKHOUSE_TOKEN",
"request_timeout": 4812,
"compression": {
"request": true
},
"log": {
"level": 127
}
})Page view
A page view is inserted as a single JSONEachRow row. The payload columns (data, context, globals, custom, user, nested, consent, source) are JSON-encoded strings and the timestamp is a UTC datetime literal, both produced by eventToRow.
{
"name": "page view",
"data": {
"domain": "www.example.com",
"title": "walkerOS documentation",
"referrer": "https://www.walkeros.io/",
"search": "?foo=bar",
"hash": "#hash",
"id": "/docs/"
},
"context": {
"dev": [
"test",
1
]
},
"globals": {
"pagegroup": "docs"
},
"custom": {
"completely": "random"
},
"user": {
"id": "us3r",
"device": "c00k13",
"session": "s3ss10n"
},
"nested": [
{
"entity": "child",
"data": {
"is": "subordinated"
}
}
],
"consent": {
"functional": true
},
"id": "f0cc5f6fec3d8eeb",
"trigger": "load",
"entity": "page",
"action": "view",
"timestamp": 1700000000123,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}insert({
"table": "events",
"values": [
{
"name": "page view",
"data": "{\"domain\":\"www.example.com\",\"title\":\"walkerOS documentation\",\"referrer\":\"https://www.walkeros.io/\",\"search\":\"?foo=bar\",\"hash\":\"#hash\",\"id\":\"/docs/\"}",
"context": "{\"dev\":[\"test\",1]}",
"globals": "{\"pagegroup\":\"docs\"}",
"custom": "{\"completely\":\"random\"}",
"user": "{\"id\":\"us3r\",\"device\":\"c00k13\",\"session\":\"s3ss10n\"}",
"nested": "[{\"entity\":\"child\",\"data\":{\"is\":\"subordinated\"}}]",
"consent": "{\"functional\":true}",
"id": "f0cc5f6fec3d8eeb",
"trigger": "load",
"entity": "page",
"action": "view",
"timestamp": "2023-11-14 22:13:20.123",
"timing": 3.14,
"source": "{\"count\":1,\"trace\":\"0a1b2c3d4e5f60718293a4b5c6d7e8f9\",\"type\":\"collector\",\"schema\":\"4\"}"
}
],
"format": "JSONEachRow",
"clickhouse_settings": {
"async_insert": 0,
"input_format_skip_unknown_fields": 0,
"input_format_null_as_default": 0,
"insert_deduplication_token": "a58f3019507d0cfaef6623ca56954255ccc611cbf2f3dcadacd63d192e6164e7"
}
})Purchase
An order event is inserted as one row. The nested items array is JSON-encoded into the data column, so a richer payload needs no table change. Promoting a hot key to its own column is a MATERIALIZED expression in the table DDL, not a destination setting.
{
"name": "order complete",
"data": {
"id": "ORD-500",
"currency": "EUR",
"value": 199.99,
"items": [
{
"sku": "SKU-1",
"quantity": 2
},
{
"sku": "SKU-2",
"quantity": 1
}
]
},
"context": {
"shopping": [
"complete",
0
]
},
"globals": {
"pagegroup": "shop"
},
"custom": {
"completely": "random"
},
"user": {
"id": "us3r",
"device": "c00k13",
"session": "s3ss10n"
},
"nested": [
{
"entity": "product",
"data": {
"id": "ers",
"name": "Everyday Ruck Snack",
"color": "black",
"size": "l",
"price": 420
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
},
{
"entity": "product",
"data": {
"id": "cc",
"name": "Cool Cap",
"size": "one size",
"price": 42
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
},
{
"entity": "gift",
"data": {
"name": "Surprise"
},
"context": {
"shopping": [
"complete",
0
]
},
"nested": []
}
],
"consent": {
"functional": true
},
"id": "235d0d7bd7a213f2",
"trigger": "load",
"entity": "order",
"action": "complete",
"timestamp": 1700000000456,
"timing": 3.14,
"source": {
"count": 1,
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "collector",
"schema": "4"
}
}insert({
"table": "events",
"values": [
{
"name": "order complete",
"data": "{\"id\":\"ORD-500\",\"currency\":\"EUR\",\"value\":199.99,\"items\":[{\"sku\":\"SKU-1\",\"quantity\":2},{\"sku\":\"SKU-2\",\"quantity\":1}]}",
"context": "{\"shopping\":[\"complete\",0]}",
"globals": "{\"pagegroup\":\"shop\"}",
"custom": "{\"completely\":\"random\"}",
"user": "{\"id\":\"us3r\",\"device\":\"c00k13\",\"session\":\"s3ss10n\"}",
"nested": "[{\"entity\":\"product\",\"data\":{\"id\":\"ers\",\"name\":\"Everyday Ruck Snack\",\"color\":\"black\",\"size\":\"l\",\"price\":420},\"context\":{\"shopping\":[\"complete\",0]},\"nested\":[]},{\"entity\":\"product\",\"data\":{\"id\":\"cc\",\"name\":\"Cool Cap\",\"size\":\"one size\",\"price\":42},\"context\":{\"shopping\":[\"complete\",0]},\"nested\":[]},{\"entity\":\"gift\",\"data\":{\"name\":\"Surprise\"},\"context\":{\"shopping\":[\"complete\",0]},\"nested\":[]}]",
"consent": "{\"functional\":true}",
"id": "235d0d7bd7a213f2",
"trigger": "load",
"entity": "order",
"action": "complete",
"timestamp": "2023-11-14 22:13:20.456",
"timing": 3.14,
"source": "{\"count\":1,\"trace\":\"0a1b2c3d4e5f60718293a4b5c6d7e8f9\",\"type\":\"collector\",\"schema\":\"4\"}"
}
],
"format": "JSONEachRow",
"clickhouse_settings": {
"async_insert": 0,
"input_format_skip_unknown_fields": 0,
"input_format_null_as_default": 0,
"insert_deduplication_token": "40154acbfbc074b8a89782c2721f33ca89b3a5aa316032adc482cc628a6531a8"
}
})When it fails
- Empty token: An empty credentials.token, such as a secret that resolved to nothing, fails init with code config instead of going out as an empty Bearer header. No client is created, and every event fails with that reason. Reported as
failedwith codeconfig. - Signed without a host that signs: settings.signed: true where no host hands the destination its signer (a runner that is not paired) fails init with code config, naming settings.signed. No client is created, and every event fails with that reason. Reported as
failedwith codeconfig. - Token in the url: An access_token in the query of settings.url fails init with code config: a token belongs in credentials.token, backed by a managed secret. No client is created, and every event fails with that reason. Reported as
failedwith codeconfig. - Token beside a passthrough password: A token in credentials beside a username or password in settings.clickhouse fails init with code config: ClickHouse signs in with one of them. No client is created, and every event fails with that reason. Reported as
failedwith codeconfig. - Token beside a username in the url: A token in credentials beside a username or password in the settings url fails init with code config: ClickHouse signs in with one of them. No client is created, and every event fails with that reason. Reported as
failedwith codeconfig. - Token beside a username: Credentials that carry a token and a username or password fail init with code config: ClickHouse signs in with one of them. No client is created, and every event fails with that reason. Reported as
failedwith codeconfig.
Credentials
config.credentials says how the destination signs in: the
{ username, password } of the ClickHouse user it writes as, or a { token }
for an endpoint that takes one, such as a proxy in front of ClickHouse. Back the
password or the token with a managed secret ($secret.NAME) instead of writing
it into the flow config. The credentials win over the same keys left in settings.clickhouse.
Without credentials the client signs in as the default user with an empty
password.
"config": {
"settings": { "url": "https://clickhouse.example.com:8443" },
"credentials": {
"username": "walkeros_writer",
"password": "$secret.CLICKHOUSE_PASSWORD"
}
}A token travels as an Authorization: Bearer header. A path in settings.url
is the path every insert is sent to, and the database stays the one
settings.database names:
"config": {
"settings": { "url": "https://clickhouse-proxy.example.com/events" },
"credentials": { "token": "$secret.CLICKHOUSE_TOKEN" }
}A token beside a username or password, in credentials, settings.clickhouse
or the userinfo of settings.url, fails init with code config, since
ClickHouse signs in with one of them. An empty token and an access_token in
the query of settings.url fail the same way: a token belongs in
credentials.token. Every event then fails with that reason.
An insert that the walkerOS data proxy refuses fails with the proxy's reason:
when the answer carries no ClickHouse code and its first line starts with
walkerOS data proxy, the failure and its ERROR line quote that line (at most
200 characters). Any other answer is reported by its ClickHouse code or Node
error code only, never by its text, since ClickHouse can quote the rows it
refused. The batch is retried once, as before.
Signed inserts to walkerOS hosted ingest
Run by a paired runner (runneros with its credential) against walkerOS hosted
ingest, the destination needs no credential. With settings.signed: true it
signs each insert with the runner's own key: every attempt carries a fresh
signature over the exact bytes it sends, and the data server checks it against
the keys of the runner's deployment.
"config": {
"settings": { "url": "https://ingest.walkeros.io/events", "signed": true }
}- Any other ClickHouse keeps its
credentialsand leavessignedunset. The destination then never signs, even under a paired runner. signed: truewhere no runner signs (a runner that is not paired), or beside a credential incredentials,settings.clickhouseorsettings.url, or beside othersettings.clickhouseclient options thanrequest_timeout, fails init with codeconfig, namingsettings.signed. Every event then fails with that reason.- A
503withRetry-After(a key the data server does not know yet, or a data server that started after the insert was signed) is retried after that delay, signed anew, while the retry still fits the delivery'stimeout. - A
403is final: the batch goes to the dead letter queue at once with codeauthand one ERROR line, which names the clock offset when the answer'sDateis more than 5 seconds off this runner's clock.
Passthrough options
settings.clickhouse reaches the @clickhouse/client constructor, and
settings.clickhouseSettings travels with every insert, so both stay open for
options this destination does not model itself. Three rules apply on top:
urlanddatabasealways win over the same keys insettings.clickhouse. An insert names only the table, so a passthroughdatabasethat disagreed would move every row to a different database in silence. A path inurlis the request path, never the database: name the database insettings.database.- The client's own logger is off unless
settings.clickhouse.logsets it. It would print each failed request's answer, which can quote refused rows, to the console outside the walkerOS logger. The destination reports every failed insert itself. - If you enable
async_insertthroughclickhouseSettings, keepwait_for_async_insert = 1. At0the server acknowledges before the data reaches storage, so a failure at the later flush has no way back to the caller, reaches no retry and no dead letter queue, and is lost without an error anywhere.
Event columns
Every event becomes one row. Payload fields travel as JSON-encoded strings, so the table needs no schema knowledge of what a flow sends.
| Column | Event field | Table type | Notes |
|---|---|---|---|
id | event.id | String | The only input to the deduplication token. |
name | event.name | LowCardinality(String) | entity action, with the space. |
entity | event.entity | LowCardinality(String) | |
action | event.action | LowCardinality(String) | |
trigger | event.trigger | LowCardinality(String) | |
timestamp | event.timestamp | DateTime64(3, 'UTC') | Written as a YYYY-MM-DD hh:mm:ss.SSS UTC literal. |
timing | event.timing | Float64 | |
data | event.data | String | JSON, or an empty string when absent. |
context | event.context | String | JSON, or an empty string when absent. |
globals | event.globals | String | JSON, or an empty string when absent. |
custom | event.custom | String | JSON, or an empty string when absent. |
user | event.user | String | JSON, or an empty string when absent. |
nested | event.nested | String | JSON, or an empty string when absent. |
consent | event.consent | String | JSON, or an empty string when absent. |
source | event.source | String | JSON, or an empty string when absent. |
No column is nullable. Inserts run with input_format_null_as_default = 0, so
an absent payload arrives as an empty string rather than as a null the server
would quietly replace with a default.
The timestamp is a basic-format UTC string rather than a number or an ISO
literal on purpose. date_time_input_format defaults changed in ClickHouse 26.5
and integer parsing changed in 26.8, so a number can be read as Unix seconds by
one server and as the raw value at the column's precision by another, which is a
factor of 1000 apart. The basic format reads the same on every server version.
JSONEachRow is fixed and not configurable. A positional format would silently
misalign every value the first time a column is reordered in a table the
destination does not own.
Empty payloads
An absent payload, an empty object and an empty array all become an empty
string. An object whose keys are all undefined is not empty by that test and
encodes as {}. Both forms exist in the table, so a query filtering out empty
payloads should account for '' and '{}'.
Create the table
There is no setup lifecycle and no provisioning. The destination creates
nothing, and an insert into a table that does not exist fails with
60 UNKNOWN_TABLE.
Create the table before sending events. Replace {database} and {table} with
the values in settings (default and events when unset), and read the notes
below before running it. The
ORDER BY in particular is worth deciding first.
CREATE TABLE IF NOT EXISTS {database}.{table} (
id String CODEC(ZSTD(1)),
name LowCardinality(String),
entity LowCardinality(String),
action LowCardinality(String),
trigger LowCardinality(String),
timestamp DateTime64(3, 'UTC') CODEC(DoubleDelta, ZSTD(1)),
timing Float64,
data String CODEC(ZSTD(3)),
context String CODEC(ZSTD(3)),
globals String CODEC(ZSTD(3)),
custom String CODEC(ZSTD(3)),
user String CODEC(ZSTD(3)),
nested String CODEC(ZSTD(3)),
consent String CODEC(ZSTD(3)),
source String CODEC(ZSTD(3)),
user_hash String MATERIALIZED JSONExtractString(user, 'hash') CODEC(ZSTD(1))
) ENGINE = MergeTree
PARTITION BY toYYYYMM(timestamp)
ORDER BY (entity, action, timestamp)
TTL toDateTime(timestamp) + INTERVAL 14 MONTH DELETE
-- non_replicated_deduplication_window is what makes a retried insert safe on
-- this engine. It defaults to 0, which deduplicates nothing, so without it a
-- retry after a server-side timeout writes the same rows twice.
SETTINGS ttl_only_drop_parts = 1, non_replicated_deduplication_window = 1000On a ReplicatedMergeTree the equivalent window is on by default and that
setting is unnecessary. On this non-replicated MergeTree it is not optional:
see Retries and duplicates for what the window covers
and what it does not.
The lines worth explaining:
non_replicated_deduplication_window = 1000. The number of recently inserted blocks whose hashes the table keeps, which is what theinsert_deduplication_tokenis matched against. At 1000 a retry is covered as long as fewer than 1000 further blocks landed in between. At the recommended batch settings one runtime inserts 0.2 to 1 blocks per second, so that is roughly 17 to 83 minutes, and every further runtime writing the same table shortens it in proportion. The destination retries within seconds, so this leaves a wide margin. Raise it if you insert far more often.PARTITION BY toYYYYMM(timestamp). A partition key should stay low-cardinality, usually under 100 to 1000 distinct values. Monthly partitioning keeps a 14 month retention at 14 partitions. Partitioning finer (by day, or by site) is the common cause of252 TOO_MANY_PARTS, because ClickHouse never merges parts across partitions, so each partition carries its own merge backlog.ttl_only_drop_parts = 1. Retention then drops whole parts once every row in them has expired, instead of running the mutations a partial TTL cleanup performs. The server default is0.MergeTree, notReplacingMergeTree. This destination writes raw hits and deduplicates at the insert layer, so a replacing engine buys nothing. It costs extra merge work, and it invitesOPTIMIZE ... FINAL, which rewrites whole partitions and does not guarantee uniqueness at read time anyway.14 MONTHis a placeholder. Set the retention your contract requires.
Promoting a hot key to a column
Payload columns are JSON strings, so a frequently filtered key becomes a real
column through a MATERIALIZED expression over the string. It costs the
destination nothing and needs no flow change:
ALTER TABLE {database}.{table}
ADD COLUMN site_id LowCardinality(String)
MATERIALIZED JSONExtractString(globals, 'site_id');Two constraints:
- A materialized column can only read a value the row actually contains, so the
flow has to land the site on the event first (in
globals,contextordata). No table expression can invent it. - A column added later is computed for new parts only. Existing rows read the column's default until the parts are rewritten.
The ORDER BY is the decision to get right
(entity, action, timestamp) is the safe default for a table with no tenant
column. It is almost certainly wrong for an estate of thousands of sites: with
that many tenants the leading column should be the site identifier, so that a
query for one site reads one narrow range of the primary index instead of
scanning every site's rows for the matching entity.
Changing the sorting key later is not an ALTER. It means creating a second
table with the new key and moving the data across with ATTACH PARTITION, with
ingestion paused for the switch. It is worth deciding before the first insert,
and it depends on the same site value the materialized column above needs.
Preconditions
Confirm these before the first event flows. Each one is a decision this package deliberately does not make for you:
- You run the DDL. The destination creates nothing. An insert into a table
that does not exist fails with
60 UNKNOWN_TABLE. - The
ORDER BYprefix. See above. The default is safe, not right for a large multi-site estate, and expensive to change later. - Deduplication is enabled. Either the table is a
ReplicatedMergeTree, or it setsnon_replicated_deduplication_windowabove0. The reference DDL sets it, so this is a precondition on your own DDL: if you write your own, carry the setting across. See Retries and duplicates. Without one of the two, a retry can duplicate rows. - The retention the contract requires. The 14 month TTL in the DDL is a placeholder.
- A loud failure is what you want. A walkerOS field that has no column in your table fails the whole batch rather than being dropped in silence. That trade is described in Schema drift fails loudly, and it means a schema change on our side can stop ingestion until you add the column.
Batching at scale
Batching belongs to the collector, through config.batch. The package sets no
batch, so each event is its own insert until the flow sets one. The numbers
below are a recommendation for the flow config:
"batch": { "size": 5000, "age": 5000, "wait": 1000 }ClickHouse's own guidance is explicit: "We recommend inserting data in batches of at least 1,000 rows, and ideally between 10,000-100,000 rows", and "We recommend keeping the number of insert queries around one insert query per second".
At roughly 300 events per second the settings above flush about 1,500 rows every
5 seconds, and at several times that load the size cap flushes 5,000 rows
sooner. That is between 0.2 and 1 inserts per second across the range, which
sits inside ClickHouse's recommendation at both ends.
The three fields do different jobs:
waitis a debounce. Its timer resets on every push, so it alone would never flush under continuous load.ageis the hard ceiling on how long the first event of a window waits. It is what bounds latency.sizeis the hard ceiling on rows per insert. It is what bounds insert size at peak.
Retries and duplicates
This destination's retry is the only retry in the pipeline. The collector has none: a delivery that throws is dead-lettered, and the dead letter queue is an in-memory buffer (100 entries by default, oldest dropped on overflow) that nothing drains back into the pipeline. Anything that reaches it is gone.
So a retry has to be safe. Every attempt of one batch sends the same
insert_deduplication_token, a digest of the batch's event ids computed once
before the first attempt. A server that had already written the block when the
answer stopped coming skips the repeat.
The token only works if the table deduplicates. That needs one of:
- a
ReplicatedMergeTreefamily engine, where insert deduplication is on, or non_replicated_deduplication_windowset above0on a non-replicatedMergeTree.
non_replicated_deduplication_window defaults to 0. On a plain
non-replicated MergeTree with the default, nothing deduplicates and a retry
can duplicate rows. The reference DDL sets it to 1000 for exactly this
reason. If your table is your own, confirm which of the two covers you before
enabling retries in production.
Two further conditions:
- One batch stays one block. The window counts blocks, so a batch split into several blocks by a server-side setting is no longer covered by its own token.
- The token replaces the block-content check. The server skips a repeated token while reporting success, with no error, no dead letter entry and no counter anywhere. That is why the token is derived from event ids and nothing else: a token that could repeat across different events would be silent data loss.
Retries are bounded by maxRetries (one retry by default, so two attempts) and
by the derived request timeout, so the last attempt finishes inside
config.timeout. Only transient failures are retried: server-side timeouts, a
saturated query or connection pool, a cancelled query, an overloaded server, a
table held read-only, and every transport failure that never got an answer at
all (ECONNRESET and friends). Everything else is terminal and goes to the dead
letter queue on the first failure.
Schema drift fails loudly
Two settings travel with every insert and are the reason a missing column is noisy:
input_format_skip_unknown_fields = 0. The server default drops a JSON key the table does not know. At0it raises an error instead.input_format_null_as_default = 0. The server default rewrites an explicitnullinto the column's default. At0it raises an error instead.
A walkerOS field with no column in your table therefore fails the whole batch,
loudly, attributed and counted, rather than disappearing and being found weeks
later in reporting. The cost is real: ingestion for that batch stops instead of
degrading. If you would rather have the silent drop, set
clickhouseSettings.input_format_skip_unknown_fields to 1 in the flow config.
We think the loud failure is the right default for a warehouse of record, and
this is the place to disagree with us.
Too many parts
252 TOO_MANY_PARTS fires when the active parts in one partition exceed
parts_to_throw_insert (3000 by default, with inserts delayed from 1000). It
means merging cannot keep up with how many separate inserts are arriving.
The fix is a larger batch: raise config.batch.size so the same rows arrive in
fewer inserts. Check the partition key too, since partitioning finer than
monthly multiplies the merge backlog.
Raising parts_to_throw_insert is not the fix. It hides the backlog until
it is worse.
Custom rows
A mapping rule's data object replaces the canonical row wholesale. The object
a mapping produces travels verbatim, so a table that is not the reference DDL is
configured in the flow rather than in the destination. An event without a data
mapping still arrives as the canonical row, which a custom table rejects, so the
"*": { "*": { "ignore": true } } rule keeps every other event out:
{
"destinations": {
"clickhouse": {
"package": "@walkeros/server-destination-clickhouse",
"config": {
"settings": {
"url": "https://clickhouse.example.com:8443",
"database": "analytics",
"table": "orders"
},
"mapping": {
"order": {
"complete": {
"data": {
"map": {
"event_id": "id",
"event_name": "name",
"order_id": "data.id",
"revenue": "data.value",
"currency": { "key": "data.currency", "value": "EUR" }
}
}
}
},
"*": { "*": { "ignore": true } }
}
}
}
}
}With the matching table:
CREATE TABLE IF NOT EXISTS analytics.orders (
event_id String,
event_name LowCardinality(String),
order_id String,
revenue Float64,
currency LowCardinality(String),
inserted_at DateTime64(3, 'UTC') DEFAULT now64(3)
) ENGINE = MergeTree
PARTITION BY toYYYYMM(inserted_at)
ORDER BY (order_id, inserted_at)
-- A custom table needs the deduplication window just as much as the reference
-- one: the retry is the destination's and does not know your schema.
SETTINGS non_replicated_deduplication_window = 1000Three things to know about a mapped row:
- Every key must exist as a column.
input_format_skip_unknown_fields = 0applies here too, so a typo in a map key fails the batch. - The timestamp conversion does not apply. A mapped row is not built by the
destination, so mapping
"timestamp": "timestamp"sends raw epoch milliseconds into whatever the column is, which is exactly the version-dependent parsing the canonical row avoids. Fill the column with a server-sideDEFAULT now64(3)as above, or produce theYYYY-MM-DD hh:mm:ss.SSSliteral in the flow. - A batch is one insert, and a row can be short. A map key whose value
resolves to
undefinedis left out of the row, and mapping only some events sends two shapes in one block. A column absent from a row is filled with its default rather than raising an error, which is the one silent path left. Give every column a default you can recognize, and keep one shape per destination: route a second shape to a second destination pointing at its own table.
The event id still comes from the event, never from the mapped row, so deduplication keeps working for a row that carries no id column.
Timeouts and shutdown
config.timeout is the collector's per-delivery race (10000 ms when unset). The
client's request timeout is derived from it so that every attempt and every
retry delay finishes before the collector stops waiting.
At shutdown each pending batch flush gets what is left of the collector's 8
second shutdown deadline once the sources have closed, then the destination
closes. A deployment that wants its retries to survive shutdown keeps
config.timeout below that remainder, with time to spare (behind a Pub/Sub pull
source at its 5000 default the remainder is about 3 seconds), so the last attempt
finishes before the destination closes and cuts off an insert still in flight.