Skip to content

Commit

Permalink
additional info about RO tables (#179)
Browse files Browse the repository at this point in the history
* additional info about RO tables

* fix ruff style

* add replica_path for verbose info
  • Loading branch information
k-morozov committed May 14, 2024
1 parent 77f870b commit dc5cbc6
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions ch_tools/monrun_checks/ch_ro_replica.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,54 @@


@click.command("ro-replica")
@click.option(
"-v",
"--verbose",
is_flag=True,
help="Show details about ro tables.",
)
@click.pass_context
def ro_replica_command(ctx):
def ro_replica_command(ctx, verbose=False):
"""
Check for readonly replicated tables.
"""
query = "SELECT database, table FROM system.replicas WHERE is_readonly"
query = """
SELECT database, table, replica_path, last_queue_update_exception, zookeeper_exception
FROM system.replicas WHERE is_readonly
"""
response = clickhouse_client(ctx).query_json_data(query, compact=False)
if response:
msg_verbose = ""

if verbose:
headers = [
"database",
"table",
"replica_path",
"last_queue_update_exception",
"zookeeper_exception",
]

formatted_data = []

for item in response:
formatted_row = "\n".join(
[
f"{header}: {item[header]}"
for header in headers
if header in item
]
)
formatted_data.append(formatted_row)

msg_verbose = "\n\n".join(data for data in formatted_data)

tables_str = ", ".join(
f"{item['database']}.{item['table']}" for item in response
)
return Result(CRIT, f"Readonly replica tables: {tables_str}")

return Result(
CRIT, f"Readonly replica tables: {tables_str}", verbose=msg_verbose
)

return Result(OK)

0 comments on commit dc5cbc6

Please sign in to comment.