prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Snuba cleanup for sentry onpremise
  ### Environment
  
  Sentry self-hosted 21.3.0 (based on docker-compose from here https://github.com/getsentry/onpremise/blob/21.3.0/docker-compose.yml)
  
  ### Steps to Reproduce
  
  1) Setup all containers and up snuba-cleanup container
  2) Check logs for snuba-cleanup: Every 5 minutes in log - `Dropped 0 partitions on None`
  It looks like variable CLICKHOUSE_HOST is ignored here
  https://github.com/getsentry/snuba/blob/41d7fe76aaf8a594e8f6e84015607dcde3f67ad4/snuba/cli/cleanup.py#L13
  After manual run command in container - `snuba cleanup --clickhouse-host CLICKHOUSE_HOST_HERE --dry-run True`
  i got `Dropped 0 partitions on CLICKHOUSE_HOST_HERE`
  
  ### Expected Result
  
  Pass variable https://github.com/getsentry/onpremise/blob/bdd2686021cfea07507bc07d2756ac34a775c680/docker-compose.yml#L44 into cleanup command
  
  ### Actual Result
  
  variable is `None` instead of clickhouse host
  
  I'am not sure, bug this or not.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `snuba/cli/cleanup.py`
  Content:
  ```
  1 from typing import Optional
  2 
  3 import click
  4 
  5 from snuba.clusters.cluster import ClickhouseClientSettings
  6 from snuba.datasets.storages import StorageKey
  7 from snuba.datasets.storages.factory import get_writable_storage
  8 from snuba.environment import setup_logging
  9 
  10 
  11 @click.command()
  12 @click.option(
  13     "--clickhouse-host", help="Clickhouse server to write to.",
  14 )
  15 @click.option(
  16     "--clickhouse-port", type=int, help="Clickhouse native port to write to.",
  17 )
  18 @click.option(
  19     "--dry-run",
  20     type=bool,
  21     default=True,
  22     help="If true, only print which partitions would be dropped.",
  23 )
  24 @click.option(
  25     "--storage",
  26     "storage_name",
  27     default="events",
  28     type=click.Choice(["events", "errors", "transactions"]),
  29     help="The storage to target",
  30 )
  31 @click.option("--log-level", help="Logging level to use.")
  32 def cleanup(
  33     *,
  34     clickhouse_host: Optional[str],
  35     clickhouse_port: Optional[int],
  36     dry_run: bool,
  37     storage_name: str,
  38     log_level: Optional[str] = None,
  39 ) -> None:
  40     """
  41     Deletes stale partitions for ClickHouse tables
  42     """
  43 
  44     setup_logging(log_level)
  45 
  46     from snuba.cleanup import run_cleanup, logger
  47     from snuba.clickhouse.native import ClickhousePool
  48 
  49     storage = get_writable_storage(StorageKey(storage_name))
  50 
  51     (clickhouse_user, clickhouse_password,) = storage.get_cluster().get_credentials()
  52 
  53     database = storage.get_cluster().get_database()
  54 
  55     if clickhouse_host and clickhouse_port:
  56         connection = ClickhousePool(
  57             clickhouse_host,
  58             clickhouse_port,
  59             clickhouse_user,
  60             clickhouse_password,
  61             database,
  62         )
  63     elif not storage.get_cluster().is_single_node():
  64         raise click.ClickException("Provide ClickHouse host and port for cleanup")
  65     else:
  66         connection = storage.get_cluster().get_query_connection(
  67             ClickhouseClientSettings.CLEANUP
  68         )
  69 
  70     num_dropped = run_cleanup(connection, storage, database, dry_run=dry_run)
  71     logger.info("Dropped %s partitions on %s" % (num_dropped, clickhouse_host))
  72
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/snuba/cli/cleanup.py b/snuba/cli/cleanup.py
  --- a/snuba/cli/cleanup.py
  +++ b/snuba/cli/cleanup.py
  @@ -50,7 +50,8 @@
   
       (clickhouse_user, clickhouse_password,) = storage.get_cluster().get_credentials()
   
  -    database = storage.get_cluster().get_database()
  +    cluster = storage.get_cluster()
  +    database = cluster.get_database()
   
       if clickhouse_host and clickhouse_port:
           connection = ClickhousePool(
  @@ -60,12 +61,12 @@
               clickhouse_password,
               database,
           )
  -    elif not storage.get_cluster().is_single_node():
  +    elif not cluster.is_single_node():
           raise click.ClickException("Provide ClickHouse host and port for cleanup")
       else:
  -        connection = storage.get_cluster().get_query_connection(
  +        connection = cluster.get_query_connection(
               ClickhouseClientSettings.CLEANUP
           )
   
       num_dropped = run_cleanup(connection, storage, database, dry_run=dry_run)
  -    logger.info("Dropped %s partitions on %s" % (num_dropped, clickhouse_host))
  +    logger.info("Dropped %s partitions on %s" % (num_dropped, cluster))
  
verification_info: {"golden_diff": "diff --git a/snuba/cli/cleanup.py b/snuba/cli/cleanup.py\n--- a/snuba/cli/cleanup.py\n+++ b/snuba/cli/cleanup.py\n@@ -50,7 +50,8 @@\n \n     (clickhouse_user, clickhouse_password,) = storage.get_cluster().get_credentials()\n \n-    database = storage.get_cluster().get_database()\n+    cluster = storage.get_cluster()\n+    database = cluster.get_database()\n \n     if clickhouse_host and clickhouse_port:\n         connection = ClickhousePool(\n@@ -60,12 +61,12 @@\n             clickhouse_password,\n             database,\n         )\n-    elif not storage.get_cluster().is_single_node():\n+    elif not cluster.is_single_node():\n         raise click.ClickException(\"Provide ClickHouse host and port for cleanup\")\n     else:\n-        connection = storage.get_cluster().get_query_connection(\n+        connection = cluster.get_query_connection(\n             ClickhouseClientSettings.CLEANUP\n         )\n \n     num_dropped = run_cleanup(connection, storage, database, dry_run=dry_run)\n-    logger.info(\"Dropped %s partitions on %s\" % (num_dropped, clickhouse_host))\n+    logger.info(\"Dropped %s partitions on %s\" % (num_dropped, cluster))\n", "issue": "Snuba cleanup for sentry onpremise\n### Environment\r\n\r\nSentry self-hosted 21.3.0 (based on docker-compose from here https://github.com/getsentry/onpremise/blob/21.3.0/docker-compose.yml)\r\n\r\n### Steps to Reproduce\r\n\r\n1) Setup all containers and up snuba-cleanup container\r\n2) Check logs for snuba-cleanup: Every 5 minutes in log - `Dropped 0 partitions on None`\r\nIt looks like variable CLICKHOUSE_HOST is ignored here\r\nhttps://github.com/getsentry/snuba/blob/41d7fe76aaf8a594e8f6e84015607dcde3f67ad4/snuba/cli/cleanup.py#L13\r\nAfter manual run command in container - `snuba cleanup --clickhouse-host CLICKHOUSE_HOST_HERE --dry-run True`\r\ni got `Dropped 0 partitions on CLICKHOUSE_HOST_HERE`\r\n\r\n### Expected Result\r\n\r\nPass variable https://github.com/getsentry/onpremise/blob/bdd2686021cfea07507bc07d2756ac34a775c680/docker-compose.yml#L44 into cleanup command\r\n\r\n### Actual Result\r\n\r\nvariable is `None` instead of clickhouse host\r\n\r\nI'am not sure, bug this or not.\n", "before_files": [{"content": "from typing import Optional\n\nimport click\n\nfrom snuba.clusters.cluster import ClickhouseClientSettings\nfrom snuba.datasets.storages import StorageKey\nfrom snuba.datasets.storages.factory import get_writable_storage\nfrom snuba.environment import setup_logging\n\n\n@click.command()\n@click.option(\n    \"--clickhouse-host\", help=\"Clickhouse server to write to.\",\n)\n@click.option(\n    \"--clickhouse-port\", type=int, help=\"Clickhouse native port to write to.\",\n)\n@click.option(\n    \"--dry-run\",\n    type=bool,\n    default=True,\n    help=\"If true, only print which partitions would be dropped.\",\n)\n@click.option(\n    \"--storage\",\n    \"storage_name\",\n    default=\"events\",\n    type=click.Choice([\"events\", \"errors\", \"transactions\"]),\n    help=\"The storage to target\",\n)\n@click.option(\"--log-level\", help=\"Logging level to use.\")\ndef cleanup(\n    *,\n    clickhouse_host: Optional[str],\n    clickhouse_port: Optional[int],\n    dry_run: bool,\n    storage_name: str,\n    log_level: Optional[str] = None,\n) -> None:\n    \"\"\"\n    Deletes stale partitions for ClickHouse tables\n    \"\"\"\n\n    setup_logging(log_level)\n\n    from snuba.cleanup import run_cleanup, logger\n    from snuba.clickhouse.native import ClickhousePool\n\n    storage = get_writable_storage(StorageKey(storage_name))\n\n    (clickhouse_user, clickhouse_password,) = storage.get_cluster().get_credentials()\n\n    database = storage.get_cluster().get_database()\n\n    if clickhouse_host and clickhouse_port:\n        connection = ClickhousePool(\n            clickhouse_host,\n            clickhouse_port,\n            clickhouse_user,\n            clickhouse_password,\n            database,\n        )\n    elif not storage.get_cluster().is_single_node():\n        raise click.ClickException(\"Provide ClickHouse host and port for cleanup\")\n    else:\n        connection = storage.get_cluster().get_query_connection(\n            ClickhouseClientSettings.CLEANUP\n        )\n\n    num_dropped = run_cleanup(connection, storage, database, dry_run=dry_run)\n    logger.info(\"Dropped %s partitions on %s\" % (num_dropped, clickhouse_host))\n", "path": "snuba/cli/cleanup.py"}], "after_files": [{"content": "from typing import Optional\n\nimport click\n\nfrom snuba.clusters.cluster import ClickhouseClientSettings\nfrom snuba.datasets.storages import StorageKey\nfrom snuba.datasets.storages.factory import get_writable_storage\nfrom snuba.environment import setup_logging\n\n\n@click.command()\n@click.option(\n    \"--clickhouse-host\", help=\"Clickhouse server to write to.\",\n)\n@click.option(\n    \"--clickhouse-port\", type=int, help=\"Clickhouse native port to write to.\",\n)\n@click.option(\n    \"--dry-run\",\n    type=bool,\n    default=True,\n    help=\"If true, only print which partitions would be dropped.\",\n)\n@click.option(\n    \"--storage\",\n    \"storage_name\",\n    default=\"events\",\n    type=click.Choice([\"events\", \"errors\", \"transactions\"]),\n    help=\"The storage to target\",\n)\n@click.option(\"--log-level\", help=\"Logging level to use.\")\ndef cleanup(\n    *,\n    clickhouse_host: Optional[str],\n    clickhouse_port: Optional[int],\n    dry_run: bool,\n    storage_name: str,\n    log_level: Optional[str] = None,\n) -> None:\n    \"\"\"\n    Deletes stale partitions for ClickHouse tables\n    \"\"\"\n\n    setup_logging(log_level)\n\n    from snuba.cleanup import run_cleanup, logger\n    from snuba.clickhouse.native import ClickhousePool\n\n    storage = get_writable_storage(StorageKey(storage_name))\n\n    (clickhouse_user, clickhouse_password,) = storage.get_cluster().get_credentials()\n\n    cluster = storage.get_cluster()\n    database = cluster.get_database()\n\n    if clickhouse_host and clickhouse_port:\n        connection = ClickhousePool(\n            clickhouse_host,\n            clickhouse_port,\n            clickhouse_user,\n            clickhouse_password,\n            database,\n        )\n    elif not cluster.is_single_node():\n        raise click.ClickException(\"Provide ClickHouse host and port for cleanup\")\n    else:\n        connection = cluster.get_query_connection(\n            ClickhouseClientSettings.CLEANUP\n        )\n\n    num_dropped = run_cleanup(connection, storage, database, dry_run=dry_run)\n    logger.info(\"Dropped %s partitions on %s\" % (num_dropped, cluster))\n", "path": "snuba/cli/cleanup.py"}]}