-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(generic-metrics): Add raw tags hash to gauges dist table (#5049)
* add raw tags hash to gauges dist table * add migration to group loader
- Loading branch information
1 parent
ab0a579
commit 488dd4f
Showing
2 changed files
with
69 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
68 changes: 68 additions & 0 deletions
68
snuba/snuba_migrations/generic_metrics/0026_gauges_add_raw_tags_hash_column.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,68 @@ | ||
from typing import Sequence | ||
|
||
from snuba.clickhouse.columns import Array, Column, UInt | ||
from snuba.clusters.storage_sets import StorageSetKey | ||
from snuba.datasets.storages.tags_hash_map import ( | ||
hash_map_int_column_definition, | ||
hash_map_int_key_str_value_column_definition, | ||
) | ||
from snuba.migrations import migration, operations | ||
from snuba.migrations.columns import MigrationModifiers as Modifiers | ||
|
||
|
||
class Migration(migration.ClickhouseNodeMigration): | ||
blocking = False | ||
dist_table_name = "generic_metric_gauges_aggregated_dist" | ||
storage_set_key = StorageSetKey.GENERIC_METRICS_GAUGES | ||
|
||
def forwards_ops(self) -> Sequence[operations.SqlOperation]: | ||
return [ | ||
operations.AddColumn( | ||
storage_set=self.storage_set_key, | ||
table_name=self.dist_table_name, | ||
column=Column( | ||
"_indexed_tags_hash", | ||
Array( | ||
UInt(64), | ||
Modifiers( | ||
materialized=hash_map_int_column_definition( | ||
"tags.key", "tags.indexed_value" | ||
) | ||
), | ||
), | ||
), | ||
target=operations.OperationTarget.DISTRIBUTED, | ||
), | ||
operations.AddColumn( | ||
storage_set=self.storage_set_key, | ||
table_name=self.dist_table_name, | ||
column=Column( | ||
"_raw_tags_hash", | ||
Array( | ||
UInt(64), | ||
Modifiers( | ||
materialized=hash_map_int_key_str_value_column_definition( | ||
"tags.key", "tags.raw_value" | ||
) | ||
), | ||
), | ||
), | ||
target=operations.OperationTarget.DISTRIBUTED, | ||
), | ||
] | ||
|
||
def backwards_ops(self) -> Sequence[operations.SqlOperation]: | ||
return [ | ||
operations.DropColumn( | ||
column_name="_raw_tags_hash", | ||
storage_set=self.storage_set_key, | ||
table_name=self.dist_table_name, | ||
target=operations.OperationTarget.DISTRIBUTED, | ||
), | ||
operations.DropColumn( | ||
column_name="_indexed_tags_hash", | ||
storage_set=self.storage_set_key, | ||
table_name=self.dist_table_name, | ||
target=operations.OperationTarget.DISTRIBUTED, | ||
), | ||
] |