diff --git a/posthog/models/app_metrics/sql.py b/posthog/models/app_metrics/sql.py index fa1a0c856e80d..897e1a15b0d9c 100644 --- a/posthog/models/app_metrics/sql.py +++ b/posthog/models/app_metrics/sql.py @@ -26,6 +26,11 @@ error_details String CODEC(ZSTD(3)) """.strip() +# NOTE: We have producers that take advantage of the timestamp being truncated to the hour, +# i.e. they batch up metrics and send them pre-truncated. If we ever change this truncation +# we need to revisit producers (e.g. the webhook service currently known as rusty-hook or pgqueue). +APP_METRICS_TIMESTAMP_TRUNCATION = "toStartOfHour(timestamp)" + APP_METRICS_DATA_TABLE_SQL = ( lambda: f""" CREATE TABLE IF NOT EXISTS sharded_app_metrics ON CLUSTER '{settings.CLICKHOUSE_CLUSTER}' @@ -35,7 +40,7 @@ ) ENGINE = {SHARDED_APP_METRICS_TABLE_ENGINE()} PARTITION BY toYYYYMM(timestamp) -ORDER BY (team_id, plugin_config_id, job_id, category, toStartOfHour(timestamp), error_type, error_uuid) +ORDER BY (team_id, plugin_config_id, job_id, category, {APP_METRICS_TIMESTAMP_TRUNCATION}, error_type, error_uuid) """ )