feat: Support retry in open api client
What's the purpose of this PR
about issue 104
Brief changelog
1.Custom HttpRequestRetyHandler supports all method requests to be retried 2.Add retry count parameter, default no retry
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the Contributing Guide before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run
mvn clean testto make sure this pull request doesn't break anything. - [x] Update the
CHANGESlog.
Summary by CodeRabbit
-
New Features
- Added configurable retry functionality to the open API client, allowing users to specify the number of retry attempts and define which HTTP methods are considered idempotent for retries.
-
Documentation
- Updated release notes to document the new retry support in the open API client.
-
Tests
- Enhanced integration tests to include configuration for the retry feature.
"""
Walkthrough
A retry mechanism was added to the Apollo OpenAPI client. The client and its builder now accept a retry count parameter and an array of idempotent HTTP methods. A new retry handler class was introduced to control retry behavior for specific network exceptions and HTTP methods. Documentation and integration tests were updated accordingly.
Changes
| File(s) | Change Summary |
|---|---|
| CHANGES.md | Added a release note entry for retry support in the Apollo Java 2.5.0 release notes. |
| .../openapi/client/ApolloOpenApiClient.java, .../openapi/client/ApolloOpenApiClientBuilder | Modified constructor to accept retryCount and idempotentHttpMethods; builder extended with withRetryCount(int) and withIdempotentHttpMethods(...); retry handler set conditionally. |
| .../openapi/client/extend/ApolloStandardHttpRequestRetryHandler.java | Added new class implementing retry logic for specific network exceptions and idempotent HTTP methods. |
| .../openapi/client/extend/IdempotentHttpMethod.java | Added new enum defining idempotent HTTP methods with helper methods to return standard and safe sets. |
| .../openapi/client/ApolloOpenApiClientIntegrationTest.java | Updated client creation to specify retry count with .withRetryCount(3) and idempotent HTTP methods with .withIdempotentHttpMethods(...). |
Sequence Diagram(s)
sequenceDiagram
participant User
participant Builder as ApolloOpenApiClientBuilder
participant Client as ApolloOpenApiClient
participant RetryHandler as ApolloStandardHttpRequestRetryHandler
User->>Builder: withRetryCount(retryCount)
User->>Builder: withIdempotentHttpMethods(methods)
User->>Builder: build()
Builder->>Client: new ApolloOpenApiClient(..., retryCount, idempotentHttpMethods)
Client->>RetryHandler: new ApolloStandardHttpRequestRetryHandler(retryCount, idempotentHttpMethods)
Client-->>User: Returns configured ApolloOpenApiClient
Poem
In the warren of code, a new path appears,
With retries for journeys through network frontiers.
The builder now wiser, counts hops it will try,
While idempotent bunnies leap, never shy.
Three hops, then pause—if the route is still blocked,
The rabbit just smiles, for the logic is locked! 🐇✨ """
[!NOTE]
⚡️ AI Code Reviews for VS Code, Cursor, Windsurf
CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Learn more here.
[!NOTE]
⚡️ Faster reviews with caching
CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure
Review - Disable Cacheat either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off theData Retentionsetting under your Organization Settings. Enjoy the performance boost—your workflow just got faster.
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro Cache: Disabled due to data retention organization setting Knowledge Base: Disabled due to data retention organization setting
📥 Commits
Reviewing files that changed from the base of the PR and between 7e933212981688ff58ea64a207ecc8919109ad53 and 2f0f5d5990531bd536985dda3512defe7c585d26.
📒 Files selected for processing (5)
-
CHANGES.md(1 hunks) -
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java(5 hunks) -
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/extend/ApolloStandardHttpRequestRetryHandler.java(1 hunks) -
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/extend/IdempotentHttpMethod.java(1 hunks) -
apollo-openapi/src/test/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClientIntegrationTest.java(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
- CHANGES.md
- apollo-openapi/src/test/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClientIntegrationTest.java
- apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/extend/ApolloStandardHttpRequestRetryHandler.java
- apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/extend/IdempotentHttpMethod.java
- apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build (8)
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Explain this complex logic. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai explain this code block. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and explain its main purpose. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
I have read the CLA Document and I hereby sign the CLA
All review suggestions have been completed.
There are some unresolved questions here:
- remove InterruptedIOException.class in default nonRetriableClasses. Is it reasonable?
- Is it reasonable to default to using safe http methods when users do not set idempotent HTTP methods?