From 720323f5402666f824c03dd590d221a6b9aa8689 Mon Sep 17 00:00:00 2001 From: mrmissx Date: Sun, 30 Jun 2024 23:17:15 +0700 Subject: [PATCH] fix: remove prometheus client access logs --- anjani/internal_plugins/canonical.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/anjani/internal_plugins/canonical.py b/anjani/internal_plugins/canonical.py index 76d8c98d7..9f69cb779 100644 --- a/anjani/internal_plugins/canonical.py +++ b/anjani/internal_plugins/canonical.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import asyncio +import logging from base64 import b64encode from typing import Any, ClassVar, MutableMapping @@ -47,6 +48,25 @@ from anjani.core.metrics import MessageStat +class EndpointFilter(logging.Filter): + def __init__( + self, + path: str, + *args: Any, + **kwargs: Any, + ): + super().__init__(*args, **kwargs) + self._path = path + + def filter(self, record: logging.LogRecord) -> bool: + return record.getMessage().find(self._path) == -1 + + +# metrics endpoint filter +logging.getLogger("uvicorn.access").addFilter(EndpointFilter("/metrics")) +logging.getLogger("uvicorn.access").addFilter(EndpointFilter("GET / ")) + + class Canonical(plugin.Plugin): """Helper Plugin This plugin is only available for @dAnjani_bot @@ -73,7 +93,8 @@ async def on_load(self) -> None: self._api = WebServer( title="Anjani API Docs", description="API Documentation for Anjani Services" ) - self._api.app.mount("/metrics", make_asgi_app()) + prom_client = make_asgi_app() + self._api.app.mount("/metrics", prom_client, "metrics") async def on_start(self, _: int) -> None: self.log.debug("Starting watch streams")