Skip to content

Commit 0ea39ae

Browse files
authored
fix: use notebooks config fallback for culling (#1108)
1 parent d5ae093 commit 0ea39ae

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

components/renku_data_services/notebooks/core_sessions.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -527,24 +527,36 @@ def get_culling(
527527
user: AuthenticatedAPIUser | AnonymousAPIUser, resource_pool: ResourcePool, nb_config: NotebooksConfig
528528
) -> Culling:
529529
"""Create the culling specification for an AmaltheaSession."""
530-
if user.is_anonymous:
531-
# NOTE: Anonymous sessions should not be hibernated at all, but there is no such option in Amalthea
532-
# So in this case we set a very low hibernation threshold so the session is deleted quickly after
533-
# it is hibernated.
534-
hibernation_threshold: timedelta | None = timedelta(seconds=1)
535-
else:
536-
hibernation_threshold = (
537-
timedelta(seconds=resource_pool.hibernation_threshold)
538-
if resource_pool.hibernation_threshold is not None
539-
else None
540-
)
530+
hibernation_threshold: timedelta | None = None
531+
# NOTE: A value of zero on the resource_pool hibernation threshold
532+
# is interpreted by Amalthea as "never automatically delete after hibernation"
533+
match (user.is_anonymous, resource_pool.hibernation_threshold):
534+
case True, _:
535+
# NOTE: Anonymous sessions should not be hibernated at all, but there is no such option in Amalthea
536+
# So in this case we set a very low hibernation threshold so the session is deleted quickly after
537+
# it is hibernated.
538+
hibernation_threshold = timedelta(seconds=1)
539+
case False, int():
540+
hibernation_threshold = timedelta(seconds=resource_pool.hibernation_threshold)
541+
case False, None:
542+
hibernation_threshold = timedelta(seconds=nb_config.sessions.culling.registered.hibernated_seconds)
543+
544+
idle_duration: timedelta | None = None
545+
# NOTE: A value of zero on the resource_pool idle threshold
546+
# is interpreted by Amalthea as "never automatically hibernate for idleness"
547+
match (user.is_anonymous, resource_pool.idle_threshold):
548+
case True, None:
549+
idle_duration = timedelta(seconds=nb_config.sessions.culling.anonymous.idle_seconds)
550+
case _, int():
551+
idle_duration = timedelta(seconds=resource_pool.idle_threshold)
552+
case False, None:
553+
idle_duration = timedelta(seconds=nb_config.sessions.culling.registered.idle_seconds)
554+
541555
return Culling(
542556
maxAge=timedelta(seconds=nb_config.sessions.culling.registered.max_age_seconds),
543557
maxFailedDuration=timedelta(seconds=nb_config.sessions.culling.registered.failed_seconds),
544558
maxHibernatedDuration=hibernation_threshold,
545-
maxIdleDuration=timedelta(seconds=resource_pool.idle_threshold)
546-
if resource_pool.idle_threshold is not None
547-
else None,
559+
maxIdleDuration=idle_duration,
548560
maxStartingDuration=timedelta(seconds=nb_config.sessions.culling.registered.pending_seconds),
549561
)
550562

components/renku_data_services/notebooks/crs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,12 @@ def __deserialize_duration(cls, val: Any, handler: Any) -> Any:
184184

185185

186186
class Culling(_ASCulling, CullingDurationParsingMixin):
187-
"""Amalthea session culling configuration."""
187+
"""Amalthea session culling configuration.
188+
189+
A value of zero for any of the values indicates that the automatic action will never happen.
190+
I.e. a value of zero for `maxIdleDuration` indicates that the session will never be hibernated
191+
no matter how long it is idle.
192+
"""
188193

189194
pass
190195

0 commit comments

Comments
 (0)