Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
chore: Filter out logs on /healthcheck (#171)
Browse files Browse the repository at this point in the history
* Filter out logs on /healthcheck

Reduce noisy uvicorn logs when polling /healthcheck.

To test, you can run a local copy of api-tools to regenerate one of the pipeline apis, and try
calling /healthcheck on it.

For instance, in api-tools, run `make install-project-local`. Jump over to unstructured-api and run
`make generate-api` and `make run-web-app`. Make a request to localhost:8000/healthcheck and verify
that the uvicorn logs do not show it.

* version sync

---------

Co-authored-by: cragwolfe <[email protected]>
  • Loading branch information
awalker4 and cragwolfe authored May 8, 2023
1 parent b7a7eed commit f00abf5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.10.4

* Add filter on /healthcheck logs

# 0.10.3

* Add support for json and msg file types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


from fastapi import FastAPI, Request, status
import logging

from .process_file_1 import router as process_file_1_router
from .process_file_2 import router as process_file_2_router
Expand Down Expand Up @@ -44,6 +45,15 @@
app.include_router(process_text_file_4_router)


# Filter out /healthcheck noise
class HealthCheckFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
return record.getMessage().find("/healthcheck") == -1


logging.getLogger("uvicorn.access").addFilter(HealthCheckFilter())


@app.get("/healthcheck", status_code=status.HTTP_200_OK, include_in_schema=False)
def healthcheck(request: Request):
return {"healthcheck": "HEALTHCHECK STATUS: EVERYTHING OK!"}
2 changes: 1 addition & 1 deletion unstructured_api_tools/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.3" # pragma: no cover
__version__ = "0.10.4" # pragma: no cover
8 changes: 8 additions & 0 deletions unstructured_api_tools/pipelines/templates/pipeline_app.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


from fastapi import FastAPI, Request, status
import logging

{% for module in module_names -%}
from .{{ module }} import router as {{module}}_router
Expand All @@ -22,6 +23,13 @@ app = FastAPI(
app.include_router({{ module }}_router)
{% endfor %}

# Filter out /healthcheck noise
class HealthCheckFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
return record.getMessage().find("/healthcheck") == -1

logging.getLogger("uvicorn.access").addFilter(HealthCheckFilter())

@app.get("/healthcheck", status_code=status.HTTP_200_OK, include_in_schema=False)
def healthcheck(request: Request):
return {"healthcheck": "HEALTHCHECK STATUS: EVERYTHING OK!"}

0 comments on commit f00abf5

Please sign in to comment.