Only log hub / singleuser version mismatch once

If your jupyterhub and jupyterhub-singleuser instances
are running at different minor or greater versions a
warning gets logged per active server which can be a lot
when you have hundreds of active servers.

This adds a flag to that version mismatch logging logic
such that the warning is only logged once per restart
of the hub server.

Closes issue #2970
This commit is contained in:
Matt Riedemann
2020-03-04 11:40:23 -05:00
parent b4391d0f79
commit 08eee9309e
2 changed files with 42 additions and 7 deletions

View File

@@ -18,6 +18,15 @@ version_info = (
__version__ = ".".join(map(str, version_info[:3])) + ".".join(version_info[3:])
# Singleton flag to only log the major/minor mismatch warning once.
_version_mismatch_warning_logged = False
def reset_globals():
"""Used to reset globals between test cases."""
global _version_mismatch_warning_logged
_version_mismatch_warning_logged = False
def _check_version(hub_version, singleuser_version, log):
"""Compare Hub and single-user server versions"""
@@ -42,19 +51,26 @@ def _check_version(hub_version, singleuser_version, log):
hub_major_minor = V(hub_version).version[:2]
singleuser_major_minor = V(singleuser_version).version[:2]
extra = ""
do_log = True
if singleuser_major_minor == hub_major_minor:
# patch-level mismatch or lower, log difference at debug-level
# because this should be fine
log_method = log.debug
else:
# log warning-level for more significant mismatch, such as 0.8 vs 0.9, etc.
log_method = log.warning
extra = " This could cause failure to authenticate and result in redirect loops!"
log_method(
"jupyterhub version %s != jupyterhub-singleuser version %s." + extra,
hub_version,
singleuser_version,
)
global _version_mismatch_warning_logged
if _version_mismatch_warning_logged:
do_log = False # We already logged this warning so don't log it again.
else:
log_method = log.warning
extra = " This could cause failure to authenticate and result in redirect loops!"
_version_mismatch_warning_logged = True
if do_log:
log_method(
"jupyterhub version %s != jupyterhub-singleuser version %s." + extra,
hub_version,
singleuser_version,
)
else:
log.debug(
"jupyterhub and jupyterhub-singleuser both on version %s" % hub_version