Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

feat(health): Custom health checks #237

Merged
merged 8 commits into from
Jan 13, 2023
Merged

Conversation

gazorby
Copy link
Collaborator

@gazorby gazorby commented Jan 12, 2023

Closes #174

It also brings AbstractHealthCheck to register custom health checks:

class MyHealthCheck(AbstractHealthCheck):
    name: str = "my_health_check"

    def ready(self) -> bool:
        return True

...

from starlite_saqlalchemy.sqlalchemy_plugin import SQLAlchemyHealthCheck
from starlite_saqlalchemy.health import AppHealthCheck

config = init_plugin.PluginConfig(health_checks=[AppHealthCheck, SQLAlchemyHealthCheck, MyHealthCheck])
Starlite(route_handlers=[], on_app_init=[init_plugin.ConfigureApp(config=config)])

Calling the health endpoint now returns all health checks statuses:

{
  "app": {
    "BUILD_NUMBER": "",
    "CHECK_DB_READY": true,
    "CHECK_REDIS_READY": true,
    "DEBUG": false,
    "ENVIRONMENT": "prod",
    "NAME": "my-starlite-saqlalchemy-app"
  },
  "health": {
    "app": true,
    "db": true,
    "my_health_check": true
  }
}

This would would also help getting #213 merged since we could easily disable SQLAlchemyHealthCheck if sqlalchemy is not installed.

@sonarcloud
Copy link

sonarcloud bot commented Jan 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

98.6% 98.6% Coverage
0.0% 0.0% Duplication

@peterschutt peterschutt merged commit bfe64f4 into main Jan 13, 2023
@peterschutt peterschutt deleted the feat/dbless-health-check branch January 13, 2023 11:39
@peterschutt
Copy link
Member

very nice!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: running app without database requires custom health endpoint
2 participants