Complete the code to register a service instance with the discovery server.
discovery_client.register_service('[1]', '10.0.0.1', 8080)
The first argument should be the service name to identify the service in the discovery system.
Complete the code to discover the address of a service instance.
address = discovery_client.get_service_address('[1]')
You need to provide the service name to get the address of one of its instances.
Fix the error in the service registration code to include health check.
discovery_client.register_service('payment-service', '10.0.0.5', 9090, health_check='[1]')
The health check URL must be a full HTTP URL so the discovery server can call it to check service health.
Fill both blanks to create a dictionary of service instances filtered by status.
healthy_services = {id: info for id, info in services.items() if info['[1]'] == '[2]'}We filter services where the status key equals healthy to get only healthy instances.
Fill all three blanks to implement a simple client-side load balancer picking a random healthy instance.
import random instances = discovery_client.get_service_instances('[1]') healthy = [i for i in instances if i['[2]'] == '[3]'] selected = random.choice(healthy)
We get instances of 'order-service', filter by 'status' equal to 'healthy', then pick one randomly.