Skip to content

feat: add global fallback support for AspectJ annotation extension (#3110)#3617

Open
EvanYao826 wants to merge 1 commit into
alibaba:masterfrom
EvanYao826:feat/global-fallback-aspectj-3110
Open

feat: add global fallback support for AspectJ annotation extension (#3110)#3617
EvanYao826 wants to merge 1 commit into
alibaba:masterfrom
EvanYao826:feat/global-fallback-aspectj-3110

Conversation

@EvanYao826
Copy link
Copy Markdown

Fixes #3110

Summary

Add SentinelAnnotationGlobalFallback interface and integrate it into AbstractSentinelAspectSupport as a last-resort fallback handler.

When set on SentinelResourceAspect, the global fallback is invoked for all @SentinelResource-annotated methods when neither per-method fallback nor defaultFallback is configured (or found). This provides a universal 兜底 strategy without requiring each annotation to specify its own fallback.

Design

Follows the direction suggested by @sczyh30 in #3116: the global fallback lives in SentinelResourceAspect (not in the annotation), making it a cross-cutting concern.

Fallback resolution order:

  1. Per-method fallback (annotation attribute)
  2. Per-method defaultFallback (annotation attribute or class-level)
  3. Global fallback (set on the aspect) ← NEW
  4. Throw exception

Changes

New: SentinelAnnotationGlobalFallback interface

public interface SentinelAnnotationGlobalFallback {
    Object handle(Method originalMethod, Object[] args, Throwable t) throws Throwable;
}

Modified: AbstractSentinelAspectSupport

  • Added globalFallback field with getter/setter
  • Modified handleDefaultFallback() to try global fallback before throwing

Tests

3 unit tests for get/set/clear global fallback on AbstractSentinelAspectSupportTest.

Usage

@Bean
public SentinelResourceAspect sentinelResourceAspect() {
    SentinelResourceAspect aspect = new SentinelResourceAspect();
    aspect.setGlobalFallback((method, args, t) -> {
        // Universal fallback logic
        return "Global fallback: " + t.getMessage();
    });
    return aspect;
}

Notes

…libaba#3110)

Add SentinelAnnotationGlobalFallback interface and integrate it into
AbstractSentinelAspectSupport as a last-resort fallback handler.

When set on SentinelResourceAspect, the global fallback is invoked for
all @SentinelResource-annotated methods when neither per-method fallback
nor defaultFallback is configured (or found). This provides a universal
兜底 strategy without requiring each annotation to specify its own fallback.

Changes:
- New: SentinelAnnotationGlobalFallback interface with
  handle(Method, Object[], Throwable) contract
- Modified: AbstractSentinelAspectSupport adds setGlobalFallback/getGlobalFallback
- Modified: handleDefaultFallback() tries global fallback before throwing
- Tests: 3 unit tests for get/set/clear global fallback

Usage:
  SentinelResourceAspect aspect = new SentinelResourceAspect();
  aspect.setGlobalFallback((method, args, t) -> {
      return "Global fallback: " + t.getMessage();
  });

Fixes alibaba#3110
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@EvanYao826
Copy link
Copy Markdown
Author

I have read and fully agree to the Contributor License Agreement (CLA).

1 similar comment
@EvanYao826
Copy link
Copy Markdown
Author

I have read and fully agree to the Contributor License Agreement (CLA).

@LearningGp
Copy link
Copy Markdown
Collaborator

The CLA check failed. Please ensure that your commit email matches your GitHub account email.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants