Skip to content

Commit 1a7fa0e

Browse files
authored
[earthscope, staging] feat: deploy experimental hub image for usage quotas (#7892)
* feat: add quotas requirements file * feat: add chartpress config for experimental quotas image * feat: add chart values for compute quotas
1 parent b2d103b commit 1a7fa0e

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

config/clusters/earthscope/staging.values.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ basehub:
1616
# To login to earthscope staging, now use https://staging.geolab.earthscope.cloud/hub/oauth_login
1717
redirect_to: https://www.earthscope.org/data/geolab/
1818
hub:
19+
image:
20+
name: quay.io/2i2c/jupyterhub-usage-quotas
21+
tag: 0.0.1-0.dev.git.15310.hc76f02d9a
1922
config:
2023
GenericOAuthenticator:
2124
token_url: https://login-dev.earthscope.org/oauth/token
@@ -25,6 +28,41 @@ basehub:
2528
extra_authorize_params:
2629
# This isn't an actual URL, just a string. Must not have a trailing slash
2730
audience: https://api.dev.earthscope.org
31+
UsageQuotaManager:
32+
prometheus_scrape_interval: 60
33+
prometheus_url: http://support-prometheus-server.support.svc.cluster.local
34+
prometheus_usage_metrics:
35+
memory: kube_pod_container_resource_requests{resource='memory'}
36+
scope_backup_strategy:
37+
empty:
38+
resource: memory
39+
limit:
40+
value: 1000
41+
unit: GiB-hours
42+
window: 7
43+
intersection: max
44+
extraConfig:
45+
11-enforce-usage-quotas: |
46+
from jupyterhub_usage_quotas.manager import SpawnException, UsageQuotaManager
47+
48+
quota_manager = UsageQuotaManager(config=c)
49+
50+
async def quota_pre_spawn_hook(spawner):
51+
try:
52+
output = await quota_manager.enforce(spawner)
53+
launch_flag = output["allow_server_launch"]
54+
except Exception:
55+
raise SpawnException(
56+
status_code=424,
57+
log_message="Spawn failed occurred due to a failed dependency in the usage quota system. Please contact your hub admin for assistance.",
58+
)
59+
if launch_flag is False:
60+
raise SpawnException(
61+
status_code=403,
62+
log_message=f"{output['error']['message']}",
63+
html_message=f"<p>Compute {output['quota']['resource']} quota limit exceeded.</p><p style='font-size:100%'>You have used <span style='color:var(--bs-red)'>{output['quota']['used']:.2f}</span> / {output['quota']['limit']['value']:.2f} {output['quota']['limit']['unit']} in the last {output['quota']['window']} days.</p><p style='font-size:100%'>Contact your JupyterHub admin if you need additional quota.</p><i style='font-size:100%;color:var(--bs-gray)'>Last updated: {output["timestamp"]} (UTC).</i>",
64+
)
65+
c.KubeSpawner.pre_spawn_hook = quota_pre_spawn_hook
2866
singleuser:
2967
nodeSelector:
3068
2i2c/hub-name: staging

helm-charts/chartpress.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ charts:
1616
valuesPath: jupyterhub.hub.image
1717
buildArgs:
1818
REQUIREMENTS_FILE: requirements.txt
19+
usage-quotas:
20+
imageName: quay.io/2i2c/jupyterhub-usage-quotas
21+
buildArgs:
22+
REQUIREMENTS_FILE: quotas-requirements.txt
23+
contextPath: images/hub
24+
dockerfilePath: images/hub/Dockerfile
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
git+https://github.com/2i2c-org/jupyterhub-usage-quotas@985ab1ac79e3b83ec1fd5543564347856859b0d5
2+
jupyterhub-fancy-profiles==0.4.1

0 commit comments

Comments
 (0)