Skip to content
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
merged 1 commit into from
Apr 11, 2024

Conversation

evanh
Copy link
Member

@evanh evanh commented Apr 9, 2024

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

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.
@evanh evanh requested a review from a team as a code owner April 9, 2024 21:31
Copy link

github-actions bot commented Apr 9, 2024

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

Copy link
Member

@volokluev volokluev left a 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

@evanh evanh merged commit 26fdbb7 into master Apr 11, 2024
30 checks passed
@evanh evanh deleted the evanh/feat/counters-meta-tables-final branch April 11, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants