From 9f940150fcd689e19bdcc37e31e20c96775b6fba Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 8 May 2024 16:43:26 -0400 Subject: [PATCH] Closes #16010: Enable Prometheus middleware only if metrics are enabled --- netbox/netbox/settings.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 38df16551..f2b01041f 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -372,7 +372,6 @@ if not DJANGO_ADMIN_ENABLED: # Middleware MIDDLEWARE = [ "strawberry_django.middlewares.debug_toolbar.DebugToolbarMiddleware", - 'django_prometheus.middleware.PrometheusBeforeMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', @@ -386,8 +385,14 @@ MIDDLEWARE = [ 'netbox.middleware.RemoteUserMiddleware', 'netbox.middleware.CoreMiddleware', 'netbox.middleware.MaintenanceModeMiddleware', - 'django_prometheus.middleware.PrometheusAfterMiddleware', ] +if METRICS_ENABLED: + # If metrics are enabled, add the before & after Prometheus middleware + MIDDLEWARE = [ + 'django_prometheus.middleware.PrometheusBeforeMiddleware', + *MIDDLEWARE, + 'django_prometheus.middleware.PrometheusAfterMiddleware', + ] # URLs ROOT_URLCONF = 'netbox.urls'