From dfb8fd39ca53b3ee6650dc182d54aa865422e1dd Mon Sep 17 00:00:00 2001 From: Tal Date: Mon, 30 Dec 2024 12:06:22 +0200 Subject: [PATCH] feat(api): no auth for processing metrics (#2932) --- keep/api/routes/metrics.py | 39 +++++++++++++++++++++++++------------- pyproject.toml | 2 +- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/keep/api/routes/metrics.py b/keep/api/routes/metrics.py index 71444c2e5..4eff4d52c 100644 --- a/keep/api/routes/metrics.py +++ b/keep/api/routes/metrics.py @@ -24,19 +24,32 @@ router = APIRouter() CONTENT_TYPE_LATEST = "text/plain; version=0.0.4; charset=utf-8" - - -@router.get("/processing", include_in_schema=False) -async def get_processing_metrics( - request: Request, - authenticated_entity: AuthenticatedEntity = Depends( - IdentityManagerFactory.get_auth_verifier(["read:metrics"]) - ), -): - registry = CollectorRegistry() - multiprocess.MultiProcessCollector(registry) - metrics = generate_latest(registry) - return Response(content=metrics, media_type=CONTENT_TYPE_LATEST) +NO_AUTH_METRICS = config("KEEP_NO_AUTH_METRICS", default=False, cast=bool) + +if NO_AUTH_METRICS: + + @router.get("/processing", include_in_schema=False) + async def get_processing_metrics( + request: Request, + ): + registry = CollectorRegistry() + multiprocess.MultiProcessCollector(registry) + metrics = generate_latest(registry) + return Response(content=metrics, media_type=CONTENT_TYPE_LATEST) + +else: + + @router.get("/processing", include_in_schema=False) + async def get_processing_metrics( + request: Request, + authenticated_entity: AuthenticatedEntity = Depends( + IdentityManagerFactory.get_auth_verifier(["read:metrics"]) + ), + ): + registry = CollectorRegistry() + multiprocess.MultiProcessCollector(registry) + metrics = generate_latest(registry) + return Response(content=metrics, media_type=CONTENT_TYPE_LATEST) @router.get("") diff --git a/pyproject.toml b/pyproject.toml index 387b6bb84..e80169dfb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "keep" -version = "0.33.2" +version = "0.33.3" description = "Alerting. for developers, by developers." authors = ["Keep Alerting LTD"] packages = [{include = "keep"}]