From 80ca5eab472a320c9bc175660b75d8f01730d1dc Mon Sep 17 00:00:00 2001 From: Joel Jacob Date: Tue, 10 Dec 2024 17:47:53 +0000 Subject: [PATCH] Merge "Migrate lb query to use non batch API requests fixes: 383171958" -- Branch commit log -- commit d091fa4618845e87151df162970bb78ac23bc4f1 Author: Joel Jacob Date: 2024-12-09T18:06:51-05:00 Migrate lb query to use non batch API requests fixes: 383171958 Change-Id: I669c752ccd83999fa1b677807eb7a8b3153a2a7f GitOrigin-RevId: e4843bafe5d943953e3e469f829731ece20d562e --- gcpdiag/queries/lb.py | 61 ++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/gcpdiag/queries/lb.py b/gcpdiag/queries/lb.py index d4d30634e..7d47d032f 100644 --- a/gcpdiag/queries/lb.py +++ b/gcpdiag/queries/lb.py @@ -310,20 +310,6 @@ def health_state(self) -> str: return self._resource_data.get('healthState', 'UNHEALTHY') -def _generate_health_response_callback( - backend_heath_statuses: List[BackendHealth], group: str): - - def health_response_callback(request_id, response, exception): - del request_id, exception - - # None is returned when backend type doesn't support health check - if response is not None: - for health_status in response.get('healthStatus', []): - backend_heath_statuses.append(BackendHealth(health_status, group)) - - return health_response_callback - - @caching.cached_api_call(in_memory=True) def get_backend_service_health( project_id: str, @@ -340,34 +326,33 @@ def get_backend_service_health( backend_heath_statuses: List[BackendHealth] = [] compute = apis.get_api('compute', 'v1', project_id) - batch = compute.new_batch_http_request() - for i, backend in enumerate(backend_service.backends): + for backend in backend_service.backends: group = backend['group'] if not backend_service.region: - batch.add( - compute.backendServices().getHealth( - project=project_id, - backendService=backend_service.name, - body={'group': group}, - ), - request_id=str(i), - callback=_generate_health_response_callback(backend_heath_statuses, - group), - ) + response = compute.backendServices().getHealth( + project=project_id, + backendService=backend_service.name, + body={ + 'group': group + }, + ).execute(num_retries=config.API_RETRIES) + # None is returned when backend type doesn't support health check + if response is not None: + for health_status in response.get('healthStatus', []): + backend_heath_statuses.append(BackendHealth(health_status, group)) else: - batch.add( - compute.regionBackendServices().getHealth( - project=project_id, - region=backend_service.region, - backendService=backend_service.name, - body={'group': group}, - ), - request_id=str(i), - callback=_generate_health_response_callback(backend_heath_statuses, - group), - ) - batch.execute() + response = compute.regionBackendServices().getHealth( + project=project_id, + region=backend_service.region, + backendService=backend_service.name, + body={ + 'group': group + }, + ).execute(num_retries=config.API_RETRIES) + if response is not None: + for health_status in response.get('healthStatus', []): + backend_heath_statuses.append(BackendHealth(health_status, group)) return backend_heath_statuses