Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

snuba events_analytics_ platform requires clickhouse 23.3 #1474

Open
1 task done
ntcong opened this issue Sep 24, 2024 · 7 comments
Open
1 task done

snuba events_analytics_ platform requires clickhouse 23.3 #1474

ntcong opened this issue Sep 24, 2024 · 7 comments

Comments

@ntcong
Copy link
Contributor

ntcong commented Sep 24, 2024

Issue submitter TODO list

  • I've searched for an already existing issues here

Describe the bug (actual behavior)

The upgrading process failed with snuba-migrate because events_analytics_ platform can't be migrated
Executing snuba migrations migrate manually and it fails

  File "/usr/local/lib/python3.11/site-packages/clickhouse_driver/client.py", line 237, in receive_packet
    raise packet.exception
clickhouse_driver.errors.ServerException: Code: 36.
DB::Exception: Codec DoubleDelta does not accept any arguments. Stack trace:

0. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<
char> > const&, int, bool) @ 0xa40325a in /usr/bin/clickhouse
1. ? @ 0x140fec52 in /usr/bin/clickhouse
2. ? @ 0x14e1cf6e in /usr/bin/clickhouse
3. DB::ISerialization::enumerateStreams(DB::ISerialization::SubstreamPath&, std::__1::function<void (DB::I
Serialization::SubstreamPath const&)> const&, DB::ISerialization::SubstreamData const&) const @ 0x14238771
 in /usr/bin/clickhouse

Expected behavior

migrations successful

values.yaml

.

Helm chart version

25.9.0

Steps to reproduce

official self-hosted image uses 23.8 and automatically upgrade clickhouse to 23.8
https://github.com/getsentry/self-hosted/blob/master/install/upgrade-clickhouse.sh

I tried setting clickhouse image to 23.3.19.32 and the migrations went through.

Screenshots

No response

Logs

No response

Additional context

No response

@patsevanton
Copy link
Contributor

Please write your values.yaml

@shcherbak
Copy link
Contributor

shcherbak commented Sep 27, 2024

we facing similar problem with release 24.8
getsentry/snuba#6355
there is a syntax error in migration query

events_analytics_platform (readiness_state: limited)
[-]  0001_spans (IN PROGRESS)

@swade1987
Copy link

swade1987 commented Oct 4, 2024

I also raised the same issue #1508 but mine is for a total fresh installation.

When you read this error: getsentry/snuba#6355, it matches the exact point at which my failure occurred.

2024-10-04 11:19:58,663 Query: SELECT version FROM migrations_dist FINAL WHERE group = 'events_analytics_platform' AND migration_id = '0001_spans’; ⁠

Then I have a failure straight after ⁠ 0001_spans ⁠

@patsevanton
Copy link
Contributor

patsevanton commented Oct 14, 2024

Try tag 25.16.0

@patsevanton
Copy link
Contributor

@Mokto
Copy link
Contributor

Mokto commented Nov 23, 2024

This issue is stale because it has been open for 30 days with no activity.

@Mokto Mokto added the stale label Nov 23, 2024
@tyr1k
Copy link

tyr1k commented Dec 5, 2024

events_analytics_platform (readiness_state: limited)
[-]  0001_spans (IN PROGRESS)

Fix this with command:

snuba migrations reverse --group events_analytics_platform --migration-id 0001_spans

aaaand after use this code

/usr/src/snuba/snuba/snuba_migrations/events_analytics_platform/0001_spans.py
from typing import List, Sequence

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 AddIndicesData, OperationTarget, SqlOperation
from snuba.utils.schemas import (
    UUID,
    Column,
    DateTime,
    DateTime64,
    Float,
    Int,
    Map,
    String,
    UInt,
)

storage_set_name = StorageSetKey.EVENTS_ANALYTICS_PLATFORM
local_table_name = "eap_spans_local"
dist_table_name = "eap_spans_dist"
num_attr_buckets = 20

