From 67b774faca4c8767aa86b38fecc06b400e4f19b5 Mon Sep 17 00:00:00 2001 From: GeorgianaElena Date: Tue, 2 Oct 2018 11:58:33 +0300 Subject: [PATCH] fix missing import and resolve class attributes --- jupyterhub/handlers/base.py | 8 ++++---- jupyterhub/metrics.py | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index ee6d1eba..a7282da8 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -32,7 +32,7 @@ from ..utils import maybe_future, url_path_join from ..metrics import ( SERVER_SPAWN_DURATION_SECONDS, ServerSpawnStatus, PROXY_ADD_DURATION_SECONDS, ProxyAddStatus, - SERVER_POLL_DURATION_SECONDS, + SERVER_POLL_DURATION_SECONDS, ServerPollStatus, RUNNING_SERVERS ) @@ -825,7 +825,7 @@ class BaseHandler(RequestHandler): poll_start_time = time.perf_counter() status = await spawner.poll() SERVER_POLL_DURATION_SECONDS.labels( - status=ServerPollStatus.status_to_string(status) + status=ServerPollStatus.from_status(status) ).observe(time.perf_counter() - poll_start_time) if status is not None: @@ -859,7 +859,7 @@ class BaseHandler(RequestHandler): poll_start_time = time.perf_counter() status = await spawner.poll() SERVER_POLL_DURATION_SECONDS.labels( - status=ServerPollStatus.status_to_string(status) + status=ServerPollStatus.from_status(status) ).observe(time.perf_counter() - poll_start_time) @@ -1170,7 +1170,7 @@ class UserSpawnHandler(BaseHandler): poll_start_time = time.perf_counter() status = await spawner.poll() SERVER_POLL_DURATION_SECONDS.labels( - status=ServerPollStatus.status_to_string(status) + status=ServerPollStatus.from_status(status) ).observe(time.perf_counter() - poll_start_time) else: status = 0 diff --git a/jupyterhub/metrics.py b/jupyterhub/metrics.py index d4742376..0d62d31c 100644 --- a/jupyterhub/metrics.py +++ b/jupyterhub/metrics.py @@ -93,10 +93,12 @@ class ServerPollStatus(Enum): running = 'running' stopped = 'stopped' - def status_to_string(status): + @classmethod + def from_status(cls, status): + """Return enum string for a given poll status""" if status is None: - return running - return stopped + return cls.running + return cls.stopped def __str__(self): return self.value