twitter / finatra

Fast, testable, Scala services built on TwitterServer and Finagle
https://twitter.github.io/finatra/
Apache License 2.0
2.27k stars 406 forks source link

Programmatically access registered routes #384

Open fbiville opened 7 years ago

fbiville commented 7 years ago

There currently isn't any clean way to access HttpRouter tracked routes.

Context

I am trying to monitor (via our Graphite backend) unrouted requests. The only way I found was to create a catch-all controller.

Now, I want to use ScalaCheck to check the following invariant: all unrouted routes trigger a counter increment. To that end, I need a programmatic access to the app registered routes (so that mapped routes [except the catch-all one] are not generated).

Expected behavior

I expect some public method exposing a read-only copy of the configured routes, such as:

def registeredRoutes(): Seq[Route]

Actual behavior

Currently, I see only three hacky ways to get that information:

Steps to reproduce the behavior

N/A

cacoco commented 7 years ago

@fbiville thanks for the issue. This is currently by design. Why? Because the routes are added to the HttpRouter at a specific point in the startup lifecycle of the server and exposing a method or methods to read them opens the potential for that method to used at the wrong point in the lifecycle potentially leading to undesirable issues.

We have kicked around the idea for programmatic access for a bit but have not decided on a way forward yet. Please stay tuned. Thanks.