Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion redis/multidb/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(
self,
retry: Retry = Retry(retries=DEFAULT_HEALTH_CHECK_RETRIES, backoff=DEFAULT_HEALTH_CHECK_BACKOFF),
rest_api_port: int = 9443,
lag_aware_tolerance: int = 100,
timeout: float = DEFAULT_TIMEOUT,
auth_basic: Optional[Tuple[str, str]] = None,
verify_tls: bool = True,
Expand All @@ -104,6 +105,7 @@ def __init__(
Args:
retry: Retry configuration for health checks
rest_api_port: Port number for Redis Enterprise REST API (default: 9443)
lag_aware_tolerance: Tolerance in lag between databases in MS (default: 100)
timeout: Request timeout in seconds (default: DEFAULT_TIMEOUT)
auth_basic: Tuple of (username, password) for basic authentication
verify_tls: Whether to verify TLS certificates (default: True)
Expand All @@ -130,6 +132,7 @@ def __init__(
client_key_password=client_key_password
)
self._rest_api_port = rest_api_port
self._lag_aware_tolerance = lag_aware_tolerance

def check_health(self, database) -> bool:
if database.health_check_url is None:
Expand Down Expand Up @@ -163,7 +166,8 @@ def check_health(self, database) -> bool:
logger.warning("LagAwareHealthCheck failed: Couldn't find a matching bdb")
raise ValueError("Could not find a matching bdb")

url = f"/v1/local/bdbs/{matching_bdb['uid']}/endpoint/availability"
url = (f"/v1/local/bdbs/{matching_bdb['uid']}/endpoint/availability"
f"?extend_check=lag&availability_lag_tolerance_ms={self._lag_aware_tolerance}")
self._http_client.get(url, expect_json=False)

# Status checked in an http client, otherwise HttpError will be raised
Expand Down
7 changes: 3 additions & 4 deletions tests/test_multidb/test_healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from redis.backoff import ExponentialBackoff
from redis.multidb.database import Database
from redis.multidb.healthcheck import EchoHealthCheck
from redis.http.http_client import HttpError
from redis.multidb.healthcheck import EchoHealthCheck, LagAwareHealthCheck
from redis.multidb.circuit import State as CBState
Expand Down Expand Up @@ -74,7 +73,7 @@ def test_database_is_healthy_when_bdb_matches_by_dns_name(self, mock_client, moc

hc = LagAwareHealthCheck(
retry=Retry(backoff=ExponentialBackoff(cap=1.0), retries=3),
rest_api_port=1234,
rest_api_port=1234, lag_aware_tolerance=150
)
# Inject our mocked http client
hc._http_client = mock_http
Expand All @@ -89,7 +88,7 @@ def test_database_is_healthy_when_bdb_matches_by_dns_name(self, mock_client, moc
first_call = mock_http.get.call_args_list[0]
second_call = mock_http.get.call_args_list[1]
assert first_call.args[0] == "/v1/bdbs"
assert second_call.args[0] == "/v1/local/bdbs/bdb-1/endpoint/availability"
assert second_call.args[0] == "/v1/local/bdbs/bdb-1/endpoint/availability?extend_check=lag&availability_lag_tolerance_ms=150"
assert second_call.kwargs.get("expect_json") is False

def test_database_is_healthy_when_bdb_matches_by_addr(self, mock_client, mock_cb):
Expand Down Expand Up @@ -121,7 +120,7 @@ def test_database_is_healthy_when_bdb_matches_by_addr(self, mock_client, mock_cb

assert hc.check_health(db) is True
assert mock_http.get.call_count == 2
assert mock_http.get.call_args_list[1].args[0] == "/v1/local/bdbs/bdb-42/endpoint/availability"
assert mock_http.get.call_args_list[1].args[0] == "/v1/local/bdbs/bdb-42/endpoint/availability?extend_check=lag&availability_lag_tolerance_ms=100"

def test_raises_value_error_when_no_matching_bdb(self, mock_client, mock_cb):
"""
Expand Down