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 7, 2023
1 parent f31296a commit 97b6465
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 182 deletions.
16 changes: 14 additions & 2 deletions 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 All @@ -74,7 +75,7 @@ def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=No
'signify-resource', 'signify-timestamp']))
if os.getenv("KERI_AGENT_CORS", "false").lower() in ("true", "1"):
app.add_middleware(middleware=httping.HandleCORS())
app.add_middleware(authing.SignatureValidationComponent(agency=agency, authn=authn, allowed=["/agent"]))
app.add_middleware(authing.SignatureValidationComponent(agency=agency, authn=authn, allowed=["/agent", "/health"]))
app.req_options.media_handlers.update(media.Handlers())
app.resp_options.media_handlers.update(media.Handlers())

Expand Down Expand Up @@ -114,6 +115,7 @@ def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=No

specEnd = AgentSpecResource(app=app, title='KERIA Interactive Web Interface API')
specEnd.addRoutes(happ)
happ.add_route("/health", HealthEnd())
happ.add_route("/spec.yaml", specEnd)

print("The Agency is loaded and waiting for requests...")
Expand Down Expand Up @@ -774,6 +776,8 @@ def loadEnds(app):
queryEnd = QueryCollectionEnd()
app.add_route("/queries", queryEnd)

app.add_route("/health", HealthEnd())


class BootEnd:
""" Resource class for creating datastore in cloud ahab """
Expand Down Expand Up @@ -869,6 +873,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
Loading

0 comments on commit 97b6465

Please sign in to comment.