Skip to content

Commit f9fdc99

Browse files
authored
Added lag_aware_tolerance parameter to LagAwareHealthcheck (#3752)
1 parent 8daa531 commit f9fdc99

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

redis/multidb/healthcheck.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def __init__(
8686
self,
8787
retry: Retry = Retry(retries=DEFAULT_HEALTH_CHECK_RETRIES, backoff=DEFAULT_HEALTH_CHECK_BACKOFF),
8888
rest_api_port: int = 9443,
89+
lag_aware_tolerance: int = 100,
8990
timeout: float = DEFAULT_TIMEOUT,
9091
auth_basic: Optional[Tuple[str, str]] = None,
9192
verify_tls: bool = True,
@@ -104,6 +105,7 @@ def __init__(
104105
Args:
105106
retry: Retry configuration for health checks
106107
rest_api_port: Port number for Redis Enterprise REST API (default: 9443)
108+
lag_aware_tolerance: Tolerance in lag between databases in MS (default: 100)
107109
timeout: Request timeout in seconds (default: DEFAULT_TIMEOUT)
108110
auth_basic: Tuple of (username, password) for basic authentication
109111
verify_tls: Whether to verify TLS certificates (default: True)
@@ -130,6 +132,7 @@ def __init__(
130132
client_key_password=client_key_password
131133
)
132134
self._rest_api_port = rest_api_port
135+
self._lag_aware_tolerance = lag_aware_tolerance
133136

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

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

169173
# Status checked in an http client, otherwise HttpError will be raised

tests/test_multidb/test_healthcheck.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from redis.backoff import ExponentialBackoff
66
from redis.multidb.database import Database
7-
from redis.multidb.healthcheck import EchoHealthCheck
87
from redis.http.http_client import HttpError
98
from redis.multidb.healthcheck import EchoHealthCheck, LagAwareHealthCheck
109
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
7473

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

9594
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
121120

122121
assert hc.check_health(db) is True
123122
assert mock_http.get.call_count == 2
124-
assert mock_http.get.call_args_list[1].args[0] == "/v1/local/bdbs/bdb-42/endpoint/availability"
123+
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"
125124

126125
def test_raises_value_error_when_no_matching_bdb(self, mock_client, mock_cb):
127126
"""

0 commit comments

Comments
 (0)