17. Actuator API

The /gateway actuator endpoint lets you monitor and interact with a Spring Cloud Gateway application. To be remotely accessible, the endpoint has to be enabled and exposed over HTTP or JMX in the application properties. The following listing shows how to do so:spring-doc.cn

Example 73. application.properties
management.endpoint.gateway.enabled=true # default value
management.endpoints.web.exposure.include=gateway

17.1. Verbose Actuator Format

A new, more verbose format has been added to Spring Cloud Gateway. It adds more detail to each route, letting you view the predicates and filters associated with each route along with any configuration that is available. The following example configures /actuator/gateway/routes:spring-doc.cn

[
  {
    "predicate": "(Hosts: [**.addrequestheader.org] && Paths: [/headers], match trailing slash: true)",
    "route_id": "add_request_header_test",
    "filters": [
      "[[AddResponseHeader X-Response-Default-Foo = 'Default-Bar'], order = 1]",
      "[[AddRequestHeader X-Request-Foo = 'Bar'], order = 1]",
      "[[PrefixPath prefix = '/httpbin'], order = 2]"
    ],
    "uri": "lb://testservice",
    "order": 0
  }
]

This feature is enabled by default. To disable it, set the following property:spring-doc.cn

Example 74. application.properties
spring.cloud.gateway.actuator.verbose.enabled=false

This will default to true in a future release.spring-doc.cn

17.2. Retrieving Route Filters

This section details how to retrieve route filters, including:spring-doc.cn

17.2.1. Global Filters

To retrieve the global filters applied to all routes, make a GET request to /actuator/gateway/globalfilters. The resulting response is similar to the following:spring-doc.cn

{
  "org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter@77856cc5": 10100,
  "org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@4f6fd101": 10000,
  "org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@32d22650": -1,
  "org.springframework.cloud.gateway.filter.ForwardRoutingFilter@106459d9": 2147483647,
  "org.springframework.cloud.gateway.filter.NettyRoutingFilter@1fbd5e0": 2147483647,
  "org.springframework.cloud.gateway.filter.ForwardPathFilter@33a71d23": 0,
  "org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@135064ea": 2147483637,
  "org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@23c05889": 2147483646
}

The response contains the details of the global filters that are in place. For each global filter, there is a string representation of the filter object (for example, org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter@77856cc5) and the corresponding order in the filter chain.}spring-doc.cn

17.2.2. Route Filters

To retrieve the GatewayFilter factories applied to routes, make a GET request to /actuator/gateway/routefilters. The resulting response is similar to the following:spring-doc.cn

{
  "[AddRequestHeaderGatewayFilterFactory@570ed9c configClass = AbstractNameValueGatewayFilterFactory.NameValueConfig]": null,
  "[SecureHeadersGatewayFilterFactory@fceab5d configClass = Object]": null,
  "[SaveSessionGatewayFilterFactory@4449b273 configClass = Object]": null
}

The response contains the details of the GatewayFilter factories applied to any particular route. For each factory there is a string representation of the corresponding object (for example, [SecureHeadersGatewayFilterFactory@fceab5d configClass = Object]). Note that the null value is due to an incomplete implementation of the endpoint controller, because it tries to set the order of the object in the filter chain, which does not apply to a GatewayFilter factory object.spring-doc.cn

17.3. Refreshing the Route Cache

To clear the routes cache, make a POST request to /actuator/gateway/refresh. The request returns a 200 without a response body.spring-doc.cn

17.4. Retrieving the Routes Defined in the Gateway

To retrieve the routes defined in the gateway, make a GET request to /actuator/gateway/routes. The resulting response is similar to the following:spring-doc.cn

[{
  "route_id": "first_route",
  "route_object": {
    "predicate": "org.springframework.cloud.gateway.handler.predicate.PathRoutePredicateFactory$$Lambda$432/1736826640@1e9d7e7d",
    "filters": [
      "OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.PreserveHostHeaderGatewayFilterFactory$$Lambda$436/674480275@6631ef72, order=0}"
    ]
  },
  "order": 0
},
{
  "route_id": "second_route",
  "route_object": {
    "predicate": "org.springframework.cloud.gateway.handler.predicate.PathRoutePredicateFactory$$Lambda$432/1736826640@cd8d298",
    "filters": []
  },
  "order": 0
}]

