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(breakdowns): Schema change for span op breakdowns #1761

Merged
merged 3 commits into from
Mar 30, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(breakdowns): Schema change for span op breakdowns
dashed committed Mar 24, 2021
commit 010838b818d864986ae02718d569237c7a22403f
1 change: 1 addition & 0 deletions snuba/datasets/storages/transactions.py
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@
("contexts", Nested([("key", String()), ("value", String())])),
("_contexts_flattened", String()),
("measurements", Nested([("key", String()), ("value", Float(64))]),),
("span_op_breakdowns", Nested([("key", String()), ("value", Float(64))]),),
("partition", UInt(16)),
("offset", UInt(64)),
("message_timestamp", DateTime()),
1 change: 1 addition & 0 deletions snuba/migrations/groups.py
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@ def get_migrations(self) -> Sequence[str]:
"0008_transactions_add_timestamp_index",
"0009_transactions_fix_title_and_message",
"0010_transactions_nullable_trace_id",
"0011_transactions_add_span_op_breakdowns",
]


Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from typing import Sequence

from snuba.clickhouse.columns import Column, Float, Nested, String
from snuba.clusters.storage_sets import StorageSetKey
from snuba.migrations import migration, operations
from snuba.migrations.columns import MigrationModifiers as Modifiers


class Migration(migration.ClickhouseNodeMigration):
"""
Adds the span_op_breakdowns nested column
"""

blocking = False

def forwards_local(self) -> Sequence[operations.SqlOperation]:
return [
operations.AddColumn(
storage_set=StorageSetKey.TRANSACTIONS,
table_name="transactions_local",
column=Column(
"span_op_breakdowns",
Nested(
[
("key", String(Modifiers(low_cardinality=True))),
("value", Float(64)),
]
),
),
after="measurements",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work.
the measurements column does not exist after the DDL operation that creates it.
After such ddl you have measurements.key and measurements.value columns.
So this should be
after="measurements.value"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fpacifici Good catch. I updated to after="measurements.value".

Interestingly, the span_op_breakdowns columns are added after the measurements columns in my local Clickhouse instance.

),
]

def backwards_local(self) -> Sequence[operations.SqlOperation]:
return [
operations.DropColumn(
StorageSetKey.TRANSACTIONS, "transactions_local", "span_op_breakdowns"
),
]

def forwards_dist(self) -> Sequence[operations.SqlOperation]:
return [
operations.AddColumn(
storage_set=StorageSetKey.TRANSACTIONS,
table_name="transactions_dist",
column=Column(
"span_op_breakdowns",
Nested(
[
("key", String(Modifiers(low_cardinality=True))),
("value", Float(64)),
]
),
),
after="measurements",
),
]

def backwards_dist(self) -> Sequence[operations.SqlOperation]:
return [
operations.DropColumn(
StorageSetKey.TRANSACTIONS, "transactions_dist", "span_op_breakdowns"
)
]