-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Add /health endpoint (#28)
* fix(validations): move Prometheus /runtimeinfo API call under validations Signed-off-by: hayk96 <hayko5999@gmail.com> * feat(api): Add /health endpoint Signed-off-by: hayk96 <hayko5999@gmail.com> * docs: Update CHANGELOG.md Signed-off-by: hayk96 <hayko5999@gmail.com> * chore(api): Bump app version #patch Signed-off-by: hayk96 <hayko5999@gmail.com> --------- Signed-off-by: hayk96 <hayko5999@gmail.com>
- Loading branch information
Showing
7 changed files
with
95 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from .. v1.endpoints import reverse_proxy, rules, policies, web | ||
from .. v1.endpoints import reverse_proxy, rules, policies, web, health | ||
from fastapi import APIRouter | ||
|
||
api_router = APIRouter() | ||
api_router.include_router(rules.router, prefix="/api/v1") | ||
api_router.include_router(policies.router, prefix="/api/v1") | ||
api_router.include_router(web.router, prefix="") | ||
api_router.include_router(health.router, prefix="") | ||
api_router.add_route("/{path:path}", reverse_proxy._reverse_proxy, ["GET", "POST", "PUT"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from src.utils.settings import check_prom_readiness | ||
from fastapi import APIRouter, Response, status | ||
from src.utils.arguments import arg_parser | ||
|
||
router = APIRouter() | ||
rule_path = arg_parser().get("rule.path") | ||
prom_addr = arg_parser().get("prom.addr") | ||
|
||
|
||
@router.get("/health", | ||
name="Get system health", | ||
description="Returns a 200 status when the prometheus-api is able to connect to the Prometheus server", | ||
status_code=status.HTTP_200_OK, | ||
tags=["health"], | ||
responses={ | ||
200: { | ||
"description": "OK", | ||
"content": { | ||
"application/json": { | ||
"example": [ | ||
{ | ||
"status": "success", | ||
"message": "Service is up and running" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
503: { | ||
"description": "Service Unavailable", | ||
"content": { | ||
"application/json": { | ||
"example": [ | ||
{ | ||
"status": "error", | ||
"message": "Service is unavailable due to a health-check failure" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}) | ||
async def health(response: Response): | ||
global prom_addr | ||
if not check_prom_readiness(prom_addr): | ||
response.status_code = status.HTTP_503_SERVICE_UNAVAILABLE | ||
return {"status": "error", | ||
"message": "Service is unavailable due to a health-check failure"} | ||
return {"status": "success", | ||
"message": "Service is up and running"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters