Skip to content

Commit

Permalink
Simple healthcheck
Browse files Browse the repository at this point in the history
Useful for Kubernetes readinessProbe and livenessProbe
  • Loading branch information
kentbull committed Dec 19, 2023
1 parent 0621cdb commit 47abfb4
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 182 deletions.
11 changes: 10 additions & 1 deletion src/keria/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from keri.vc import protocoling

from keria.end import ending
from keri.help import helping, ogler
from keri.help import helping, ogler, nowIso8601
from keri.peer import exchanging
from keri.vdr import verifying
from keri.vdr.credentialing import Regery, sendArtifacts
Expand Down Expand Up @@ -64,6 +64,7 @@ def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=No
bootServerDoer = http.ServerDoer(server=bootServer)
bootEnd = BootEnd(agency)
bootApp.add_route("/boot", bootEnd)
bootApp.add_route("/health", HealthEnd())

# Create Authenticater for verifying signatures on all requests
authn = Authenticater(agency=agency)
Expand Down Expand Up @@ -869,6 +870,14 @@ def on_post(self, req, rep):
rep.data = json.dumps(asdict(agent.agentHab.kever.state())).encode("utf-8")


class HealthEnd:
"""Health resource for determining that a container is live"""

def on_get(self, req, resp):
resp.status = falcon.HTTP_OK
resp.media = {"message": f"Health is okay. Time is {nowIso8601()}"}


class KeyStateCollectionEnd:

@staticmethod
Expand Down
12 changes: 12 additions & 0 deletions tests/app/test_httping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
Testing the Mark II Agent
"""
import json

from keria.app.agenting import HealthEnd
from keria.core.httping import parseRangeHeader


Expand Down Expand Up @@ -66,8 +69,17 @@ def test_parse_range_header():
assert end == 9


def test_healthcheck_end(helpers):
with helpers.openKeria() as (agency, agent, app, client):
healthEnd = HealthEnd()
app.add_route("/health", healthEnd)

res = client.simulate_get(path="/health")
health = json.loads(res.content)

assert res.status_code == 200
assert 'message' in health
assert health['message'].startswith('Health is okay')



Expand Down
Loading

0 comments on commit 47abfb4

Please sign in to comment.