mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
filter health checks
This commit is contained in:
parent
60b09f646b
commit
ee806f6d44
@ -28,12 +28,27 @@ class FilteredAccessLogger(AccessLogger):
|
||||
|
||||
Attributes:
|
||||
LOG_PATH_REGEX(re.Pattern): (class attribute) regex for logs uri
|
||||
LOG_PATPROCESS_PATH_REGEXH_REGEX(re.Pattern): (class attribute) regex for process uri
|
||||
"""
|
||||
|
||||
HEALTH_PATH_REGEX = "/api/v1/info"
|
||||
LOG_PATH_REGEX = re.compile(r"^/api/v1/packages/[^/]+/logs$")
|
||||
# technically process id is uuid, but we might change it later
|
||||
PROCESS_PATH_REGEX = re.compile(r"^/api/v1/service/process/[^/]+$")
|
||||
|
||||
@staticmethod
|
||||
def is_info_get(request: BaseRequest) -> bool:
|
||||
"""
|
||||
check if the request is for health check
|
||||
|
||||
Args:
|
||||
request(BaseRequest): http reqeust descriptor
|
||||
|
||||
Returns:
|
||||
bool: True in case if request is health check and false otherwise
|
||||
"""
|
||||
return request.method == "GET" and FilteredAccessLogger.HEALTH_PATH_REGEX == request.path
|
||||
|
||||
@staticmethod
|
||||
def is_logs_post(request: BaseRequest) -> bool:
|
||||
"""
|
||||
@ -69,7 +84,8 @@ class FilteredAccessLogger(AccessLogger):
|
||||
response(StreamResponse): streaming response object
|
||||
time(float): log record timestamp
|
||||
"""
|
||||
if self.is_logs_post(request) \
|
||||
if self.is_info_get(request) \
|
||||
or self.is_logs_post(request) \
|
||||
or self.is_process_get(request):
|
||||
return
|
||||
AccessLogger.log(self, request, response, time)
|
||||
|
@ -4,6 +4,25 @@ from unittest.mock import MagicMock
|
||||
from ahriman.core.log.filtered_access_logger import FilteredAccessLogger
|
||||
|
||||
|
||||
def is_info_get() -> None:
|
||||
"""
|
||||
must correctly define health check request
|
||||
"""
|
||||
request = MagicMock()
|
||||
|
||||
request.method = "GET"
|
||||
request.path = "/api/v1/info"
|
||||
assert FilteredAccessLogger.is_info_get(request)
|
||||
|
||||
request.method = "POST"
|
||||
request.path = "/api/v1/info"
|
||||
assert not FilteredAccessLogger.is_info_get(request)
|
||||
|
||||
request.method = "GET"
|
||||
request.path = "/api/v1/infos"
|
||||
assert not FilteredAccessLogger.is_info_get(request)
|
||||
|
||||
|
||||
def test_is_logs_post() -> None:
|
||||
"""
|
||||
must correctly define if request belongs to logs posting
|
||||
|
Loading…
Reference in New Issue
Block a user