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

Make idle culler settings configurable from the nebari-config.yaml #1689

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions nebari/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,23 @@ class JupyterHub(Base):
overrides: typing.Optional[typing.Dict]


# ================= JupyterLab ==================


class IdleCuller(Base):
terminal_cull_inactive_timeout: typing.Optional[int]
terminal_cull_interval: typing.Optional[int]
kernel_cull_idle_timeout: typing.Optional[int]
kernel_cull_interval: typing.Optional[int]
kernel_cull_connected: typing.Optional[bool]
kernel_cull_busy: typing.Optional[int]
server_shutdown_no_activity_timeout: typing.Optional[int]


class JupyterLab(Base):
idle_culler: typing.Optional[IdleCuller]


# ================== Profiles ==================


Expand Down Expand Up @@ -585,6 +602,7 @@ class Main(Base):
clearml: typing.Optional[ClearML]
tf_extensions: typing.Optional[typing.List[NebariExtension]]
jupyterhub: typing.Optional[JupyterHub]
jupyterlab: typing.Optional[JupyterLab]
prevent_deploy: bool = (
False # Optional, but will be given default value if not present
)
Expand Down
2 changes: 2 additions & 0 deletions nebari/stages/input_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ def stage_07_kubernetes_services(stage_outputs, config):
.get("hub", {})
.get("extraEnv", [])
),
# jupyterlab
"idle-culler-settings": config.get("jupyterlab", {}).get("idle_culler", {}),
# dask-gateway
"dask-worker-image": _split_docker_image_name(
config["default_images"]["dask_worker"]
Expand Down
3 changes: 3 additions & 0 deletions nebari/template/stages/07-kubernetes-services/jupyterhub.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,7 @@ module "jupyterhub" {

jupyterhub-logout-redirect-url = var.jupyterhub-logout-redirect-url
jupyterhub-hub-extraEnv = var.jupyterhub-hub-extraEnv

idle-culler-settings = local.idle-culler-settings

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
locals {
jupyter-notebook-config-py-template = templatefile("${path.module}/files/jupyter/jupyter_notebook_config.py.tpl", {
terminal_cull_inactive_timeout = var.idle-culler-settings.terminal_cull_inactive_timeout
terminal_cull_interval = var.idle-culler-settings.terminal_cull_interval
kernel_cull_idle_timeout = var.idle-culler-settings.kernel_cull_idle_timeout
kernel_cull_interval = var.idle-culler-settings.kernel_cull_interval
kernel_cull_connected = var.idle-culler-settings.kernel_cull_connected ? "True" : "False" # for Python compatible boolean values
kernel_cull_busy = var.idle-culler-settings.kernel_cull_busy ? "True" : "False" # for Python compatible boolean values
server_shutdown_no_activity_timeout = var.idle-culler-settings.server_shutdown_no_activity_timeout
}
)
}


resource "local_file" "jupyter_notebook_config_py" {
content = local.jupyter-notebook-config-py-template
filename = "${path.module}/files/jupyter/jupyter_notebook_config.py"
}


resource "kubernetes_config_map" "etc-ipython" {
metadata {
name = "etc-ipython"
Expand All @@ -12,14 +32,17 @@ resource "kubernetes_config_map" "etc-ipython" {


resource "kubernetes_config_map" "etc-jupyter" {
depends_on = [
local_file.jupyter_notebook_config_py
]

metadata {
name = "etc-jupyter"
namespace = var.namespace
}

data = {
for filename in fileset("${path.module}/files/jupyter", "*") :
filename => file("${path.module}/files/jupyter/${filename}")
"jupyter_notebook_config.py" : local_file.jupyter_notebook_config_py.content
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@

# Timeout (in seconds) in which a terminal has been inactive and ready to
# be culled.
c.TerminalManager.cull_inactive_timeout = 30 * 60
c.TerminalManager.cull_inactive_timeout = ${terminal_cull_inactive_timeout} * 60

# The interval (in seconds) on which to check for terminals exceeding the
# inactive timeout value.
c.TerminalManager.cull_interval = 5 * 60
c.TerminalManager.cull_interval = ${terminal_cull_interval} * 60

# cull_idle_timeout: timeout (in seconds) after which an idle kernel is
# considered ready to be culled
c.MappingKernelManager.cull_idle_timeout = 30 * 60
c.MappingKernelManager.cull_idle_timeout = ${kernel_cull_idle_timeout} * 60

# cull_interval: the interval (in seconds) on which to check for idle
# kernels exceeding the cull timeout value
c.MappingKernelManager.cull_interval = 5 * 60
c.MappingKernelManager.cull_interval = ${kernel_cull_interval} * 60

# cull_connected: whether to consider culling kernels which have one
# or more connections
c.MappingKernelManager.cull_connected = True
c.MappingKernelManager.cull_connected = ${kernel_cull_connected}

# cull_busy: whether to consider culling kernels which are currently
# busy running some code
c.MappingKernelManager.cull_busy = False
c.MappingKernelManager.cull_busy = ${kernel_cull_busy}

# Shut down the server after N seconds with no kernels or terminals
# running and no activity.
c.NotebookApp.shutdown_no_activity_timeout = 30 * 60
c.NotebookApp.shutdown_no_activity_timeout = ${server_shutdown_no_activity_timeout} * 60

###############################################################################
# JupyterHub idle culler total timeout corresponds (approximately) to:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,16 @@ variable "default-conda-store-namespace" {
description = "Default conda-store namespace"
type = string
}

variable "idle-culler-settings" {
description = "Idle culler timeout settings (in minutes)"
type = object({
kernel_cull_busy = bool
kernel_cull_connected = bool
kernel_cull_idle_timeout = number
kernel_cull_interval = number
server_shutdown_no_activity_timeout = number
terminal_cull_inactive_timeout = number
terminal_cull_interval = number
})
}
20 changes: 20 additions & 0 deletions nebari/template/stages/07-kubernetes-services/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,23 @@ variable "conda-store-service-token-scopes" {
}
}
}


variable "idle-culler-settings" {
description = "Idle culler timeout settings (in minutes)"
type = any
}

# allows us to merge variables set in the nebari-config.yaml with the default values below
locals {
default-idle-culler-settings = {
kernel_cull_busy = false
kernel_cull_connected = true
kernel_cull_idle_timeout = 15
kernel_cull_interval = 5
server_shutdown_no_activity_timeout = 15
terminal_cull_inactive_timeout = 15
terminal_cull_interval = 5
}
idle-culler-settings = merge(local.default-idle-culler-settings, var.idle-culler-settings)
}