spring-cloud / spring-cloud/spring-cloud-gateway

Activate metrics for route filters

Open
#2,986 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests, so start by tracing how route filters execute and how Micrometer metrics are currently registered. Define the supported timing scope for individual filters, combinations, and Ordered filters before implementation. Done should provide per-filter timing without requiring route configuration boundary filters.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend, observability
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.