Skip to content

Commit

Permalink
Feat: Add health check endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Hall <[email protected]>
  • Loading branch information
j-hall-mwam committed Nov 28, 2023
1 parent 2b77279 commit a1d38d4
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,33 @@ class Endpoints(
) {
private val metricsEndpoint: PublicEndpoint[Unit, Unit, String, Any] = endpoint.in("metrics").get.out(stringBody)

// Health check endpoints. As of now, just return 200 no preparation is done
// after the HTTP server starts.
private val livenessEndpoint: PublicEndpoint[Unit, Nothing, Unit, Any] =
infallibleEndpoint.in("health").in("live").get
private val readinessEndpoint: PublicEndpoint[Unit, Nothing, Unit, Any] =
infallibleEndpoint.in("health").in("ready").get
private val startupProbeEndpoint: PublicEndpoint[Unit, Nothing, Unit, Any] =
infallibleEndpoint.in("health").in("startup").get

val endpoints: List[ZServerEndpoint[Any, Any]] = {
val api = deploymentServerEndpoints.endpoints
val docs = docsEndpoints(api)
val metrics = List(metricsEndpoint.zServerLogic[Any](_ => getMetrics))
api ++ docs ++ metrics
val health =
List(livenessEndpoint, readinessEndpoint, startupProbeEndpoint)
.map(
_.zServerLogic[Any](_ => ZIO.succeed(()))
)
api ++ docs ++ metrics ++ health
}

private def docsEndpoints(apiEndpoints: List[ZServerEndpoint[Any, Any]]): List[ZServerEndpoint[Any, Any]] = SwaggerInterpreter()
.fromServerEndpoints[Task](apiEndpoints, "kafkakewl-deploy", "1.0.0")

private def getMetrics: ZIO[Any, Unit, String] =
prometheusPublisher.get // TODO this adds the timestamp as well which isn't desirable due to prometheus's staleness handling

}

object Endpoints {
Expand Down

0 comments on commit a1d38d4

Please sign in to comment.