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

@CLAassistant

CLAassistant commented May 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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.

@EvanYao826

Copy link
Copy Markdown
Author

@CLAassistant recheck please. I have signed the CLA.

@EvanYao826

Copy link
Copy Markdown
Author

@LearningGp I will fix the commit email to use the GitHub noreply format (155432245+EvanYao826@users.noreply.github.com) and force-push to resolve the CLA check failure.

@EvanYao826 EvanYao826 force-pushed the feat/global-fallback-aspectj-3110 branch from 6df4b3f to 96def8c Compare May 23, 2026 04:44
@EvanYao826

Copy link
Copy Markdown
Author

@LearningGp Thanks for pointing this out! The commit author email has been updated to the GitHub noreply format (155432245+EvanYao826@users.noreply.github.com). CLA check now passes successfully.

Please let me know if there are any other issues!

@EvanYao826

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

…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
@EvanYao826 EvanYao826 force-pushed the feat/global-fallback-aspectj-3110 branch from 96def8c to 530eb1f Compare May 27, 2026 02:10
@EvanYao826

Copy link
Copy Markdown
Author

Fixed the CLA issue - updated committer email to match my GitHub account email (2869018789@qq.com). Please recheck.

@EvanYao826

Copy link
Copy Markdown
Author

@LearningGp Fixed the CLA issue - updated committer email to match GitHub account (2869018789@qq.com). Please recheck.

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

Labels

None yet

3 participants