initial gateway actuator endpoint
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -28,6 +28,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot.experimental</groupId>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.springframework.cloud.gateway.actuate;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "endpoints.gateway")
|
||||
public class GatewayEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
private List<GatewayFilter> filters;
|
||||
|
||||
public GatewayEndpoint(List<GatewayFilter> filters) {
|
||||
super("gateway");
|
||||
this.filters = filters;
|
||||
AnnotationAwareOrderComparator.sort(this.filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> invoke() {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
ArrayList<String> filterNames = new ArrayList<>();
|
||||
for (GatewayFilter filter : this.filters) {
|
||||
filterNames.add(filter.getClass().getName());
|
||||
}
|
||||
map.put("filters", filterNames);
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.springframework.cloud.gateway.config;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.gateway.actuate.GatewayEndpoint;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.RouteToUrlFilter;
|
||||
import org.springframework.cloud.gateway.handler.GatewayFilteringWebHandler;
|
||||
@@ -13,6 +16,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.web.client.reactive.WebClient;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -56,4 +61,14 @@ public class GatewayAutoConfiguration {
|
||||
return new GatewayHostHandlerMapping(properties, webHandler);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(Endpoint.class)
|
||||
protected static class GatewayActuatorConfiguration {
|
||||
|
||||
@Bean
|
||||
public GatewayEndpoint gatewayEndpoint(List<GatewayFilter> filters) {
|
||||
return new GatewayEndpoint(filters);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,12 +6,16 @@ spring:
|
||||
cloud:
|
||||
gateway:
|
||||
routes:
|
||||
test1:
|
||||
requestPath: /**
|
||||
downstreamUrl: http://httpbin.org:80
|
||||
# test1:
|
||||
# requestPath: /**
|
||||
# downstreamUrl: http://httpbin.org:80
|
||||
test2:
|
||||
requestHost: '**.example.org'
|
||||
downstreamUrl: http://httpbin.org:80
|
||||
logging:
|
||||
level:
|
||||
org.springframework.cloud.gateway: TRACE
|
||||
|
||||
management:
|
||||
context-path: /admin
|
||||
# port: 8081
|
||||
|
||||
Reference in New Issue
Block a user