Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

开放健康检查的URL /actuator/** #287

Closed
Yookoo opened this issue Aug 14, 2020 · 3 comments
Closed

开放健康检查的URL /actuator/** #287

Yookoo opened this issue Aug 14, 2020 · 3 comments
Labels
type: question Further information is requested

Comments

@Yookoo
Copy link

Yookoo commented Aug 14, 2020

您好,我在文档 《网关过滤 springboot健康检查》一节中,看到通过自定义Filter可以解决健康检查问题,但里面只是直接写死返回Health UP 的json对象, 而我在项目中引用了Springboot的actuator的依赖,如何将actuator对应的 /actuator/** 下的详细信息都暴露出来?
目前我如果访问/actuator下的路径,soul会把它拦截返回 {code: -107,message: "未能匹配选择器,请检查你的选择器配置!",data: null},但是我只是想访问这个路径,而不是需要做转发。请问有什么好的解决方法吗?谢谢你的解答。

@yu199195
Copy link
Member

在前面的拦截器里面做就好了

@Yookoo
Copy link
Author

Yookoo commented Aug 17, 2020

你好, 我仔细学习了WebFlux的过滤器的用法,写了下面段代码去解决这个问题,但是目前还有一个疑问:当请求匹配到路由白名单之后,如果不在继续执行后面的过滤器链,需要如何返回一个Mono?(具体代码在倒数第5行)。谢谢你的解答。

@Slf4j
@Order(Integer.MIN_VALUE)
public class ActuatorFilter implements WebFilter {
    
    private static final String[] FILTER_TAG = {"/actuator/**", "/health_check"};

    /**
     * 过滤策略
     * @param exchange
     * @param chain
     * @return
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        ServerHttpRequest request = Objects.requireNonNull(exchange).getRequest();
        String urlPath = request.getURI().getPath();
        if (FilterUtil.checkWhiteList(urlPath, FILTER_TAG)) {
            //
            log.info("请求[{}]在白名单之中,允许访问.", urlPath);
            // 不在调用其他的过滤器,应该如何返回
            return Mono.empty();
        }
        return chain.filter(exchange);
    }
}

@yu199195 yu199195 added the type: question Further information is requested label Sep 1, 2020
@yu199195 yu199195 closed this as completed Sep 1, 2020
@lixianli1987
Copy link

你好, 我仔细学习了WebFlux的过滤器的用法,写了下面段代码去解决这个问题,但是目前还有一个疑问:当请求匹配到路由白名单之后,如果不在继续执行后面的过滤器链,需要如何返回一个Mono?(具体代码在倒数第5行)。谢谢你的解答。

@Slf4j
@Order(Integer.MIN_VALUE)
public class ActuatorFilter implements WebFilter {
    
    private static final String[] FILTER_TAG = {"/actuator/**", "/health_check"};

    /**
     * 过滤策略
     * @param exchange
     * @param chain
     * @return
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        ServerHttpRequest request = Objects.requireNonNull(exchange).getRequest();
        String urlPath = request.getURI().getPath();
        if (FilterUtil.checkWhiteList(urlPath, FILTER_TAG)) {
            //
            log.info("请求[{}]在白名单之中,允许访问.", urlPath);
            // 不在调用其他的过滤器,应该如何返回
            return Mono.empty();
        }
        return chain.filter(exchange);
    }
}

请问你是怎么获取到/actuator/**下所有信息的?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants