Skip to content

feat: support Sentinel flow control for RestClient - #4273

Open
uuuyuqi wants to merge 3 commits into
alibaba:2025.1.xfrom
uuuyuqi:uuuyuqi/2025.1.x-sentinel-restclient-support
Open

feat: support Sentinel flow control for RestClient#4273
uuuyuqi wants to merge 3 commits into
alibaba:2025.1.xfrom
uuuyuqi:uuuyuqi/2025.1.x-sentinel-restclient-support

Conversation

@uuuyuqi

@uuuyuqi uuuyuqi commented Feb 27, 2026

Copy link
Copy Markdown
Collaborator

Describe what this PR does / why we need it

Support Sentinel flow control for RestClient

Does this pull request fix one issue?

None

This PR builds upon the original work by @QHtttttt . Thank you for the contribution! I have made a few minor fixes on top of it.

QHtttttt and others added 2 commits February 26, 2026 14:14
- Add SentinelRestClientInterceptor to intercept RestClient requests
- Add SentinelRestClientBeanPostProcessor to auto-inject interceptor
- Add SentinelRestClientHttpResponse for blocked request responses
- Support flow control (QPS limiting) and circuit breaking (degrade)
- Support custom blockHandler and fallback handlers
- Support URL cleaner for RESTful path normalization

Change-Id: Iedbe1dbe377eb5e1a6531c86c9c9850adcad12fb
Co-developed-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@uuuyuqi uuuyuqi changed the title feat: support Sentinel flow control for RestClient [WIP]feat: support Sentinel flow control for RestClient Feb 27, 2026
@uuuyuqi uuuyuqi added area/sentinel spring cloud alibaba sentinel area/ospp 开源之夏赛题 labels Feb 27, 2026
…er for each RestClient

Change-Id: Id9c65c5e44e97ffbbee804265db2f0bcf59d7ce0
Co-developed-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@uuuyuqi
uuuyuqi requested a review from LearningGp March 2, 2026 09:55
@uuuyuqi uuuyuqi changed the title [WIP]feat: support Sentinel flow control for RestClient feat: support Sentinel flow control for RestClient Mar 2, 2026
DegradeRule degradeRule2 = new DegradeRule("GET:https://httpbin.org/delay/3");
degradeRule2.setGrade(RuleConstant.DEGRADE_GRADE_RT);
degradeRule2.setCount(2000);
degradeRule1.setStatIntervalMs(10 * 1000);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

*/
@AutoConfiguration
@ConditionalOnClass(RestClient.class)
@ConditionalOnProperty(prefix = "spring.cloud.sentinel", name = "enabled",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否需要考虑 sentinel.restclient.enabled

@oss-sentinel-ai

Copy link
Copy Markdown

⚠️ Merge conflict detected

This PR has conflicts with the base branch and cannot be merged. Please rebase or merge the base branch into your branch and resolve the conflicts:

git fetch origin
git checkout uuuyuqi/2025.1.x-sentinel-restclient-support
git rebase origin/2025.1.x
# resolve conflicts, then:
git push --force-with-lease

This is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved.


Automated notification by github-manager-bot

@oss-sentinel-ai oss-sentinel-ai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR adds Sentinel flow control support for Spring 6 RestClient, creating two-level resources (host + path) with configurable block/fallback/urlCleaner handlers. The implementation follows the existing SentinelRestTemplate pattern closely. The code structure is clean and the entry/exit lifecycle is correct. However, the auto-configuration is too aggressive (applies to all RestClient beans by default) and there is no working test coverage.

Note: This PR has merge conflicts with the base branch that need to be resolved before it can be merged.

Suggestions

  • Consider making the blanket interceptor opt-in rather than opt-out to avoid surprising existing users
  • Add working unit tests (the current test is @Disabled)
  • Resolve merge conflicts with 2025.1.x

Automated review by github-manager-bot

@ConditionalOnClass(RestClient.class)
@ConditionalOnProperty(prefix = "spring.cloud.sentinel", name = "enabled",
havingValue = "true", matchIfMissing = true)
public class SentinelRestClientAutoConfiguration {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Warning] This auto-configuration registers a SentinelRestClientBeanPostProcessor that adds the Sentinel interceptor to every RestClient.Builder bean in the application (when spring.cloud.sentinel.enabled is true, which is the default). This is a broad behavioral change — users who add the Sentinel starter will silently get flow control on all their RestClient calls, even without the @SentinelRestClient annotation.

Consider either:

  1. Making the auto-configuration opt-in (e.g. matchIfMissing = false), or
  2. Only applying the interceptor to builders annotated with @SentinelRestClient (via the BeanPostProcessor), and removing the blanket RestClientBuilderCustomizer bean.

The existing SentinelRestTemplate integration requires explicit @SentinelRestTemplate annotation — this should follow the same pattern for consistency.

* @author QHT
*/
@Disabled("For debugging")
public class RestClientApplicationTest {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Warning] The only test in this module is @Disabled("For debugging"), providing zero test coverage for the new Sentinel + RestClient integration. Consider adding at least:

  • A unit test for SentinelRestClientInterceptor.intercept() that verifies entry/exit lifecycle and block handling
  • A test verifying the @SentinelRestClient annotation correctly wires the interceptor

The existing sentinel-resttemplate-example has working tests that can serve as a template.


String interceptorBeanName = interceptorBeanNamePrefix + "@"
+ bean.toString();
registerBean(interceptorBeanName, sentinelRestClient);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Info] The interceptor bean name includes bean.toString() which may produce unstable or verbose names depending on the RestClient.Builder implementation. Consider using a hash code or a simpler identifier (e.g., the bean name from the @Bean method) to keep the bean registry clean.

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

Labels

area/ospp 开源之夏赛题 area/sentinel spring cloud alibaba sentinel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants