diff --git a/redis/multidb/healthcheck.py b/redis/multidb/healthcheck.py index 63ba415334..9818d06e28 100644 --- a/redis/multidb/healthcheck.py +++ b/redis/multidb/healthcheck.py @@ -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, @@ -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) @@ -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: @@ -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 diff --git a/tests/test_multidb/test_healthcheck.py b/tests/test_multidb/test_healthcheck.py index bc71fdb57d..18bfe5f23b 100644 --- a/tests/test_multidb/test_healthcheck.py +++ b/tests/test_multidb/test_healthcheck.py @@ -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 @@ -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 @@ -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): @@ -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): """