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

Kill singleuser test servers to reduce k3s resource usage #1784

Merged
merged 3 commits into from
Oct 21, 2023

Conversation

manics
Copy link
Member

@manics manics commented Oct 20, 2023

Closes #1754

We build and launch several servers, but we don't shut them down.

async def test_build(app, needs_build, needs_launch, always_build, slug, pytestconfig):
"""
Test build a repo that is very quick and easy to build.
"""
# can't use mark.github_api since only some tests here use GitHub
if slug.startswith("gh/") and "not github_api" in pytestconfig.getoption(
"markexpr"
):
pytest.skip("Skipping GitHub API test")
build_url = f"{app.url}/build/{slug}"
r = await async_requests.get(build_url, stream=True)
r.raise_for_status()
events = []
launch_events = 0
async for line in async_requests.iter_lines(r):
line = line.decode("utf8", "replace")
if line.startswith("data:"):
event = json.loads(line.split(":", 1)[1])
events.append(event)
assert "message" in event
sys.stdout.write(f"{event.get('phase', '')}: {event['message']}")
# this is the signal that everything is ready, pod is launched
# and server is up inside the pod. Break out of the loop now
# because BinderHub keeps the connection open for many seconds
# after to avoid "reconnects" from slow clients
if event.get("phase") == "ready":
r.close()
break
if event.get("phase") == "launching" and not event["message"].startswith(
("Launching server...", "Launch attempt ")
):
# skip standard launching events of builder
# we are interested in launching events from spawner
launch_events += 1
assert launch_events > 0
final = events[-1]
assert "phase" in final
assert final["phase"] == "ready"
assert "url" in final
assert "token" in final
print(final["url"])
r = await async_requests.get(url_concat(final["url"], {"token": final["token"]}))
r.raise_for_status()
assert r.url.startswith(final["url"])

@manics manics changed the title Try culling servers quickly Try culling servers quickly to reduce k3s resouce usage Oct 20, 2023
@manics manics added the ci label Oct 20, 2023
@manics manics changed the title Try culling servers quickly to reduce k3s resouce usage Kill singleuser servers to reduce k3s resource usage Oct 20, 2023
@manics manics marked this pull request as ready for review October 20, 2023 23:01
Copy link
Member

@consideRatio consideRatio left a comment

Choose a reason for hiding this comment

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

Wieeeee thanks for resolving this @manics!!!!!!!!!

@consideRatio consideRatio changed the title Kill singleuser servers to reduce k3s resource usage Kill singleuser test servers to reduce k3s resource usage Oct 21, 2023
@consideRatio consideRatio merged commit 61fc931 into jupyterhub:main Oct 21, 2023
consideRatio pushed a commit to jupyterhub/helm-chart that referenced this pull request Oct 21, 2023
@manics manics deleted the cull-quickly branch October 21, 2023 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failures in main branch
2 participants