Skip to content

Commit

Permalink
fix(generic-metrics): Add raw tags hash to gauges dist table (#5049)
Browse files Browse the repository at this point in the history
* add raw tags hash to gauges dist table

* add migration to group loader
  • Loading branch information
enochtangg authored Nov 16, 2023
1 parent ab0a579 commit 488dd4f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions snuba/migrations/group_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def get_migrations(self) -> Sequence[str]:
"0023_gauges_raw_table",
"0024_gauges_mv",
"0025_counters_add_raw_tags_hash_column",
"0026_gauges_add_raw_tags_hash_column",
]


Expand Down
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,
),
]

0 comments on commit 488dd4f

Please sign in to comment.