Skip to content

Commit 5e6c97e

Browse files
authored
Simple healthcheck (WebOfTrust#144)
Useful for Kubernetes readinessProbe and livenessProbe
1 parent 0621cdb commit 5e6c97e

File tree

3 files changed

+209
-182
lines changed

3 files changed

+209
-182
lines changed

src/keria/app/agenting.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from keri.vc import protocoling
3030

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

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

871872

873+
class HealthEnd:
874+
"""Health resource for determining that a container is live"""
875+
876+
def on_get(self, req, resp):
877+
resp.status = falcon.HTTP_OK
878+
resp.media = {"message": f"Health is okay. Time is {nowIso8601()}"}
879+
880+
872881
class KeyStateCollectionEnd:
873882

874883
@staticmethod

tests/app/test_httping.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
66
Testing the Mark II Agent
77
"""
8+
import json
9+
10+
from keria.app.agenting import HealthEnd
811
from keria.core.httping import parseRangeHeader
912

1013

@@ -66,8 +69,17 @@ def test_parse_range_header():
6669
assert end == 9
6770

6871

72+
def test_healthcheck_end(helpers):
73+
with helpers.openKeria() as (agency, agent, app, client):
74+
healthEnd = HealthEnd()
75+
app.add_route("/health", healthEnd)
6976

77+
res = client.simulate_get(path="/health")
78+
health = json.loads(res.content)
7079

80+
assert res.status_code == 200
81+
assert 'message' in health
82+
assert health['message'].startswith('Health is okay')
7183

7284

7385

0 commit comments

Comments
 (0)