Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration for FastAPI #81

Merged
merged 17 commits into from
Feb 21, 2024
Merged

Add integration for FastAPI #81

merged 17 commits into from
Feb 21, 2024

Conversation

grahamalama
Copy link
Contributor

@grahamalama grahamalama commented Aug 2, 2023

Looking for some early feedback on this implementation of a Dockerflow integration with FastAPI.

Many more tests to write, but I wanted to get an early look at the general "API" of the integration (for now, documented only in how it's used in tests).

I'm also wondering if FastAPI is a library we want to actually support. It's a pretty popular library, but with all the talk at Mozilla about standardizing how we build products, it's worth considering if FastAPI is or should be one of those standard tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This middleware is based heavily on https://github.com/Kludex/asgi-logger/. What's interesting though is that while this is currently in the fastapi subpackage, as is implied in that project, we may be able to write one Asgi middleware for all ASGI servers / frameworks e.g..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like we should define some of the stuff in this module more centrally. Each of the framework integrations define their own healthcheck registration mechanisms. Also, it seems like just convention that "a healthcheck function should return a list of CheckMessage objects". That seems like something we should enforce or standardize somehow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe... I'm getting more into typed Python, so I like CheckMessage. dataclass requires Python 3.7, we're close to that being a minimum. Re-writing the code to use common functions sounds like a different PR, and probably a different version. I'd want a release of the "boring" duplicate version before a major rewrite like that.

@jwhitlock
Copy link
Member

I'm also wondering if FastAPI is a library we want to actually support. It's a pretty popular library, but with all the talk at Mozilla about standardizing how we build products, if FastAPI is or should be one of those standard tools.

I think if we can find a Mozilla employee that will use this integration, than we are justified to add it. If it won't be used by anyone, it is not worth adding.

I don't have any active FastAPI projects, so I'm not volunteering to sponsor. It has been a while since I've used FastAPI, but the code looks correct. I can probably dig in an give a full review later this week.

errors = check()
level = max([0] + [e.level for e in errors])
return CheckDetail(
status=level_to_text(level), level=level, messages={e.id: e.msg for e in errors}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit worried me - it looks like if two errors have the same level, just one will win:

messages={e.id: e.msg for e in errors}

However, the other platforms seem to work that way as well, so 🤷

Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good :)
Some design decisions seem to come from what was already made for other frameworks.

src/dockerflow/fastapi/checks.py Outdated Show resolved Hide resolved
src/dockerflow/fastapi/checks.py Outdated Show resolved Hide resolved
leplatrem and others added 2 commits February 20, 2024 17:39
* Add FastAPI documentation

* Update docs/fastapi.rst

Co-authored-by: grahamalama <graham.beckley@gmail.com>

* Mention APP_DIR for the version file

---------

Co-authored-by: grahamalama <graham.beckley@gmail.com>
Copy link
Contributor Author

@grahamalama grahamalama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't approve this because I was the original author of the PR, but r+ from me

APIRoute("/__version__", endpoint=version, methods=["GET"]),
],
)
"""This router adds the Dockerflow views."""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the top of the file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way Sphinx autodoc documents module attributes (docstring below)

tox.ini Outdated Show resolved Hide resolved
Co-authored-by: grahamalama <graham.beckley@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (6c032ec) 98.23% compared to head (8ba84ef) 97.97%.

Files Patch % Lines
src/dockerflow/fastapi/middleware.py 93.02% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #81      +/-   ##
==========================================
- Coverage   98.23%   97.97%   -0.27%     
==========================================
  Files          19       22       +3     
  Lines         624      692      +68     
  Branches       85       92       +7     
==========================================
+ Hits          613      678      +65     
- Misses          7        8       +1     
- Partials        4        6       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leplatrem leplatrem merged commit 9f6a0ec into main Feb 21, 2024
5 checks passed
@leplatrem leplatrem deleted the fastapi-integration branch February 21, 2024 10:20
@leplatrem leplatrem mentioned this pull request Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants