From 34db3229151390b5caf7896b47ec55ec5033ef5b Mon Sep 17 00:00:00 2001 From: Matyas Selmeci Date: Tue, 5 Mar 2024 15:31:50 -0600 Subject: [PATCH] Handle prometheus-client missing in webapp, too --- src/app.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app.py b/src/app.py index e9d393f81..288c14f2d 100755 --- a/src/app.py +++ b/src/app.py @@ -5,8 +5,6 @@ import flask import flask.logging from flask import Flask, Response, make_response, request, render_template, redirect, url_for, session -from werkzeug.middleware.dispatcher import DispatcherMiddleware -from prometheus_client import make_wsgi_app from io import StringIO import logging import os @@ -1081,10 +1079,16 @@ def _get_authorized(): return default_authorized -# Enable prometheus integration with the topology webapp -app.wsgi_app = DispatcherMiddleware(app.wsgi_app, { - '/metrics': make_wsgi_app() -}) +try: + from werkzeug.middleware.dispatcher import DispatcherMiddleware + from prometheus_client import make_wsgi_app + # Enable prometheus integration with the topology webapp + app.wsgi_app = DispatcherMiddleware(app.wsgi_app, { + '/metrics': make_wsgi_app() + }) +except ImportError: + print("*** /metrics endpoint unavailable: prometheus-client missing", + file=sys.stderr) if __name__ == '__main__':