alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.42k stars 8.04k forks source link

Add support for asynchronous Servlet in Sentinel Web Servlet Filter #306

Open xiejiashuai opened 5 years ago

xiejiashuai commented 5 years ago

Issue Description

Type: feature request

Describe what happened (or what feature you want)

Support asynchronous Servlet in Sentinel Web Servlet Filter.

Spring Boot中使用 CompletableFuture<T> or DefferdResult<T> or Callable<T> 作为返回值,引入 Sentinel CommonFilter 后无法响应,且无法正确统计。是否支持两种形式(同步与异步 Servlet)并存,比如使用案例如下:

@RestController
public class AsyncController {

    @GetMapping("/async")
    public CompletableFuture<String> async() {

        return CompletableFuture.supplyAsync(() -> {

                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    return "async\";
                }
        );

    }

}
jasonjoo2010 commented 5 years ago

I am trying working on it.

So there're two plan to support it: Same filter or separate filters

Which one we prefer? @sczyh30 @xiejiashuai

In one filter to implement them all reflecting should be used.

sczyh30 commented 5 years ago

I am trying working on it.

So there're two plan to support it: Same filter or separate filters

Which one we prefer? @sczyh30 @xiejiashuai

In one filter to implement them all reflecting should be used.

Maybe it's better to do this in the same filter, but seems a little tricky?

xiejiashuai commented 5 years ago

I am trying working on it. So there're two plan to support it: Same filter or separate filters Which one we prefer? @sczyh30 @xiejiashuai In one filter to implement them all reflecting should be used.

Maybe it's better to do this in the same filter, but seems a little tricky?

In my opinion ,One Filter seems impossible. Even more tricky,One application both has synchronized servlet and asychronous servlet.

xiejiashuai commented 5 years ago

I am trying working on it. So there're two plan to support it: Same filter or separate filters Which one we prefer? @sczyh30 @xiejiashuai In one filter to implement them all reflecting should be used.

Maybe it's better to do this in the same filter, but seems a little tricky?

Can only support that in Spring Mvc By AsyncHandlerInterceptor ?

jasonjoo2010 commented 5 years ago

I am trying working on it. So there're two plan to support it: Same filter or separate filters Which one we prefer? @sczyh30 @xiejiashuai In one filter to implement them all reflecting should be used.

Maybe it's better to do this in the same filter, but seems a little tricky?

In my opinion ,One Filter seems impossible. Even more tricky,One application both has synchronized servlet and asychronous servlet.

One filter is indeed possible i think.

I make an implementation and testing now

jasonjoo2010 commented 5 years ago

I post a PR #310

And still working on more unit tests

xiejiashuai commented 5 years ago

I post a PR #310

And still working on more unit tests

Very Thanks, I will see it.