Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unique version check in monrun ch_replication_lag and ch_system_queues #93

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions ch_tools/monrun_checks/ch_replication_lag.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import logging
from typing import Any, Dict

import click
from tabulate import tabulate

from ch_tools.common.result import Result
from ch_tools.monrun_checks.clickhouse_client import ClickhouseClient
from ch_tools.monrun_checks.clickhouse_info import ClickhouseInfo


@click.command("replication-lag")
Expand Down Expand Up @@ -160,16 +158,6 @@ def replication_lag_command(ctx, xcrit, crit, warn, mwarn, mcrit, verbose):
lag, lag_with_errors, max_execution, max_merges
)

try:
replica_versions_mismatch = ClickhouseInfo.get_versions_count(ctx) > 1
if replica_versions_mismatch:
msg += ", ClickHouse versions on replicas mismatch"
return Result(code=1, message=msg, verbose=msg_verbose)
except Exception:
logging.warning("Unable to get version info from replicas", exc_info=True)
msg += ", one or more replicas is unavailable"
return Result(code=1, message=msg, verbose=msg_verbose)

if (
lag_with_errors < crit
and max_execution < xcrit
Expand Down
17 changes: 2 additions & 15 deletions ch_tools/monrun_checks/ch_system_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from ch_tools.common.result import Result
from ch_tools.monrun_checks.clickhouse_client import ClickhouseClient
from ch_tools.monrun_checks.clickhouse_info import ClickhouseInfo


@click.command("system-queues")
Expand All @@ -27,7 +26,7 @@ def system_queues_command(ctx, crit, warn, conf):
config = {"triggers": {"default": {"crit": crit, "warn": warn}}}

metrics = get_metrics(ctx)
return check_metrics(ctx, metrics, config)
return check_metrics(metrics, config)


def get_config(conf):
Expand All @@ -49,7 +48,7 @@ def get_metrics(ctx):
return ClickhouseClient(ctx).execute(query, compact=False)


def check_metrics(ctx, metrics, config):
def check_metrics(metrics, config):
"""
Check that metrics are within acceptable levels.
"""
Expand All @@ -60,7 +59,6 @@ def check_metrics(ctx, metrics, config):
status = 0
message = "OK"
triggers = []
versions_count = 0

for row in metrics:
db_table = "{}.{}".format(row["database"], row["table"])
Expand All @@ -73,17 +71,10 @@ def check_metrics(ctx, metrics, config):
thresholds = table_thresholds.get(key, default_thresholds[key])

report = ""
table_status = 0
for prior in "crit", "warn":
threshold = thresholds[prior]
if value > threshold:
table_status = status_map[prior]
if table_status > 1:
if versions_count == 0:
versions_count = ClickhouseInfo.get_versions_count(ctx)
if versions_count > 1:
table_status = 1
prior = "crit->warn"
report += "{}: {} {} > {} ({});".format(
db_table, key, value, threshold, prior
)
Expand All @@ -94,9 +85,5 @@ def check_metrics(ctx, metrics, config):
triggers.sort(reverse=True, key=lambda x: x[0])
status = triggers[0][0]
message = " ".join(x[1] for x in triggers)
if versions_count == 0:
versions_count = ClickhouseInfo.get_versions_count(ctx)
if versions_count > 1:
message += " ClickHouse versions on replicas mismatch"

return Result(code=status, message=message)
19 changes: 1 addition & 18 deletions ch_tools/monrun_checks/clickhouse_info.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
import functools

from ch_tools.monrun_checks.clickhouse_client import ClickhouseClient, ClickhousePort
from ch_tools.monrun_checks.clickhouse_client import ClickhouseClient


class ClickhouseInfo:
@classmethod
@functools.lru_cache(maxsize=1)
def get_versions_count(cls, ctx):
"""
Count different clickhouse versions in cluster.
"""
ch_client = ClickhouseClient(ctx)
# I believe that all hosts in cluster have the same port set, so check current for security port
remote_command = (
"remoteSecure"
if ch_client.check_port(ClickhousePort.TCP_SECURE)
else "remote"
)
replicas = ",".join(cls.get_replicas(ctx))
query = f"""SELECT uniq(version()) FROM {remote_command}('{replicas}', system.one)"""
return int(ch_client.execute(query)[0][0])

@classmethod
@functools.lru_cache(maxsize=1)
def get_replicas(cls, ctx):
Expand Down