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

Add support for MVC Server actuator

Open imdr0id opened this issue 1 year ago • 6 comments

We're moving away from zuul to spring cloud gateway mvc. Earlier we used to get the routes with /actuator/routes endpoint, but now with gateway mvc I'm unable to get the list of routes defined via /actuator/gateway/routes.

I'm using the latest version of spring boot 3.2.2. please help!

application.yml

management:
  endpoint:
    gateway:
      enabled: true
  endpoints:
    web:
      exposure:
        include: '*'

dependencies:


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.2.2</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>17</java.version>
		<spring-cloud.version>2023.0.0</spring-cloud.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-gateway-mvc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-loadbalancer</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

imdr0id avatar Jan 24 '24 10:01 imdr0id

I have the same issue with the same setup as you. If I use Spring Cloud Gateway Reactive Server then I can access the routes from /actuator/gateway/routes. If I use Spring Cloud Gateway Server MVC then I cannot access the routes from /actuator/gateway/routes.

This dependency doesn't work for /actuator/gateway/routes <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway-mvc</artifactId>

This dependency will work for /actuator/gateway/routes <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId>

oexos avatar Feb 15 '24 00:02 oexos

@oexos yeah, while using the reactive server this will work, But our current setup won't allow us to use reactive server, because we're deploying this as a war to an external tomcat. That's the reason why we opted for gateway mvc instead of reactive gateway.

imdr0id avatar Feb 15 '24 05:02 imdr0id

Yes, there simply wasn't time to get it in before the initial release.

spencergibb avatar Mar 11 '24 19:03 spencergibb

In the meantime, they are all available via RouterFunction beans. For an example see https://github.com/spring-cloud/spring-cloud-gateway/blob/67b612d4af1ad9882a95cd7db0025ef0c7633089/spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/config/GatewayMvcPropertiesBeanDefinitionRegistrarTests.java#L143-L162

spencergibb avatar Mar 11 '24 19:03 spencergibb

Please add an actuator to the MVC version.

Gondagar avatar Mar 20 '24 15:03 Gondagar

@spencergibb : i was able to get the routes with the RouterFunction.

`

@Autowired
List<RouterFunction>  routerImplList;
private List<String> getRoutes() {
    AtomicReference<List<String>> routesList = new AtomicReference<>();
    routerImplList.forEach(a -> {
        if (a.getClass().getSimpleName().equals("DelegatingRouterFunction")) {
            a.accept(new AbstractRouterFunctionVisitor() {
                @Override
                @SuppressWarnings("unchecked")
                public void attributes(Map<String, Object> attributes) {
                    if (attributes.containsKey("gatewayRouterFunctions")) {
                        Map<String, RouterFunction> map = (Map<String, RouterFunction>) attributes
                                .get("gatewayRouterFunctions");
                        routesList.compareAndSet(null, map);
                    }
                }
            });
        }
    });
    return routesList.get();
}

`

imdr0id avatar Mar 22 '24 09:03 imdr0id