-
-
Notifications
You must be signed in to change notification settings - Fork 56
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(meta): Add updated versions of meta tables for counters #5734
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These are the final versions of the meta tables that should be used going forwards. Since the counters table already has the `record_meta` column added, these tables can be created directly. This creates two tables populated by materialized views. The first contains just tag keys, to be used to look up metric IDs for a project, and tag keys for a given metric ID. The second table contains tag values, to be used for looking up tag values for a given metric ID and tag key. This table drops org_id and use_case_id since those are superfluous given a project_id + metric_id filter.
This PR has a migration; here is the generated SQL -- start migrations
-- forward migration generic_metrics : 0036_counters_meta_tables_final
Local op: CREATE TABLE IF NOT EXISTS generic_metric_counters_meta_local (org_id UInt64, project_id UInt64, use_case_id LowCardinality(String), metric_id UInt64, tag_key UInt64, timestamp DateTime CODEC (DoubleDelta), retention_days UInt16, count AggregateFunction(sum, Float64)) ENGINE ReplicatedAggregatingMergeTree('/clickhouse/tables/generic_metrics_counters/{shard}/default/generic_metric_counters_meta_local', '{replica}') PRIMARY KEY (org_id, project_id, use_case_id, metric_id, tag_key, timestamp) ORDER BY (org_id, project_id, use_case_id, metric_id, tag_key, timestamp) PARTITION BY (retention_days, toMonday(timestamp)) TTL timestamp + toIntervalDay(retention_days) SETTINGS index_granularity=8192;
Distributed op: CREATE TABLE IF NOT EXISTS generic_metric_counters_meta_dist (org_id UInt64, project_id UInt64, use_case_id LowCardinality(String), metric_id UInt64, tag_key UInt64, timestamp DateTime CODEC (DoubleDelta), retention_days UInt16, count AggregateFunction(sum, Float64)) ENGINE Distributed(`cluster_one_sh`, default, generic_metric_counters_meta_local);
Local op: CREATE MATERIALIZED VIEW IF NOT EXISTS generic_metric_counters_meta_mv TO generic_metric_counters_meta_local (org_id UInt64, project_id UInt64, use_case_id LowCardinality(String), metric_id UInt64, tag_key UInt64, timestamp DateTime CODEC (DoubleDelta), retention_days UInt16, count AggregateFunction(sum, Float64)) AS
SELECT
org_id,
project_id,
use_case_id,
metric_id,
tag_key,
toStartOfWeek(timestamp) as timestamp,
retention_days,
sumState(count_value) as count
FROM generic_metric_counters_raw_local
ARRAY JOIN tags.key AS tag_key
WHERE record_meta = 1
GROUP BY
org_id,
project_id,
use_case_id,
metric_id,
tag_key,
timestamp,
retention_days
;
Local op: CREATE TABLE IF NOT EXISTS generic_metric_counters_meta_tag_values_local (project_id UInt64, metric_id UInt64, tag_key UInt64, tag_value String, timestamp DateTime CODEC (DoubleDelta), retention_days UInt16, count AggregateFunction(sum, Float64)) ENGINE ReplicatedAggregatingMergeTree('/clickhouse/tables/generic_metrics_counters/{shard}/default/generic_metric_counters_meta_tag_values_local', '{replica}') PRIMARY KEY (project_id, metric_id, tag_key, tag_value, timestamp) ORDER BY (project_id, metric_id, tag_key, tag_value, timestamp) PARTITION BY (retention_days, toMonday(timestamp)) TTL timestamp + toIntervalDay(retention_days) SETTINGS index_granularity=8192;
Distributed op: CREATE TABLE IF NOT EXISTS generic_metric_counters_meta_tag_values_dist (project_id UInt64, metric_id UInt64, tag_key UInt64, tag_value String, timestamp DateTime CODEC (DoubleDelta), retention_days UInt16, count AggregateFunction(sum, Float64)) ENGINE Distributed(`cluster_one_sh`, default, generic_metric_counters_meta_tag_values_local);
Local op: CREATE MATERIALIZED VIEW IF NOT EXISTS generic_metric_counters_meta_tag_values_mv TO generic_metric_counters_meta_tag_values_local (project_id UInt64, metric_id UInt64, tag_key UInt64, tag_value String, timestamp DateTime CODEC (DoubleDelta), retention_days UInt16, count AggregateFunction(sum, Float64)) AS
SELECT
project_id,
metric_id,
tag_key,
tag_value,
toStartOfWeek(timestamp) as timestamp,
retention_days,
sumState(count_value) as count
FROM generic_metric_counters_raw_local
ARRAY JOIN
tags.key AS tag_key, tags.raw_value AS tag_value
WHERE record_meta = 1
GROUP BY
project_id,
metric_id,
tag_key,
tag_value,
timestamp,
retention_days
;
-- end forward migration generic_metrics : 0036_counters_meta_tables_final
-- backward migration generic_metrics : 0036_counters_meta_tables_final
Local op: DROP TABLE IF EXISTS generic_metric_counters_meta_tag_values_mv;
Distributed op: DROP TABLE IF EXISTS generic_metric_counters_meta_tag_values_dist;
Local op: DROP TABLE IF EXISTS generic_metric_counters_meta_tag_values_local;
Local op: DROP TABLE IF EXISTS generic_metric_counters_meta_mv;
Distributed op: DROP TABLE IF EXISTS generic_metric_counters_meta_dist;
Local op: DROP TABLE IF EXISTS generic_metric_counters_meta_local;
-- end backward migration generic_metrics : 0036_counters_meta_tables_final |
volokluev
approved these changes
Apr 9, 2024
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.
Great job on this Evan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
These are the final versions of the meta tables that should be used going
forwards. Since the counters table already has the
record_meta
column added,these tables can be created directly.
This creates two tables populated by materialized views. The first contains
just tag keys, to be used to look up metric IDs for a project, and tag keys for
a given metric ID.
The second table contains tag values, to be used for looking up tag values for
a given metric ID and tag key. This table drops org_id and use_case_id since
those are superfluous given a project_id + metric_id filter.
These tables were tested and researched as part of this epic: #5695