Skip to content

Commit

Permalink
feat(cardinality): Add clickhouse host and port parameters (#5237)
Browse files Browse the repository at this point in the history
In our prod systems, there seems to be an issue when cron jobs try to
access other systems using envoy. In order to bypass that, we can use
the dns name of the cluster to reach the clickhouse host. That is
what we do today in the optimize and cleanup jobs as well. So added the
requirement to pass in clickhouse host information as a CLI argument.
  • Loading branch information
nikhars authored Dec 20, 2023
1 parent 9632d85 commit 66728f7
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions snuba/cli/spans_cardinality_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from snuba import settings
from snuba.admin.notifications.slack.client import SlackClient
from snuba.clickhouse.native import ClickhousePool
from snuba.clickhouse.span_cardinality_analyzer import (
SpanGroupingCardinalityResult,
span_grouping_cardinality_query,
Expand All @@ -30,9 +31,22 @@ def write_cardnaltiy_to_csv(


@click.command()
@click.option(
"--clickhouse-host",
help="Clickhouse server to write to.",
required=True,
)
@click.option(
"--clickhouse-port",
type=int,
help="Clickhouse native port to write to.",
required=True,
)
@click.option("--log-level", help="Logging level to use.")
def spans_cardinality_analyzer(
*,
clickhouse_host: str,
clickhouse_port: int,
log_level: Optional[str] = None,
) -> None:
"""
Expand All @@ -47,9 +61,15 @@ def spans_cardinality_analyzer(

storage_key = StorageKey("generic_metrics_distributions")
storage = get_storage(storage_key)
(clickhouse_user, clickhouse_password) = storage.get_cluster().get_credentials()

connection = storage.get_cluster().get_query_connection(
ClickhouseClientSettings.CARDINALITY_ANALYZER
connection = ClickhousePool(
host=clickhouse_host,
port=clickhouse_port,
user=clickhouse_user,
password=clickhouse_password,
database=storage.get_cluster().get_database(),
client_settings=ClickhouseClientSettings.CARDINALITY_ANALYZER.value.settings,
)

# Get the distinct span modules we are ingesting.
Expand Down

0 comments on commit 66728f7

Please sign in to comment.