Skip to content

Commit

Permalink
monrun check rename new options
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Unisikhin committed Aug 9, 2024
1 parent 0d213ff commit 4678dfd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions ch_tools/chadmin/cli/object_storage_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)


Expand Down
40 changes: 20 additions & 20 deletions ch_tools/monrun_checks/ch_orphaned_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

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


@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(
Expand All @@ -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}"
Expand All @@ -63,32 +63,32 @@ 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

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
36 changes: 18 additions & 18 deletions tests/features/monrun.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -410,41 +410,41 @@ 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
"""
0;Total size: 10
"""
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
"""
1;Total size: 10
"""
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
"""
Expand All @@ -458,47 +458,47 @@ 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
"""
0;Total size: 10
"""
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
"""
1;Total size: 10
"""
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
"""
ch-monitoring orphaned-objects -w 9 -c 19
"""
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
"""

0 comments on commit 4678dfd

Please sign in to comment.