zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
787 stars 396 forks source link

Introduce healthcheck HttpApp that relies on ZIO Metrics Connectors #1490

Open jdegoes opened 2 years ago

jdegoes commented 2 years ago

Is your feature request related to a problem? Please describe.

All of the metrics (ZIO, ZIO HTTP, + user metrics) can be exposed via an HTTP API, but currently, doing so requires depending on the project zio-metrics-connectors, which depends on zio-http (an older version), and which launches a separate server on a separate port requiring its own configuration. This is inconvenient, as we want a single server and a healthcheck API available on this server.

Describe the solution you'd like

Flip the dependency so that zio-http relies on zio-metrics-connectors, and zio-metrics-connectors is standalone, depending only on zio-core. Using functionality inside this library, zio-http can expose a healthcheck API:

  1. A prometheus version
  2. An HTML version, for developer-mode experience
  3. A JSON version, for programmatic access

It's probable we should do this as an HttpApp (Http.publishMetrics or Http.exposeMetrics). The user can then mix the route into their other routes in order to expose a healthcheck API (e.g. myApp ++ Http.publishMetrics).

Describe alternatives you've considered

Leaving the functionality in zio-metrics-connectors.

987Nabil commented 2 years ago

May I suggest another name? I mean this is an endpoint to expose metrics right? A health check might be in someone's domain something different. Like is the db connection alive. I would call the middleware exposeMetrics or maybe publishMetrics

jdegoes commented 2 years ago

👍

arumus commented 1 year ago

going to attempt this