feat: implement lab3 API load balancing and failover
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import time
|
||||
import urllib.request
|
||||
|
||||
base = os.getenv('BASE_URL', 'http://localhost:8080')
|
||||
seen = set()
|
||||
for _ in range(180):
|
||||
try:
|
||||
with urllib.request.urlopen(base+'/health/ready', timeout=2) as r:
|
||||
seen.add(r.headers['X-Instance-Id'])
|
||||
if len(seen)>=2:
|
||||
print('Ready: two API instances through LB:', ', '.join(sorted(seen)))
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(.5)
|
||||
else:
|
||||
raise SystemExit('Two ready instances not observed in readiness deadline')
|
||||
Reference in New Issue
Block a user