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(profiles): Add a dataset to store profile chunks #5895

Merged
merged 20 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions snuba/clusters/storage_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"SPANS": "spans",
"GROUP_ATTRIBUTES": "group_attributes",
"METRICS_SUMMARIES": "metrics_summaries",
"PROFILE_CHUNKS": "profile_chunks",
}


Expand Down
10 changes: 10 additions & 0 deletions snuba/migrations/group_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,13 @@ def get_migrations(self) -> Sequence[str]:
"0002_metrics_summaries_add_tags_hashmap",
"0003_metrics_summaries_add_segment_id_duration_group_columns",
]


class ProfileChunksLoader(DirectoryLoader):
def __init__(self) -> None:
super().__init__("snuba.snuba_migrations.profile_chunks")

def get_migrations(self) -> Sequence[str]:
return [
"0001_create_profile_chunks_table",
]
8 changes: 8 additions & 0 deletions snuba/migrations/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
MetricsLoader,
MetricsSummariesLoader,
OutcomesLoader,
ProfileChunksLoader,
ProfilesLoader,
QuerylogLoader,
ReplaysLoader,
Expand Down Expand Up @@ -43,6 +44,7 @@ class MigrationGroup(Enum):
SPANS = "spans"
GROUP_ATTRIBUTES = "group_attributes"
METRICS_SUMMARIES = "metrics_summaries"
PROFILE_CHUNKS = "profile_chunks"


# Migration groups are mandatory by default. Specific groups can
Expand All @@ -59,6 +61,7 @@ class MigrationGroup(Enum):
MigrationGroup.SEARCH_ISSUES,
MigrationGroup.GROUP_ATTRIBUTES,
MigrationGroup.METRICS_SUMMARIES,
MigrationGroup.PROFILE_CHUNKS,
}


Expand Down Expand Up @@ -169,6 +172,11 @@ def __init__(
storage_sets_keys={StorageSetKey.METRICS_SUMMARIES},
readiness_state=ReadinessState.PARTIAL,
),
MigrationGroup.PROFILE_CHUNKS: _MigrationGroup(
loader=ProfileChunksLoader(),
storage_sets_keys={StorageSetKey.PROFILE_CHUNKS},
readiness_state=ReadinessState.PARTIAL,
Copy link
Member

Choose a reason for hiding this comment

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

Does the ClickHouse cluster already exist in SaaS (US + DE) and S4S? If the table is suppose to live the profiles cluster, has the storage_set been added there? If this isn't done yet, we should set the readiness state to ReadinessState.LIMITED for now so that GoCD doesn't try to run these migrations on a cluster that doesn't exist.

Copy link
Contributor Author

@phacops phacops May 14, 2024

Choose a reason for hiding this comment

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

The ClickHouse cluster we'd use exists in all environments (us, de, s4s, all STs).

I also have https://github.com/getsentry/ops/pull/10526 to configure it for all environments.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member

Choose a reason for hiding this comment

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

which cluster are you using @phacops ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The cluster dedicated to profiling.

),
}


Expand Down
1 change: 1 addition & 0 deletions snuba/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"group_attributes",
"generic_metrics_gauges",
"metrics_summaries",
"profile_chunks",
},
"single_node": True,
},
Expand Down
1 change: 1 addition & 0 deletions snuba/settings/settings_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"group_attributes",
"generic_metrics_gauges",
"metrics_summaries",
"profile_chunks",
},
"single_node": False,
"cluster_name": "cluster_one_sh",
Expand Down
1 change: 1 addition & 0 deletions snuba/settings/settings_test_distributed_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"group_attributes",
"generic_metrics_gauges",
"metrics_summaries",
"profile_chunks",
},
"single_node": False,
"cluster_name": "storage_cluster",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from typing import List, Sequence

from snuba.clickhouse.columns import UUID, Column, DateTime64, UInt
from snuba.clusters.storage_sets import StorageSetKey
from snuba.migrations import migration, operations, table_engines
from snuba.migrations.columns import MigrationModifiers as Modifiers
from snuba.migrations.operations import OperationTarget, SqlOperation

storage_set = StorageSetKey.PROFILE_CHUNKS
phacops marked this conversation as resolved.
Show resolved Hide resolved
table_prefix = "profile_chunks"
local_table_name = f"{table_prefix}_local"
dist_table_name = f"{table_prefix}_dist"

columns: List[Column[Modifiers]] = [
Column("project_id", UInt(64)),
Column("profiler_id", UUID()),
Column("chunk_id", UUID()),
phacops marked this conversation as resolved.
Show resolved Hide resolved
Column(
"start_timestamp",
DateTime64(
phacops marked this conversation as resolved.
Show resolved Hide resolved
precision=6,
modifiers=Modifiers(codecs=["DoubleDelta"]),
),
),
Column(
"end_timestamp",
DateTime64(
precision=6,
modifiers=Modifiers(codecs=["DoubleDelta"]),
),
),
Column("retention_days", UInt(16)),
Column("partition", UInt(16)),
Column("offset", UInt(64)),
]


class Migration(migration.ClickhouseNodeMigration):
blocking = False

def forwards_ops(self) -> Sequence[SqlOperation]:
return [
operations.CreateTable(
storage_set=storage_set,
table_name=local_table_name,
columns=columns,
engine=table_engines.ReplacingMergeTree(
order_by="(project_id, profiler_id, start_timestamp, cityHash64(chunk_id))",
partition_by="(retention_days, toStartOfDay(start_timestamp))",
sample_by="cityHash64(chunk_id)",
settings={"index_granularity": "8192"},
storage_set=storage_set,
ttl="toDateTime(end_timestamp) + toIntervalDay(retention_days)",
),
target=OperationTarget.LOCAL,
),
operations.CreateTable(
storage_set=storage_set,
table_name=dist_table_name,
columns=columns,
engine=table_engines.Distributed(
local_table_name=local_table_name,
sharding_key="cityHash64(profiler_id)",
),
target=OperationTarget.DISTRIBUTED,
),
]

def backwards_ops(self) -> Sequence[SqlOperation]:
return [
operations.DropTable(
storage_set=storage_set,
table_name=dist_table_name,
target=OperationTarget.DISTRIBUTED,
),
operations.DropTable(
storage_set=storage_set,
table_name=local_table_name,
target=OperationTarget.LOCAL,
),
]
Loading