columns: List[Column[Modifiers]] = [
    Column("organization_id", UInt(64)),
    Column("project_id", UInt(64)),
    Column("service", String(Modifiers(codecs=["ZSTD(1)"]))),
    Column("trace_id", UUID()),
    Column("span_id", UInt(64)),
    Column("parent_span_id", UInt(64, Modifiers(codecs=["ZSTD(1)"]))),
    Column("segment_id", UInt(64, Modifiers(codecs=["ZSTD(1)"]))),
    Column("segment_name", String(Modifiers(codecs=["ZSTD(1)"]))),
    Column("is_segment", UInt(8, Modifiers(codecs=["T64", "ZSTD(1)"]))),
    Column("_sort_timestamp", DateTime(Modifiers(codecs=["DoubleDelta", "ZSTD(1)"]))),
    Column(
        "start_timestamp",
        DateTime64(6, modifiers=Modifiers(codecs=["DoubleDelta", "ZSTD(1)"])),
    ),
    Column(
        "end_timestamp",
        DateTime64(6, modifiers=Modifiers(codecs=["DoubleDelta", "ZSTD(1)"])),
    ),
    Column(
        "duration_ms",
        UInt(32, modifiers=Modifiers(codecs=["DoubleDelta", "ZSTD(1)"])),
    ),
    Column("exclusive_time_ms", Float(64, modifiers=Modifiers(codecs=["ZSTD(1)"]))),
    Column(
        "retention_days",
        UInt(16, modifiers=Modifiers(codecs=["DoubleDelta", "ZSTD(1)"])),
    ),
    Column("name", String(modifiers=Modifiers(codecs=["ZSTD(1)"]))),
    Column("sampling_factor", Float(64, modifiers=Modifiers(codecs=["ZSTD(1)"]))),
    Column("sampling_weight", Float(64, modifiers=Modifiers(codecs=["ZSTD(1)"]))),
    Column("sign", Int(8, modifiers=Modifiers(codecs=["DoubleDelta"]))),
]
columns.extend(
    [
        Column(
            f"attr_str_{i}",
            Map(String(), String(), modifiers=Modifiers(codecs=["ZSTD(1)"])),
        )
        for i in range(num_attr_buckets)
    ]
)

columns.extend(
    [
        Column(
            f"attr_num_{i}",
            Map(String(), Float(64), modifiers=Modifiers(codecs=["ZSTD(1)"])),
        )
        for i in range(num_attr_buckets)
    ]
)

indices: Sequence[AddIndicesData] = (
    [
        AddIndicesData(
            name="bf_trace_id",
            expression="toString(trace_id)",  # Convert UUID to string
            type="bloom_filter",
            granularity=1,
        )
    ]
    + [
        AddIndicesData(
            name=f"bf_attr_str_{i}",
            expression=f"toString(mapKeys(attr_str_{i}))",  # Convert Map keys to strings
            type="bloom_filter",
            granularity=1,
        )
        for i in range(num_attr_buckets)
    ]
    + [
        AddIndicesData(
            name=f"ngrambf_attr_str_val_{i}",
            expression=f"toString(mapValues(attr_str_{i}))",  # Convert Map values ​​to strings
            type="ngrambf_v1(4, 1024, 10, 1)",
            granularity=1,
        )
        for i in range(num_attr_buckets)
    ]
)

