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

Centralize check registration / running logic #85

Merged
merged 23 commits into from Dec 15, 2023

Conversation

grahamalama
Copy link
Contributor

@grahamalama grahamalama commented Aug 10, 2023

This PR adds to the dockerflow.checks package to provide the ability to register checks, run registered checks (both synchronously and asynchronously), and return the results of the checks in a standardized manner.

Since Django already has the concept of a check registry, we just run the checks there (but with our check runner). For other frameworks, we use the new registry in dockerflow.checks.registry.

Still todo is add tests for the check running functions (to make assertions about the shape of the data they return) and update documentation. But I'm open to review in this PR's current state.

@codecov-commenter
Copy link

codecov-commenter commented Aug 10, 2023

Codecov Report

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

Comparison is base (a7cad34) 97.84% compared to head (880630f) 98.23%.

Files Patch % Lines
src/dockerflow/checks/registry.py 96.29% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #85      +/-   ##
==========================================
+ Coverage   97.84%   98.23%   +0.39%     
==========================================
  Files          18       19       +1     
  Lines         602      624      +22     
  Branches       88       85       -3     
==========================================
+ Hits          589      613      +24     
+ Misses          9        7       -2     
  Partials        4        4              

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

@grahamalama grahamalama marked this pull request as ready for review August 15, 2023 23:12
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.

👌 Top!

src/dockerflow/checks/registry.py Outdated Show resolved Hide resolved
src/dockerflow/checks/registry.py Outdated Show resolved Hide resolved
Adds a given check callback with the provided object to the list
of checks. Useful for built-ins but also advanced custom checks.
"""
logger.debug("Adding extension check %s" % check.__name__)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that this comes from the Django implementation, but I don't really understand the vocabulary here: why is it an extension check?

Is it specific to Django built-in checks or are we going to use this in other integrations? Maybe it should remain under dockerflow.django

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are great questions. I had ones that were similar. The init_check / "extension check" vocabulary existed before this PR -- it was a pattern for Flask and Sanic. I don't actually see any traces of it in Django 🤔.

It does seem like it could be reworked. I'll give it a try in this PR, but if things get too crazy, maybe it deserves its own.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops you're right, misread the diff at the moment of writing the comment :)
Don't hesitate to open a follow-up if you think that's too much for this PR

src/dockerflow/sanic/checks.py Outdated Show resolved Hide resolved
def init_check(check, obj):
"""
Adds a given check callback with the provided object to the list
of checks. Useful for built-ins but also advanced custom checks.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why init check?
Could we add types and/or docstrings for the input parameters for better clarity? Or provide an example on how to use this init_check()?

Adds a given check callback with the provided object to the list
of checks. Useful for built-ins but also advanced custom checks.
"""
logger.debug("Adding extension check %s" % check.__name__)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are great questions. I had ones that were similar. The init_check / "extension check" vocabulary existed before this PR -- it was a pattern for Flask and Sanic. I don't actually see any traces of it in Django 🤔.

It does seem like it could be reworked. I'll give it a try in this PR, but if things get too crazy, maybe it deserves its own.

src/dockerflow/sanic/checks.py Outdated Show resolved Hide resolved
src/dockerflow/flask/app.py Show resolved Hide resolved
@leplatrem
Copy link
Contributor

@grahamalama shall we resume this work?

@leplatrem
Copy link
Contributor

@grahamalama r?

@grahamalama
Copy link
Contributor Author

Nice @leplatrem, thanks for taking this over and finishing it 🙌🏻

But oh no, I can't actually approve this PR because I was an author on some of the commits 😱.

You could pull another reviewer in, or you can consider this my approval and bypass branch protections.

@leplatrem leplatrem merged commit 886ac45 into main Dec 15, 2023
5 checks passed
@leplatrem leplatrem deleted the centralized-check-registry branch December 15, 2023 08:57
leplatrem added a commit that referenced this pull request Feb 14, 2024
leplatrem added a commit that referenced this pull request Feb 21, 2024
* Add tox config for FastAPI 100

* Add dockerflow router to package root

* Add request summary middleware

* Add version endpoint and tests

* Add initial heartbeat route, check mechanism, and tests

* Refactor package structure, names of things

- Define "router" in package init, register view functions defined in views
  module
- Add test for check with custom name
- use better name for check operations

* Leverage centralized checks (#85)

* Do not test on Python 3.7

* Add 'taskName' to excluded fields

* Test with python 3.12

* Improve test coverage of FastAPI

* Blackify

* FastAPI integration docs (#95)

* 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>

* Update tox.ini

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

---------

Co-authored-by: Mathieu Leplatre <mathieu@mozilla.com>
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

3 participants