scalafinagletwitter-finagle

Take control over /health endpoint in finagle


I'm trying to override health endpoint. I need to make it return something else then 'OK'. As described in docs, I should use Lifecycle.Warmup trait. Neither

HttpMuxer.addHandler(Route("/health", new ReplyHandler("not OK\n"))) 

nor overriding method doesn't helped yet.

This code below, doesn't help either.

HttpMuxer.addHandler(
      Route(
        pattern = "/health",
        handler = new ReplyHandler("not OK\n"),
        index = Some(RouteIndex(
          alias = "Health",
          group = group))))

What should I do to change this message?

UPD: One more approach which should work but it doesn't

premain {
    addAdminRoute(
      AdminHttpServer
        .Route("/health1",
          handler = service,
          "Service Health",
          Some("Misc"),
          false, Method.Get)
    )
  }
  val service = new Service[Request, Response] {
    def apply(request: Request) = {
      val response = Response(request.version, Status.Ok)
      response.contentString = "test" + "\n"
      com.twitter.util.Future.value(response)
    }
  }

I debug, I see it's added to Muxer, I see it appears in logs as well. Have no idea why it doesn't work

Logs


Solution

  • Sounds a bit fantastic, but if I place this code before main, instead of premain - it works.

    HttpMuxer.addHandler(
        Route(
          pattern = "/health",
          handler = new ReplyHandler("not OK\n"),
          index = Some(RouteIndex(alias = "Health", group = group))
        )
      )