The response contains the details of all the routes defined in the gateway. The following table describes the structure of each element (each is a route) of the response:spring-doc.cn

Path Type Description

route_idspring-doc.cn

Stringspring-doc.cn

The route ID.spring-doc.cn

route_object.predicatespring-doc.cn

Objectspring-doc.cn

The route predicate.spring-doc.cn

route_object.filtersspring-doc.cn

Arrayspring-doc.cn

The GatewayFilter factories applied to the route.spring-doc.cn

orderspring-doc.cn

Numberspring-doc.cn

The route order.spring-doc.cn

17.5. Retrieving Information about a Particular Route

To retrieve information about a single route, make a GET request to /actuator/gateway/routes/{id} (for example, /actuator/gateway/routes/first_route). The resulting response is similar to the following:spring-doc.cn

{
  "id": "first_route",
  "predicates": [{
    "name": "Path",
    "args": {"_genkey_0":"/first"}
  }],
  "filters": [],
  "uri": "https://www.uri-destination.org",
  "order": 0
}

The following table describes the structure of the response:spring-doc.cn

Path Type Description

idspring-doc.cn

Stringspring-doc.cn

The route ID.spring-doc.cn

predicatesspring-doc.cn

Arrayspring-doc.cn

The collection of route predicates. Each item defines the name and the arguments of a given predicate.spring-doc.cn

filtersspring-doc.cn

Arrayspring-doc.cn

The collection of filters applied to the route.spring-doc.cn

urispring-doc.cn

Stringspring-doc.cn

The destination URI of the route.spring-doc.cn

orderspring-doc.cn

Numberspring-doc.cn

The route order.spring-doc.cn

17.6. Creating and Deleting a Particular Route

To create a route, make a POST request to /gateway/routes/{id_route_to_create} with a JSON body that specifies the fields of the route (see Retrieving Information about a Particular Route).spring-doc.cn

To delete a route, make a DELETE request to /gateway/routes/{id_route_to_delete}.spring-doc.cn

17.7. Recap: The List of All endpoints

The folloiwng table below summarizes the Spring Cloud Gateway actuator endpoints (note that each endpoint has /actuator/gateway as the base-path):spring-doc.cn

ID HTTP Method Description

globalfiltersspring-doc.cn

GETspring-doc.cn

Displays the list of global filters applied to the routes.spring-doc.cn

routefiltersspring-doc.cn

GETspring-doc.cn

Displays the list of GatewayFilter factories applied to a particular route.spring-doc.cn

refreshspring-doc.cn

POSTspring-doc.cn

Clears the routes cache.spring-doc.cn

routesspring-doc.cn

GETspring-doc.cn

Displays the list of routes defined in the gateway.spring-doc.cn

routes/{id}spring-doc.cn

GETspring-doc.cn

Displays information about a particular route.spring-doc.cn

routes/{id}spring-doc.cn

POSTspring-doc.cn

Adds a new route to the gateway.spring-doc.cn

routes/{id}spring-doc.cn

DELETEspring-doc.cn

Removes an existing route from the gateway.spring-doc.cn

17.8. Sharing Routes between multiple Gateway instances

Spring Cloud Gateway offers two RouteDefinitionRepository implementations. The first one is the InMemoryRouteDefinitionRepository which only lives within the memory of one Gateway instance. This type of Repository is not suited to populate Routes across multiple Gateway instances.spring-doc.cn

In order to share Routes across a cluster of Spring Cloud Gateway instances, RedisRouteDefinitionRepository can be used. To enable this kind of repository, the following property has to set to true: spring.cloud.gateway.redis-route-definition-repository.enabled Likewise to the RedisRateLimiter Filter Factory it requires the use of the spring-boot-starter-data-redis-reactive Spring Boot starter.spring-doc.cn