Skip to content

Commit fd4c2b4

Browse files
committed
Debug: Add local make_metrics_app
1 parent f0d0d7b commit fd4c2b4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

gen3workflow/app.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from gen3workflow.routes.system import router as system_router
1818
from gen3workflow.auth import Auth
1919

20+
from prometheus_client import CollectorRegistry, make_asgi_app, multiprocess
21+
2022

2123
def get_app(httpx_client=None) -> FastAPI:
2224
logger.info("Initializing app")
@@ -73,7 +75,9 @@ def get_app(httpx_client=None) -> FastAPI:
7375
logger.debug(
7476
f"Vieweing metrics associated with the registry {list(app.metrics._registry.collect())=}"
7577
)
76-
app.mount("/metrics", app.metrics.get_asgi_app())
78+
metrics_app = make_metrics_app(config["PROMETHEUS_MULTIPROC_DIR"])
79+
app.mount("/metrics", metrics_app)
80+
# app.mount("/metrics", app.metrics.get_asgi_app())
7781

7882
@app.middleware("http")
7983
async def middleware_log_response_and_api_metric(
@@ -117,4 +121,14 @@ async def middleware_log_response_and_api_metric(
117121
return app
118122

119123

124+
def make_metrics_app(prometheus_multiproc_dir):
125+
"""
126+
Required for Prometheus multiprocess setup
127+
See: https://prometheus.github.io/client_python/multiprocess/
128+
"""
129+
registry = CollectorRegistry()
130+
multiprocess.MultiProcessCollector(registry, prometheus_multiproc_dir)
131+
return make_asgi_app(registry=registry)
132+
133+
120134
app = get_app()

0 commit comments

Comments
 (0)