diff --git a/filter/common/rejected_execution_handler.go b/filter/common/rejected_execution_handler.go index 61aa0c39ea88359a5106fe33a920d5e431446098..b993b8444c14c13ce9a8861c113dc02ca5fd335a 100644 --- a/filter/common/rejected_execution_handler.go +++ b/filter/common/rejected_execution_handler.go @@ -22,8 +22,11 @@ import ( ) /** - * If the invocation cannot pass any validation in filter, like ExecuteLimit and TpsLimit, + * If the invocation cannot pass any validation in filter, like ExecuteLimitFilter and TpsLimitFilter, * the implementation will be used. + * The common case is that sometimes you want to return the default value when the request was rejected. + * Or you want to be warned if any request was rejected. + * In such situation, implement this interface and register it by invoking extension.SetRejectedExecutionHandler. */ type RejectedExecutionHandler interface { RejectedExecution(url common.URL, invocation protocol.Invocation) protocol.Result diff --git a/filter/impl/execute_limit_filter.go b/filter/impl/execute_limit_filter.go index fc710af8833463c180a32572165a566ee1c54570..156af1b140283dd76c4867ca26e9b42ce8eb25c0 100644 --- a/filter/impl/execute_limit_filter.go +++ b/filter/impl/execute_limit_filter.go @@ -58,12 +58,14 @@ func init() { * - name: "UpdateUser" * execute.limit: -1, # If the rate<0, the method will be ignored * - name: "DeleteUser" - * execute.limit.rejected.handle: "customHandler" + * execute.limit.rejected.handle: "customHandler" # Using the custom handler to do something when the request was rejected. * - name: "AddUser" * From the example, the configuration in service-level is 200, and the configuration of method GetUser is 20. * it means that, the GetUser will be counted separately. * The configuration of method UpdateUser is -1, so the invocation for it will not be counted. * So the method DeleteUser and method AddUser will be limited by service-level configuration. + * Sometimes we want to do something, like log the request or return default value when the request is over limitation. + * Then you can implement the RejectedExecutionHandler interface and register it by invoking SetRejectedExecutionHandler. */ type ExecuteLimitFilter struct { executeState *concurrent.Map