Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serve] Expose replica and controller urls on load balancer #3351

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Michaelvll
Copy link
Collaborator

@Michaelvll Michaelvll commented Mar 21, 2024

We now expose replica URLs from the load balancer for better metrics support.

curl http://lb_endpoint/-/urls

{
  'controller': 'http://endpoint:30001',
  'replicas': ['http://ip1:8080', 'http://ip2:8080']
}

Future TODO:

  • Add prometheus example

Tested (run the relevant ones):

  • Code formatting: bash format.sh
  • Any manual or new tests for this PR (please specify below)
    • sky serve up -n test examples/serve/http_server/task.yaml
    • curl $(sky serve status --endpoint test)/-/urls
  • All smoke tests: pytest tests/test_smoke.py
  • Relevant individual smoke tests: pytest tests/test_smoke.py::test_fill_in_the_name
  • Backward compatibility tests: bash tests/backward_comaptibility_tests.sh

Copy link
Collaborator

@concretevitamin concretevitamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, some comments.

async def _get_urls(self, request: fastapi.Request):
del request # Unused

ready_replica_urls = self._load_balancing_policy.ready_replicas
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should cache this in this SkyServeLoadBalancer class whenever we've finished a sync. Seems appropriate.

Alternatively, we should make abstract class LoadBalancingPolicy expose a get_ready_replicas() and use it here? Subclasses may want to have R/W locks to protect this field.

@@ -91,7 +91,21 @@ async def _redirect_handler(self, request: fastapi.Request):
logger.info(f'Redirecting request to {path}')
return fastapi.responses.RedirectResponse(url=path)

async def _get_urls(self, request: fastapi.Request):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: how about _get_ready_replicas?

nit: return type

ready_replica_urls = self._load_balancing_policy.ready_replicas
for i, ready_replica_url in enumerate(ready_replica_urls):
if not ready_replica_url.startswith('http'):
ready_replica_url = 'http://' + ready_replica_url
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to prepend this? E.g., Caddy / Prometheus's target lists do not require this.

ready_replica_url = 'http://' + ready_replica_url
ready_replica_urls[i] = ready_replica_url
return fastapi.responses.JSONResponse(content={
'controller': self._controller_url,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see the reason for this naming now. Shall we separate them out?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants