healthchecks-core


License

License

MIT
GroupId

GroupId

com.chatwork
ArtifactId

ArtifactId

healthchecks-core_2.12
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

healthchecks-core
healthchecks-core
Project URL

Project URL

https://github.com/chatwork/healthchecks
Project Organization

Project Organization

Chatwork Co., Ltd.
Source Code Management

Source Code Management

https://github.com/chatwork/healthchecks

Download healthchecks-core_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.chatwork/healthchecks-core_2.12/ -->
<dependency>
    <groupId>com.chatwork</groupId>
    <artifactId>healthchecks-core_2.12</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.chatwork/healthchecks-core_2.12/
implementation 'com.chatwork:healthchecks-core_2.12:1.0.0'
// https://jarcasting.com/artifacts/com.chatwork/healthchecks-core_2.12/
implementation ("com.chatwork:healthchecks-core_2.12:1.0.0")
'com.chatwork:healthchecks-core_2.12:jar:1.0.0'
<dependency org="com.chatwork" name="healthchecks-core_2.12" rev="1.0.0">
  <artifact name="healthchecks-core_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.chatwork', module='healthchecks-core_2.12', version='1.0.0')
)
libraryDependencies += "com.chatwork" % "healthchecks-core_2.12" % "1.0.0"
[com.chatwork/healthchecks-core_2.12 "1.0.0"]

Dependencies

compile (7)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.13
org.typelevel : cats-core_2.12 jar 2.1.0
org.typelevel : cats-macros_2.12 jar 2.1.0
org.typelevel : cats-kernel_2.12 jar 2.1.0
io.circe : circe-core_2.12 jar 0.13.0
io.circe : circe-generic_2.12 jar 0.13.0
io.circe : circe-parser_2.12 jar 0.13.0

provided (4)

Group / Artifact Type Version
com.typesafe.akka : akka-actor_2.12 jar 2.5.32
com.typesafe.akka : akka-stream_2.12 jar 2.5.32
com.typesafe.akka : akka-http_2.12 jar 10.2.4
de.heikoseeberger : akka-http-circe_2.12 jar 1.36.0

test (5)

Group / Artifact Type Version
com.typesafe.akka : akka-testkit_2.12 jar 2.5.32
com.typesafe.akka : akka-stream-testkit_2.12 jar 2.5.32
com.typesafe.akka : akka-http-testkit_2.12 jar 10.2.4
org.scalatest : scalatest-funspec_2.12 jar 3.2.7
org.scalatest : scalatest-matchers-core_2.12 jar 3.2.7

Project Modules

There are no modules declared in this project.

healthchecks

CircleCI License

tiny healthcheck library for akka-http with Kubernetes liveness/readiness probe support.

Installation

libraryDependencies += "com.chatwork" %% "healthchecks-core" % <version>
  
// when you want kubernetes liveness/readiness probe support.
libraryDependencies += "com.chatwork" %% "healthchecks-k8s-probes" % <version>

Getting Started

Simple healthcheck endpoint

All you need to give is just health check function returning cats ValidationNel[String, Unit].

  import akka.actor.ActorSystem
  import akka.stream.ActorMaterializer
  import akka.http.scaladsl.Http
  import akka.http.scaladsl.model.HttpRequest
  import cats.syntax.validated._
  import scala.concurrent.Future
  import scala.util.Random

  implicit val system       = ActorSystem()
  implicit val materializer = ActorMaterializer()
  implicit val ec           = system.dispatcher

  import com.github.everpeace.healthchecks._
  import com.github.everpeace.healthchecks.route._

  // defining sync/async healthchecks
  val simple = healthCheck(name = "simple") {
    if (Random.nextBoolean()) healthy else "Unlucky!".invalidNel
  }

  val simpleAsync = asyncHealthCheck("simpleAsync") {
    Future {
      if (Random.nextBoolean()) healthy else "Unlucky!".invalidNel
    }
  }

  // start web server listening "localhost:8888/health"
  val serverBinding = Http().bindAndHandle(
    handler = HealthCheckRoutes.health(simple, simpleAsync),
    interface = "localhost",
    port = 8888
  )

  val response = Http().singleRequest(HttpRequest(uri = "http://localhost:8888/health"))

  // status code is 200(OK) if healthy, 503(Service Unavailable) if unhealthy.
  // response body is empty by default for performance.
  // pass '?full=true' query parameter to see full check result as json. it would be similar to below.
  // Please see com.github.everpeace.healthchecks.HealthRoutesTest for various response patterns.
  // {
  //   "status": "healthy",
  //   "check_results": [
  //     { "name": "simple", "severity": "Fatal", "status": "healthy", "messages": [] },
  //     { "name": "simpleAsync", "severity": "Fatal", "status": "healthy", "messages": [] }
  //   ]
  // }

Kubernetes liveness/readiness probe endpoints

It supports to setup kubernetes liveness/readiness probe really easily like this. You con configure probe paths and binding setting by typesafe config (i.e. application.conf). Please refer reference.conf for details.

  import akka.actor.ActorSystem
  import akka.stream.ActorMaterializer
  import scala.concurrent.Future

  implicit val system       = ActorSystem()
  implicit val materializer = ActorMaterializer()
  implicit val ec           = system.dispatcher

  import com.github.everpeace.healthchecks._
  import com.github.everpeace.healthchecks.k8s._
  
  // by default, listening localhost:8086
  // and probe paths are
  //   GET /live
  //   GET /ready
  val probeBinding = bindAndHandleProbes(
    readinessProbe(healthCheck(name = "readiness_check")(healthy)),
    livenessProbe(asyncHealthCheck(name = "liveness_check")(Future(healthy)))
  )

Then you can set kubernetes liveness/readiness probe in the kubernetes manifest like below:

...
  livenessProbe:
    httpGet:
      path: /live
      port: 8086
    initialDelaySeconds: 3
    periodSeconds: 3
  readinessProbe:
    httpGet:
      path: /ready
      port: 8086
    initialDelaySeconds: 3
    periodSeconds: 3
...

Contribution policy

Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.

Please make sure to follow these conventions:

  • For each contribution there must be a ticket (GitHub issue) with a short descriptive name, e.g. "Respect host/port configuration setting"
  • Work should happen in a branch named "ISSUE-DESCRIPTION", e.g. "32-respect-host-and-port"
  • Before a PR can be merged, all commits must be squashed into one with its message made up from the ticket name and the ticket id, e.g. "Respect host/port configuration setting (closes #32)"

License

This code is open source software licensed under MIT License.

Please note that part of codes in the repository were originally written by timeoutdigital. Copyright credit presents on relevant sources.

com.chatwork

Chatwork

Versions

Version
1.0.0
0.5.0