-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(eap): rewrite the meta tables to have lower cardinality #6316
Conversation
This PR has a migration; here is the generated SQL -- start migrations
-- forward migration events_analytics_platform : 0014_span_attribute_table_smaller
Local op: DROP TABLE IF EXISTS spans_str_attrs_mv;
Local op: DROP TABLE IF EXISTS spans_num_attrs_mv;
Distributed op: DROP TABLE IF EXISTS spans_str_attrs_dist;
Distributed op: DROP TABLE IF EXISTS spans_num_attrs_dist;
Local op: DROP TABLE IF EXISTS spans_str_attrs_local;
Local op: DROP TABLE IF EXISTS spans_num_attrs_local;
Local op: CREATE TABLE IF NOT EXISTS spans_str_attrs_2_local (organization_id UInt64, project_id UInt64, attr_key String CODEC (ZSTD(1)), attr_value String CODEC (ZSTD(1)), timestamp DateTime CODEC (ZSTD(1)), retention_days UInt16, count SimpleAggregateFunction(sum, UInt64)) ENGINE ReplicatedAggregatingMergeTree('/clickhouse/tables/events_analytics_platform/{shard}/default/spans_str_attrs_2_local', '{replica}') PRIMARY KEY (organization_id, attr_key) ORDER BY (organization_id, attr_key, attr_value, project_id, timestamp, retention_days) PARTITION BY toMonday(timestamp) TTL timestamp + toIntervalDay(retention_days) SETTINGS index_granularity=8192;
Distributed op: CREATE TABLE IF NOT EXISTS spans_str_attrs_2_dist (organization_id UInt64, project_id UInt64, attr_key String CODEC (ZSTD(1)), attr_value String CODEC (ZSTD(1)), timestamp DateTime CODEC (ZSTD(1)), retention_days UInt16, count SimpleAggregateFunction(sum, UInt64)) ENGINE Distributed(`cluster_one_sh`, default, spans_str_attrs_2_local);
Local op: CREATE MATERIALIZED VIEW IF NOT EXISTS spans_str_attrs_2_mv TO spans_str_attrs_2_local (organization_id UInt64, project_id UInt64, attr_key String CODEC (ZSTD(1)), attr_value String CODEC (ZSTD(1)), timestamp DateTime CODEC (ZSTD(1)), retention_days UInt16, count SimpleAggregateFunction(sum, UInt64)) AS
SELECT
organization_id,
project_id,
attrs.1 as attr_key,
attrs.2 as attr_value,
toStartOfDay(_sort_timestamp) AS timestamp,
retention_days,
1 AS count
FROM eap_spans_local
LEFT ARRAY JOIN
arrayConcat(
CAST(attr_str_0, 'Array(Tuple(String, String))'), CAST(attr_str_1, 'Array(Tuple(String, String))'), CAST(attr_str_2, 'Array(Tuple(String, String))'), CAST(attr_str_3, 'Array(Tuple(String, String))'), CAST(attr_str_4, 'Array(Tuple(String, String))'), CAST(attr_str_5, 'Array(Tuple(String, String))'), CAST(attr_str_6, 'Array(Tuple(String, String))'), CAST(attr_str_7, 'Array(Tuple(String, String))'), CAST(attr_str_8, 'Array(Tuple(String, String))'), CAST(attr_str_9, 'Array(Tuple(String, String))'), CAST(attr_str_10, 'Array(Tuple(String, String))'), CAST(attr_str_11, 'Array(Tuple(String, String))'), CAST(attr_str_12, 'Array(Tuple(String, String))'), CAST(attr_str_13, 'Array(Tuple(String, String))'), CAST(attr_str_14, 'Array(Tuple(String, String))'), CAST(attr_str_15, 'Array(Tuple(String, String))'), CAST(attr_str_16, 'Array(Tuple(String, String))'), CAST(attr_str_17, 'Array(Tuple(String, String))'), CAST(attr_str_18, 'Array(Tuple(String, String))'), CAST(attr_str_19, 'Array(Tuple(String, String))'),
array(
tuple('service', `service`),
tuple('segment_name', `segment_name`),
tuple('name', `name`)
)
) AS attrs
GROUP BY
organization_id,
project_id,
attr_key,
attr_value,
timestamp,
retention_days
;
Local op: CREATE TABLE IF NOT EXISTS spans_num_attrs_2_local (organization_id UInt64, project_id UInt64, attr_key String, attr_min_value SimpleAggregateFunction(min, Float64), attr_max_value SimpleAggregateFunction(max, Float64), timestamp DateTime CODEC (ZSTD(1)), retention_days UInt16, count SimpleAggregateFunction(sum, UInt64)) ENGINE ReplicatedAggregatingMergeTree('/clickhouse/tables/events_analytics_platform/{shard}/default/spans_num_attrs_2_local', '{replica}') PRIMARY KEY (organization_id, attr_key) ORDER BY (organization_id, attr_key, attr_min_value, attr_max_value, timestamp, project_id, retention_days) PARTITION BY toMonday(timestamp) TTL timestamp + toIntervalDay(retention_days) SETTINGS index_granularity=8192;
Distributed op: CREATE TABLE IF NOT EXISTS spans_num_attrs_2_dist (organization_id UInt64, project_id UInt64, attr_key String, attr_min_value SimpleAggregateFunction(min, Float64), attr_max_value SimpleAggregateFunction(max, Float64), timestamp DateTime CODEC (ZSTD(1)), retention_days UInt16, count SimpleAggregateFunction(sum, UInt64)) ENGINE Distributed(`cluster_one_sh`, default, spans_num_attrs_2_local);
Local op: CREATE MATERIALIZED VIEW IF NOT EXISTS spans_num_attrs_2_mv TO spans_num_attrs_2_local (organization_id UInt64, project_id UInt64, attr_key String, attr_min_value SimpleAggregateFunction(min, Float64), attr_max_value SimpleAggregateFunction(max, Float64), timestamp DateTime CODEC (ZSTD(1)), retention_days UInt16, count SimpleAggregateFunction(sum, UInt64)) AS
SELECT
organization_id,
project_id,
attrs.1 as attr_key,
attrs.2 as attr_min_value,
attrs.2 as attr_max_value,
toStartOfDay(_sort_timestamp) AS timestamp,
retention_days,
1 AS count
FROM eap_spans_local
LEFT ARRAY JOIN
arrayConcat(
CAST(attr_num_0, 'Array(Tuple(String, Float64))'),CAST(attr_num_1, 'Array(Tuple(String, Float64))'),CAST(attr_num_2, 'Array(Tuple(String, Float64))'),CAST(attr_num_3, 'Array(Tuple(String, Float64))'),CAST(attr_num_4, 'Array(Tuple(String, Float64))'),CAST(attr_num_5, 'Array(Tuple(String, Float64))'),CAST(attr_num_6, 'Array(Tuple(String, Float64))'),CAST(attr_num_7, 'Array(Tuple(String, Float64))'),CAST(attr_num_8, 'Array(Tuple(String, Float64))'),CAST(attr_num_9, 'Array(Tuple(String, Float64))'),CAST(attr_num_10, 'Array(Tuple(String, Float64))'),CAST(attr_num_11, 'Array(Tuple(String, Float64))'),CAST(attr_num_12, 'Array(Tuple(String, Float64))'),CAST(attr_num_13, 'Array(Tuple(String, Float64))'),CAST(attr_num_14, 'Array(Tuple(String, Float64))'),CAST(attr_num_15, 'Array(Tuple(String, Float64))'),CAST(attr_num_16, 'Array(Tuple(String, Float64))'),CAST(attr_num_17, 'Array(Tuple(String, Float64))'),CAST(attr_num_18, 'Array(Tuple(String, Float64))'),CAST(attr_num_19, 'Array(Tuple(String, Float64))'),
array(
tuple('duration_ms', `duration_ms`::Float64)
)
) AS attrs
GROUP BY
organization_id,
project_id,
attrs.1,
attrs.2,
timestamp,
retention_days
;
-- end forward migration events_analytics_platform : 0014_span_attribute_table_smaller
-- backward migration events_analytics_platform : 0014_span_attribute_table_smaller
Local op: DROP TABLE IF EXISTS spans_str_attrs_2_mv;
Local op: DROP TABLE IF EXISTS spans_str_attrs_2_local;
Distributed op: DROP TABLE IF EXISTS spans_str_attrs_2_dist;
Local op: DROP TABLE IF EXISTS spans_num_attrs_2_mv;
Local op: DROP TABLE IF EXISTS spans_num_attrs_2_local;
Distributed op: DROP TABLE IF EXISTS spans_num_attrs_2_dist;
-- end backward migration events_analytics_platform : 0014_span_attribute_table_smaller |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration as its currently written would fail via CI/CD because there is a limit on how much data a table can have before it is allowed to be dropped. The setting is this https://clickhouse.com/docs/en/operations/server-configuration-parameters/settings#max_table_size_to_drop
The setting in the ops repo is here https://github.com/getsentry/ops/blob/master/salt/states/clickhouse/files/config.xml#L16
You will need to work with a SRE to manually perform the drop table/truncate table before merging the PR.
There is an explicit truncate before dropping, is that not enough? |
Nope, it won't work. From the docs linked to clickhouse docs above
|
Opened ops request: https://getsentry.atlassian.net/servicedesk/customer/portal/18/INF-274 |
❌ 1 Tests Failed:
View the top 1 failed tests by shortest run time
To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard |
Thank you. Please respond on this PR when the ops request has been completed. I will remove my blocking review then. |
My concern has been resolved. Will let someone familiar with the product provide appropriate review.
ce4bd13
to
9a7231b
Compare
67bb083
to
791988c
Compare
We tried to improve performance of other queries with a subselect, but got disappointing results.
This change: