finatra icon indicating copy to clipboard operation
finatra copied to clipboard

Programmatically access registered routes

Open fbiville opened this issue 9 years ago • 1 comments

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:

  • create a utility class to extract those routes from HttpRouter in a package com.twitter.finatra
  • use reflection
  • subclass HttpRouter

Steps to reproduce the behavior

N/A

fbiville avatar Feb 06 '17 15:02 fbiville

@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.

cacoco avatar Feb 06 '17 18:02 cacoco