Skip to content

Commit 78c764b

Browse files
authored
feat: filtering out health checks from logs (epam#99)
1 parent ea82a88 commit 78c764b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

aidial_sdk/application.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import logging.config
2+
import re
3+
from logging import Filter, LogRecord
24
from typing import Dict, Optional, Type, TypeVar
35

46
from fastapi import FastAPI, HTTPException, Request
@@ -27,6 +29,17 @@
2729
RequestType = TypeVar("RequestType", bound=FromRequestMixin)
2830

2931

32+
class PathFilter(Filter):
33+
path: str
34+
35+
def __init__(self, path: str) -> None:
36+
super().__init__(name="")
37+
self.path = path
38+
39+
def filter(self, record: LogRecord):
40+
return not re.search(f"(\\s+){self.path}(\\s+)", record.getMessage())
41+
42+
3043
class DIALApp(FastAPI):
3144
chat_completion_impls: Dict[str, ChatCompletion] = {}
3245

@@ -52,7 +65,9 @@ def __init__(
5265
HeaderPropagator(self, dial_url).enable()
5366

5467
if add_healthcheck:
55-
self.add_api_route("/health", DIALApp._healthcheck, methods=["GET"])
68+
path = "/health"
69+
self.add_api_route(path, DIALApp._healthcheck, methods=["GET"])
70+
logging.getLogger("uvicorn.access").addFilter(PathFilter(path))
5671

5772
self.add_api_route(
5873
"/openai/deployments/{deployment_id}/chat/completions",

0 commit comments

Comments
 (0)