From dc5cbc67fba47d2f51a4553437e8704f0c7edda3 Mon Sep 17 00:00:00 2001 From: Konstantin Morozov <34001730+k-morozov@users.noreply.github.com> Date: Tue, 14 May 2024 19:16:56 +0200 Subject: [PATCH] additional info about RO tables (#179) * additional info about RO tables * fix ruff style * add replica_path for verbose info --- ch_tools/monrun_checks/ch_ro_replica.py | 43 +++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/ch_tools/monrun_checks/ch_ro_replica.py b/ch_tools/monrun_checks/ch_ro_replica.py index 1a36a45e..549d3f25 100644 --- a/ch_tools/monrun_checks/ch_ro_replica.py +++ b/ch_tools/monrun_checks/ch_ro_replica.py @@ -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)