def _build_envoy_location_dict_for_backends( envoy_host: str, registration: str, tasks: Sequence[MarathonTask], location: str, should_return_individual_backends: bool, ) -> MutableMapping[str, Any]: backends = envoy_tools.get_backends( registration, envoy_host=envoy_host, envoy_admin_port=settings.system_paasta_config.get_envoy_admin_port(), ) sorted_envoy_backends = sorted( [backend[0] for backend in backends], key=lambda backend: backend["eds_health_status"], ) casper_proxied_backends = { (backend["address"], backend["port_value"]) for backend, is_casper_proxied_backend in backends if is_casper_proxied_backend } matched_envoy_backends_and_tasks = envoy_tools.match_backends_and_tasks( sorted_envoy_backends, tasks, ) return envoy_tools.build_envoy_location_dict( location, matched_envoy_backends_and_tasks, should_return_individual_backends, casper_proxied_backends, )
def _build_envoy_location_dict( envoy_host: str, envoy_admin_port: int, envoy_admin_endpoint_format: str, registration: str, pods: Iterable[V1Pod], location: str, should_return_individual_backends: bool, ) -> MutableMapping[str, Any]: backends = envoy_tools.get_backends( registration, envoy_host=envoy_host, envoy_admin_port=envoy_admin_port, envoy_admin_endpoint_format=envoy_admin_endpoint_format, ) sorted_envoy_backends = sorted( [ backend[0] for _, service_backends in backends.items() for backend in service_backends ], key=lambda backend: backend["eds_health_status"], ) casper_proxied_backends = { (backend["address"], backend["port_value"]) for _, service_backends in backends.items() for backend, is_casper_proxied_backend in service_backends if is_casper_proxied_backend } matched_envoy_backends_and_pods = envoy_tools.match_backends_and_pods( sorted_envoy_backends, pods, ) return envoy_tools.build_envoy_location_dict( location, matched_envoy_backends_and_pods, should_return_individual_backends, casper_proxied_backends, )