class Migration(migration.ClickhouseNodeMigration):
    blocking = False

    def forwards_ops(self) -> Sequence[SqlOperation]:
        res: List[SqlOperation] = [
            operations.CreateTable(
                storage_set=storage_set_name,
                table_name=local_table_name,
                columns=columns,
                engine=table_engines.CollapsingMergeTree(
                    primary_key="(organization_id, _sort_timestamp, trace_id)",
                    order_by="(organization_id, _sort_timestamp, trace_id, span_id)",
                    sign_column="sign",
                    partition_by="(toMonday(_sort_timestamp))",
                    settings={"index_granularity": "8192"},
                    storage_set=storage_set_name,
                    ttl="_sort_timestamp + toIntervalDay(retention_days)",
                ),
                target=OperationTarget.LOCAL,
            ),
            operations.CreateTable(
                storage_set=storage_set_name,
                table_name=dist_table_name,
                columns=columns,
                engine=table_engines.Distributed(
                    local_table_name=local_table_name,
                    sharding_key="cityHash64(reinterpretAsUInt128(trace_id))",
                ),
                target=OperationTarget.DISTRIBUTED,
            ),
            operations.AddIndices(
                storage_set=storage_set_name,
                table_name=local_table_name,
                indices=indices,
                target=OperationTarget.LOCAL,
            ),
        ]
        return res

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

With this code you can do

   snuba migrations run --group events_analytics_platform --migration-id 0001_spans
   snuba migrations run --group events_analytics_platform --migration-id 0002_spans_attributes_mv
   snuba migrations run --group events_analytics_platform --migration-id 0003_eap_spans_project_id_index
   snuba migrations run --group events_analytics_platform --migration-id 0004_modify_sampling_weight
   snuba migrations run --group events_analytics_platform --migration-id 0005_remove_attribute_mv
   snuba migrations run --group events_analytics_platform --migration-id 0006_drop_attribute_key_project_id_indexes
   snuba migrations run --group events_analytics_platform --migration-id 0007_drop_project_id_index
   snuba migrations run --group events_analytics_platform --migration-id 0008_drop_index_attribute_key_bucket_0

On 0009 migration you will encounter an alter_sync error, which is not supported in the current version of ClickHouse. To resolve this issue, you need change code like this:

/usr/src/snuba/snuba/snuba_migrations/events_analytics_platform/0009_drop_index_attribute_key_buckets_1_19.py
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]:
        indices_to_drop = [
            f"bf_attr_num_{bucket}" for bucket in range(1, 20)
        ] + [
            f"bf_attr_str_{bucket}" for bucket in range(1, 20)
        ]

        drop_indices_statements = ", ".join(
            f"DROP INDEX IF EXISTS {index_name}" for index_name in indices_to_drop
        )

        return [
            operations.RunSql(
                storage_set=StorageSetKey.EVENTS_ANALYTICS_PLATFORM,
                statement=f"""
                ALTER TABLE eap_spans_local
                {drop_indices_statements}
                SETTINGS mutations_sync=0;
                """,
                target=operations.OperationTarget.LOCAL,
            )
        ]

    def backwards_ops(self) -> Sequence[operations.SqlOperation]:
        return []
snuba migrations run --group events_analytics_platform --migration-id 0009_drop_index_attribute_key_buckets_1_19

and the same error for 0010, use this:

/usr/src/snuba/snuba/snuba_migrations/events_analytics_platform/0010_drop_indexes_on_attribute_values.py
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]:
        indices_to_drop = [
            f"bf_attr_str_val_{bucket}" for bucket in range(0, 20)
        ]

        drop_indices_statements = ", ".join(
            f"DROP INDEX IF EXISTS {index_name}" for index_name in indices_to_drop
        )

        return [
            operations.RunSql(
                storage_set=StorageSetKey.EVENTS_ANALYTICS_PLATFORM,
                statement=f"""
                ALTER TABLE eap_spans_local
                {drop_indices_statements}
                SETTINGS mutations_sync=0;
                """,
                target=operations.OperationTarget.LOCAL,
            )
        ]

    def backwards_ops(self) -> Sequence[operations.SqlOperation]:
        return []
snuba migrations run --group events_analytics_platform --migration-id 0010_drop_indexes_on_attribute_values
snuba migrations run --group events_analytics_platform --migration-id 0011_span_attribute_table
snuba migrations run --group events_analytics_platform --migration-id 0012_span_attribute_table_numeric
snuba migrations run --group events_analytics_platform --migration-id 0013_span_attribute_table_shard_keys

@Mokto Mokto removed the stale label Dec 6, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants