-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add use_case_id index to generic metrics (#5655)
The use_case_id is being sent with every query, and in the cases where a metric_id is not specified, can be used to very effectively reduce the number of rows scanned. The granularity is set a little higher than for the tags hash maps, since the cardinality of use case ID is quite high and the data should be fairly clumpy (metric_id should all be stored together and each metric_id has only one use case ID).
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
snuba/snuba_migrations/generic_metrics/0029_add_use_case_id_index.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from typing import Sequence | ||
|
||
from snuba.clusters.storage_sets import StorageSetKey | ||
from snuba.migrations import migration, operations | ||
|
||
|
||
class Migration(migration.ClickhouseNodeMigration): | ||
blocking = False | ||
|
||
def forwards_ops(self) -> Sequence[operations.SqlOperation]: | ||
return [ | ||
operations.AddIndex( | ||
storage_set=StorageSetKey.GENERIC_METRICS_COUNTERS, | ||
table_name="generic_metric_counters_aggregated_local", | ||
index_name="set_idx_use_case_id", | ||
index_expression="use_case_id", | ||
index_type="set(0)", | ||
granularity=1, | ||
target=operations.OperationTarget.LOCAL, | ||
), | ||
operations.AddIndex( | ||
storage_set=StorageSetKey.GENERIC_METRICS_SETS, | ||
table_name="generic_metric_sets_local", | ||
index_name="set_idx_use_case_id", | ||
index_expression="use_case_id", | ||
index_type="set(0)", | ||
granularity=1, | ||
target=operations.OperationTarget.LOCAL, | ||
), | ||
operations.AddIndex( | ||
storage_set=StorageSetKey.GENERIC_METRICS_DISTRIBUTIONS, | ||
table_name="generic_metric_distributions_aggregated_local", | ||
index_name="set_idx_use_case_id", | ||
index_expression="use_case_id", | ||
index_type="set(0)", | ||
granularity=1, | ||
target=operations.OperationTarget.LOCAL, | ||
), | ||
operations.AddIndex( | ||
storage_set=StorageSetKey.GENERIC_METRICS_GAUGES, | ||
table_name="generic_metric_gauges_aggregated_local", | ||
index_name="set_idx_use_case_id", | ||
index_expression="use_case_id", | ||
index_type="set(0)", | ||
granularity=1, | ||
target=operations.OperationTarget.LOCAL, | ||
), | ||
] | ||
|
||
def backwards_ops(self) -> Sequence[operations.SqlOperation]: | ||
return [ | ||
operations.DropIndex( | ||
storage_set=StorageSetKey.GENERIC_METRICS_GAUGES, | ||
table_name="generic_metric_gauges_aggregated_local", | ||
index_name="set_idx_use_case_id", | ||
target=operations.OperationTarget.LOCAL, | ||
), | ||
operations.DropIndex( | ||
storage_set=StorageSetKey.GENERIC_METRICS_DISTRIBUTIONS, | ||
table_name="generic_metric_distributions_aggregated_local", | ||
index_name="set_idx_use_case_id", | ||
target=operations.OperationTarget.LOCAL, | ||
), | ||
operations.DropIndex( | ||
storage_set=StorageSetKey.GENERIC_METRICS_COUNTERS, | ||
table_name="generic_metric_counters_aggregated_local", | ||
index_name="set_idx_use_case_id", | ||
target=operations.OperationTarget.LOCAL, | ||
), | ||
operations.DropIndex( | ||
storage_set=StorageSetKey.GENERIC_METRICS_SETS, | ||
table_name="generic_metric_sets_local", | ||
index_name="set_idx_use_case_id", | ||
target=operations.OperationTarget.LOCAL, | ||
), | ||
] |