feat: clickhouse logstore implementation #576
Open
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.
ClickHouse LogStore Implementation
Overview
This PR adds ClickHouse as a storage backend for the LogStore, using a single denormalized table design optimized for ClickHouse's columnar storage and aggregation functions.
Schema
Key Design Decisions
Data Model
An event with 2 delivery attempts = 2 rows:
To get the "current" status:
argMax(status, delivery_time)→ returnssuccessOperations
1. InsertManyDeliveryEvent
INSERT INTO event_log ( event_id, tenant_id, destination_id, topic, eligible_for_retry, event_time, metadata, data, delivery_id, delivery_event_id, status, delivery_time, code, response_data )delivery_id = "",status = "pending",delivery_time = event_timeevent_timeensures pending "loses" to any real delivery inargMax()2. ListEvent
Key points:
GROUP BY event_idcollapses delivery rows into one eventargMax(status, delivery_time)returns status from the row with max delivery_timeany()for event fields (identical across rows)HAVINGfor status filter (can't use WHERE on aggregates)fromUnixTimestamp64Milli()for proper DateTime64(3) comparisonCursor pagination:
3. RetrieveEvent / RetrieveEventByDestination
argMax()for latest status4. ListDelivery
Known Concerns
COUNT Query
The current implementation runs a COUNT query on every
ListEventcall. At high volumes, this may have performance implications. Worth discussing whether we want to keep COUNT in our pagination response or rethink the approach.