Skip to content

Commit

Permalink
Add health check endpoint (#9)
Browse files Browse the repository at this point in the history
* Add health check endpoint

* remove self-hosted runners due to capacity issues
  • Loading branch information
cbartz authored May 29, 2024
1 parent a3c3869 commit 281eebe
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
juju-channel: 3.1/stable
channel: 1.28-strict/stable
trivy-image-config: "trivy.yaml"
self-hosted-runner: true
self-hosted-runner-label: "edge"
self-hosted-runner: false
rockcraft-channel: latest/edge
charmcraft-channel: latest/edge
3 changes: 1 addition & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ jobs:
uses: canonical/operator-workflows/.github/workflows/test.yaml@main
secrets: inherit
with:
self-hosted-runner: true
self-hosted-runner-label: "edge"
self-hosted-runner: false
18 changes: 18 additions & 0 deletions src-docs/app.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ Receive a GitHub webhook and append the payload to a file.



**Returns:**
A tuple containing an empty string and 200 status code on success or a failure message and 403 status code.


---

<a href="../webhook_router/app.py#L44"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `health_check`

```python
health_check() → tuple[str, int]
```

Health check endpoint.



**Returns:**
A tuple containing an empty string and 200 status code.

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,14 @@ def test_webhook_validation(

assert response.status_code == expected_status
assert response.text == expected_reason


def test_health_check(client: FlaskClient):
"""
arrange: A test client.
act: Request the health check endpoint.
assert: 200 status code is returned.
"""
response = client.get("/health")
assert response.status_code == 200
assert response.data == b""
13 changes: 12 additions & 1 deletion webhook_router/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def handle_github_webhook() -> tuple[str, int]:
"""Receive a GitHub webhook and append the payload to a file.
Returns:
A tuple containing an empty string and 200 status code.
A tuple containing an empty string and 200 status code on success or
a failure message and 403 status code.
"""
if secret := app.config.get("WEBHOOK_SECRET"):
if not (signature := request.headers.get(WEBHOOK_SIGNATURE_HEADER)):
Expand All @@ -40,6 +41,16 @@ def handle_github_webhook() -> tuple[str, int]:
return "", 200


@app.route("/health", methods=["GET"])
def health_check() -> tuple[str, int]:
"""Health check endpoint.
Returns:
A tuple containing an empty string and 200 status code.
"""
return "", 200


# Exclude from coverage since unit tests should not run as __main__
if __name__ == "__main__": # pragma: no cover
# Start development server
Expand Down

0 comments on commit 281eebe

Please sign in to comment.