Skip to content

Commit 3299cd6

Browse files
committed
Added lag tollerance parameter
1 parent 8551965 commit 3299cd6

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

redis/multidb/healthcheck.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(
7373
self,
7474
retry=Retry(retries=DEFAULT_HEALTH_CHECK_RETRIES, backoff=DEFAULT_HEALTH_CHECK_BACKOFF),
7575
rest_api_port: int = 9443,
76+
availability_lag_tolerance: int = 100,
7677
timeout: float = DEFAULT_TIMEOUT,
7778
auth_basic: Optional[Tuple[str, str]] = None,
7879
verify_tls: bool = True,
@@ -85,6 +86,24 @@ def __init__(
8586
client_key_file: Optional[str] = None,
8687
client_key_password: Optional[str] = None,
8788
):
89+
"""
90+
Initialize LagAwareHealthCheck with the specified parameters.
91+
92+
Args:
93+
retry: Retry configuration for health checks
94+
rest_api_port: Port number for Redis Enterprise REST API (default: 9443)
95+
availability_lag_tolerance: Maximum acceptable lag in milliseconds (default: 100)
96+
timeout: Request timeout in seconds (default: DEFAULT_TIMEOUT)
97+
auth_basic: Tuple of (username, password) for basic authentication
98+
verify_tls: Whether to verify TLS certificates (default: True)
99+
ca_file: Path to CA certificate file for TLS verification
100+
ca_path: Path to CA certificates directory for TLS verification
101+
ca_data: CA certificate data as string or bytes
102+
client_cert_file: Path to client certificate file for mutual TLS
103+
client_key_file: Path to client private key file for mutual TLS
104+
client_key_password: Password for encrypted client private key
105+
"""
106+
88107
super().__init__(
89108
retry=retry,
90109
)
@@ -101,6 +120,7 @@ def __init__(
101120
client_key_password=client_key_password
102121
)
103122
self._rest_api_port = rest_api_port
123+
self._availability_lag_tolerance = availability_lag_tolerance
104124

105125
def check_health(self, database) -> bool:
106126
client = database.client
@@ -126,7 +146,7 @@ def check_health(self, database) -> bool:
126146
logger.warning("LagAwareHealthCheck failed: Couldn't find a matching bdb")
127147
raise ValueError("Could not find a matching bdb")
128148

129-
url = f"/v1/bdbs/{matching_bdb['uid']}/availability"
149+
url = f"/v1/bdbs/{matching_bdb['uid']}/availability?availability_lag_tolerance_ms={self._availability_lag_tolerance}"
130150
self._http_client.get(url, expect_json=False)
131151

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

tests/test_scenario/test_active_active.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def trigger_network_failure_action(fault_injector_client, event: threading.Event
1717
endpoint_config = get_endpoint_config('re-active-active')
1818
action_request = ActionRequest(
1919
action_type=ActionType.NETWORK_FAILURE,
20-
parameters={"bdb_id": endpoint_config['bdb_id'], "delay": 2, "cluster_index": 0}
20+
parameters={"bdb_id": endpoint_config['bdb_id'], "delay": 3, "cluster_index": 0}
2121
)
2222

2323
result = fault_injector_client.trigger_action(action_request)
@@ -37,7 +37,7 @@ class TestActiveActiveStandalone:
3737

3838
def teardown_method(self, method):
3939
# Timeout so the cluster could recover from network failure.
40-
sleep(4)
40+
sleep(5)
4141

4242
@pytest.mark.parametrize(
4343
"r_multi_db",
@@ -63,12 +63,12 @@ def test_multi_db_client_failover_to_another_db(self, r_multi_db, fault_injector
6363
# Execute commands before network failure
6464
while not event.is_set():
6565
assert r_multi_db.get('key') == 'value'
66-
sleep(0.1)
66+
sleep(0.5)
6767

6868
# Execute commands after network failure
6969
for _ in range(3):
7070
assert r_multi_db.get('key') == 'value'
71-
sleep(0.1)
71+
sleep(0.5)
7272

7373
assert listener.is_changed_flag == True
7474

@@ -104,12 +104,12 @@ def test_multi_db_client_uses_lag_aware_health_check(self, r_multi_db, fault_inj
104104
# Execute commands before network failure
105105
while not event.is_set():
106106
assert r_multi_db.get('key') == 'value'
107-
sleep(0.1)
107+
sleep(0.5)
108108

109109
# Execute commands after network failure
110110
for _ in range(3):
111111
assert r_multi_db.get('key') == 'value'
112-
sleep(0.1)
112+
sleep(0.5)
113113

114114
assert listener.is_changed_flag == True
115115

@@ -152,7 +152,7 @@ def test_context_manager_pipeline_failover_to_another_db(self, r_multi_db, fault
152152
pipe.get('{hash}key2')
153153
pipe.get('{hash}key3')
154154
assert pipe.execute() == [True, True, True, 'value1', 'value2', 'value3']
155-
sleep(0.1)
155+
sleep(0.5)
156156

157157
# Execute pipeline after network failure
158158
for _ in range(3):
@@ -164,7 +164,7 @@ def test_context_manager_pipeline_failover_to_another_db(self, r_multi_db, fault
164164
pipe.get('{hash}key2')
165165
pipe.get('{hash}key3')
166166
assert pipe.execute() == [True, True, True, 'value1', 'value2', 'value3']
167-
sleep(0.1)
167+
sleep(0.5)
168168

169169
assert listener.is_changed_flag == True
170170

@@ -206,7 +206,7 @@ def test_chaining_pipeline_failover_to_another_db(self, r_multi_db, fault_inject
206206
pipe.get('{hash}key2')
207207
pipe.get('{hash}key3')
208208
assert pipe.execute() == [True, True, True, 'value1', 'value2', 'value3']
209-
sleep(0.1)
209+
sleep(0.5)
210210

211211
# Execute pipeline after network failure
212212
for _ in range(3):
@@ -217,7 +217,7 @@ def test_chaining_pipeline_failover_to_another_db(self, r_multi_db, fault_inject
217217
pipe.get('{hash}key2')
218218
pipe.get('{hash}key3')
219219
assert pipe.execute() == [True, True, True, 'value1', 'value2', 'value3']
220-
sleep(0.1)
220+
sleep(0.5)
221221

222222
assert listener.is_changed_flag == True
223223

@@ -253,12 +253,12 @@ def callback(pipe: Pipeline):
253253
# Execute pipeline before network failure
254254
while not event.is_set():
255255
r_multi_db.transaction(callback)
256-
sleep(0.1)
256+
sleep(0.5)
257257

258258
# Execute pipeline after network failure
259259
for _ in range(3):
260260
r_multi_db.transaction(callback)
261-
sleep(0.1)
261+
sleep(0.5)
262262

263263
assert listener.is_changed_flag == True
264264

@@ -295,12 +295,12 @@ def handler(message):
295295
# Execute pipeline before network failure
296296
while not event.is_set():
297297
r_multi_db.publish('test-channel', data)
298-
sleep(0.1)
298+
sleep(0.5)
299299

300300
# Execute pipeline after network failure
301301
for _ in range(3):
302302
r_multi_db.publish('test-channel', data)
303-
sleep(0.1)
303+
sleep(0.5)
304304

305305
pubsub_thread.stop()
306306

@@ -340,12 +340,12 @@ def handler(message):
340340
# Execute pipeline before network failure
341341
while not event.is_set():
342342
r_multi_db.spublish('test-channel', data)
343-
sleep(0.1)
343+
sleep(0.5)
344344

345345
# Execute pipeline after network failure
346346
for _ in range(3):
347347
r_multi_db.spublish('test-channel', data)
348-
sleep(0.1)
348+
sleep(0.5)
349349

350350
pubsub_thread.stop()
351351

0 commit comments

Comments
 (0)