From 4678dfd83214a479e0c3c3e686ab63930ab6e5c9 Mon Sep 17 00:00:00 2001 From: Nikita Unisikhin Date: Sat, 10 Aug 2024 00:01:23 +0500 Subject: [PATCH] monrun check rename new options --- ch_tools/chadmin/cli/object_storage_group.py | 4 +- ch_tools/monrun_checks/ch_orphaned_objects.py | 40 +++++++++---------- tests/features/monrun.feature | 36 ++++++++--------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/ch_tools/chadmin/cli/object_storage_group.py b/ch_tools/chadmin/cli/object_storage_group.py index b9736f8e..205408aa 100644 --- a/ch_tools/chadmin/cli/object_storage_group.py +++ b/ch_tools/chadmin/cli/object_storage_group.py @@ -20,7 +20,7 @@ STREAM_TIMEOUT = 10 * 60 ORPHANED_OBJECTS_SIZE_FIELD = "orphaned_objects_size" -STORE_STATE_LOCAL_PATH = "/tmp/object_storage_cleanup_state.json" +STATE_LOCAL_PATH = "/tmp/object_storage_cleanup_state.json" @group("object-storage", cls=Chadmin) @@ -163,7 +163,7 @@ def _store_state_zk_save(ctx: Context, path: str, total_size: int) -> None: def _store_state_local_save(_: Context, total_size: int) -> None: - with open(STORE_STATE_LOCAL_PATH, "w", encoding="utf-8") as file: + with open(STATE_LOCAL_PATH, "w", encoding="utf-8") as file: json.dump({ORPHANED_OBJECTS_SIZE_FIELD: total_size}, file, indent=4) diff --git a/ch_tools/monrun_checks/ch_orphaned_objects.py b/ch_tools/monrun_checks/ch_orphaned_objects.py index fc4437fe..36c0f03b 100644 --- a/ch_tools/monrun_checks/ch_orphaned_objects.py +++ b/ch_tools/monrun_checks/ch_orphaned_objects.py @@ -4,7 +4,7 @@ from ch_tools.chadmin.cli.object_storage_group import ( ORPHANED_OBJECTS_SIZE_FIELD, - STORE_STATE_LOCAL_PATH, + STATE_LOCAL_PATH, ) from ch_tools.chadmin.internal.zookeeper import check_zk_node, get_zk_node from ch_tools.common.result import CRIT, OK, WARNING, Result @@ -12,14 +12,14 @@ @click.command("orphaned-objects") @click.option( - "--store-state-local", - "store_state_local", + "--state-local", + "state_local", is_flag=True, help="Get total size of orphaned objects from local file.", ) @click.option( - "--store-state-zk-path", - "store_state_zk_path", + "--state-zk-path", + "state_zk_path", help="Zookeeper node path from which the total size of orphaned objects will be taken.", ) @click.option( @@ -41,18 +41,18 @@ @click.pass_context def orphaned_objects_command( ctx: click.Context, - store_state_local: bool, - store_state_zk_path: str, + state_local: bool, + state_zk_path: str, crit: int, warn: int, ) -> Result: - _check_mutually_exclusive(store_state_local, store_state_zk_path) + _check_mutually_exclusive(state_local, state_zk_path) total_size = 0 - if store_state_zk_path: - total_size = _zk_get_total_size(ctx, store_state_zk_path) + if state_zk_path: + total_size = _zk_get_total_size(ctx, state_zk_path) - if store_state_local: + if state_local: total_size = _local_get_total_size() msg = f"Total size: {total_size}" @@ -63,21 +63,21 @@ def orphaned_objects_command( return Result(OK, msg) -def _check_mutually_exclusive(store_state_local, store_state_zk_path): - if not store_state_local and not store_state_zk_path: +def _check_mutually_exclusive(state_local, state_zk_path): + if not state_local and not state_zk_path: raise click.UsageError( - "One of these options must be provided: --store_state_local, --store_state_zk_path" + "One of these options must be provided: --state-local, --state-zk-path" ) - if store_state_local and store_state_zk_path: + if state_local and state_zk_path: raise click.UsageError( - "Options --store-state-local and --store-state-zk-path are mutually exclusive." + "Options --state-local and --state-zk-path are mutually exclusive." ) def _local_get_total_size() -> int: try: - with open(STORE_STATE_LOCAL_PATH, mode="r", encoding="utf-8") as file: + with open(STATE_LOCAL_PATH, mode="r", encoding="utf-8") as file: total_size = json.load(file).get(ORPHANED_OBJECTS_SIZE_FIELD) except FileNotFoundError: total_size = 0 @@ -85,10 +85,10 @@ def _local_get_total_size() -> int: return total_size -def _zk_get_total_size(ctx: click.Context, store_state_zk_path: str) -> int: +def _zk_get_total_size(ctx: click.Context, state_zk_path: str) -> int: total_size = 0 - if check_zk_node(ctx, store_state_zk_path): - total_size = json.loads(get_zk_node(ctx, store_state_zk_path)).get( + if check_zk_node(ctx, state_zk_path): + total_size = json.loads(get_zk_node(ctx, state_zk_path)).get( ORPHANED_OBJECTS_SIZE_FIELD ) return total_size diff --git a/tests/features/monrun.feature b/tests/features/monrun.feature index ed2a2efe..86ca00cf 100644 --- a/tests/features/monrun.feature +++ b/tests/features/monrun.feature @@ -389,14 +389,14 @@ Feature: ch-monitoring tool 2;KazooTimeoutError('Connection time-out') """ - Scenario: Check clickhouse orphaned objects with store-state-zk-path option + Scenario: Check clickhouse orphaned objects with state-zk-path option When we execute command on clickhouse01 """ - chadmin object-storage clean --dry-run --to-time 0h --on-cluster --keep-paths --store-state-zk-path /tmp/shard_1 + chadmin object-storage clean --dry-run --to-time 0h --on-cluster --keep-paths --state-zk-path /tmp/shard_1 """ When we execute command on clickhouse01 """ - ch-monitoring orphaned-objects --store-state-zk-path /tmp/shard_1 + ch-monitoring orphaned-objects --state-zk-path /tmp/shard_1 """ Then we get response """ @@ -410,11 +410,11 @@ Feature: ch-monitoring tool """ When we execute command on clickhouse01 """ - chadmin object-storage clean --dry-run --to-time 0h --on-cluster --keep-paths --store-state-zk-path /tmp/shard_1 + chadmin object-storage clean --dry-run --to-time 0h --on-cluster --keep-paths --state-zk-path /tmp/shard_1 """ When we execute command on clickhouse01 """ - ch-monitoring orphaned-objects --store-state-zk-path /tmp/shard_1 + ch-monitoring orphaned-objects --state-zk-path /tmp/shard_1 """ Then we get response contains """ @@ -422,7 +422,7 @@ Feature: ch-monitoring tool """ When we execute command on clickhouse01 """ - ch-monitoring orphaned-objects -w 9 -c 19 --store-state-zk-path /tmp/shard_1 + ch-monitoring orphaned-objects -w 9 -c 19 --state-zk-path /tmp/shard_1 """ Then we get response contains """ @@ -430,21 +430,21 @@ Feature: ch-monitoring tool """ When we execute command on clickhouse01 """ - ch-monitoring orphaned-objects -w 4 -c 9 --store-state-zk-path /tmp/shard_1 + ch-monitoring orphaned-objects -w 4 -c 9 --state-zk-path /tmp/shard_1 """ Then we get response contains """ 2;Total size: 10 """ - Scenario: Check clickhouse orphaned objects with store-state-local option + Scenario: Check clickhouse orphaned objects with state-local option When we execute command on clickhouse01 """ - chadmin object-storage clean --dry-run --to-time 0h --on-cluster --keep-paths --store-state-local + chadmin object-storage clean --dry-run --to-time 0h --on-cluster --keep-paths --state-local """ When we execute command on clickhouse01 """ - ch-monitoring orphaned-objects --store-state-local + ch-monitoring orphaned-objects --state-local """ Then we get response """ @@ -458,11 +458,11 @@ Feature: ch-monitoring tool """ When we execute command on clickhouse01 """ - chadmin object-storage clean --dry-run --to-time 0h --on-cluster --keep-paths --store-state-local + chadmin object-storage clean --dry-run --to-time 0h --on-cluster --keep-paths --state-local """ When we execute command on clickhouse01 """ - ch-monitoring orphaned-objects --store-state-local + ch-monitoring orphaned-objects --state-local """ Then we get response contains """ @@ -470,7 +470,7 @@ Feature: ch-monitoring tool """ When we execute command on clickhouse01 """ - ch-monitoring orphaned-objects -w 9 -c 19 --store-state-local + ch-monitoring orphaned-objects -w 9 -c 19 --state-local """ Then we get response contains """ @@ -478,21 +478,21 @@ Feature: ch-monitoring tool """ When we execute command on clickhouse01 """ - ch-monitoring orphaned-objects -w 4 -c 9 --store-state-local + ch-monitoring orphaned-objects -w 4 -c 9 --state-local """ Then we get response contains """ 2;Total size: 10 """ - Scenario: Check clickhouse orphaned objects --store-state-local and --store-state-zk-path are mutually exclusive + Scenario: Check clickhouse orphaned objects --state-local and --state-zk-path are mutually exclusive When we execute command on clickhouse01 """ - ch-monitoring orphaned-objects -w 9 -c 19 --store-state-local --store-state-zk-path /tmp/shard_1 + ch-monitoring orphaned-objects -w 9 -c 19 --state-local --state-zk-path /tmp/shard_1 """ Then we get response contains """ - 1;Unknown error: Options --store-state-local and --store-state-zk-path are mutually exclusive. + 1;Unknown error: Options --state-local and --state-zk-path are mutually exclusive. """ When we execute command on clickhouse01 """ @@ -500,5 +500,5 @@ Feature: ch-monitoring tool """ Then we get response contains """ - 1;Unknown error: One of these options must be provided: --store_state_local, --store_state_zk_path + 1;Unknown error: One of these options must be provided: --state-local, --state-zk-path """