spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Activate metrics for route filters

Open ilozano2 opened this issue 2 years ago • 1 comments

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

There is no way to measure the time and overhead of a specific filter and the combinations of several filters in a route.

The upstream service call and looking up the correct route will be included in the latency, so measuring response time of a request to SCG doesn't provide a way to know time/overhead of applying filters.

Describe the solution you'd like

Having the following example

      - id: remove_response_header_test
        uri: http://httpbin.org
        predicates:
        - Host=**.removereresponseheader.org
        - Path=/headers
        filters:
        - RemoveResponseHeader=X-Request-Foo
        - AddResponseHeader=X-Request-Foo, Bar
        - RemoveJsonAttributesResponseBody=id,color

I want to get the time spent in each filter for a request: time(RemoveResponseHeader), time(RemoveJsonAttributesResponseBody), and time(RemoveJsonAttributesResponseBody) will allow us to check if the filters are working fine together and if one of them is adding extra latency.

Describe alternatives you've considered

I implemented StartTimer and StopTimer filters which use Micrometer to register metrics between the defined boundaries.

        filters:
        - StartTimer=response-headers-metric
        - RemoveResponseHeader=X-Request-Foo
        - AddResponseHeader=X-Request-Foo, Bar
        - StopTimer=response-headers-metric
        - StartTimer=remove-json-metric
        - RemoveJsonAttributesResponseBody=id,color

I will register via micrometer the metrics for response-headers-metric and remove-json-metric. Both are tagged by the route_id and also the request URI, so you can get numbers from different situations.

Limitations:

  • One big limitation is that it doesn't work with Ordered filters. For example, LocalResponseCache is a Ordered filter, having that you cannot define a boundary to contain it.
  • The developer needs to change the route configuration in order to measure the time

Additional context

  • If SCG OSS would have a built-in feature to register metrics for filters, we hadn't some of the limitations above.
  • Also, maybe we could activate other metrics like the time spent on Predicates

ilozano2 avatar Jun 23 '23 13:06 ilozano2

Dear team ,we need exactly same functionality on reactive gateway, any news for this feature to go in to the plan ?

alphana avatar Jun 12 '24 11:06 alphana