green-creeper
green-creeper

Reputation: 316

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

Upvotes: 2

Views: 464

Answers (2)

green-creeper
green-creeper

Reputation: 316

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))
    )
  )

Upvotes: 0

nnythm
nnythm

Reputation: 3320

That looks like it should work. You should double check that the url you're hitting is $ADMIN_HOST:$ADMIN_PORT/health and not $ADMIN_HOST:$ADMIN_PORT/admin/health.

Upvotes: 0

Related Questions