apollo-java icon indicating copy to clipboard operation
apollo-java copied to clipboard

feat: Support retry in open api client

Open zth9 opened this issue 10 months ago • 3 comments

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 test to make sure this pull request doesn't break anything.
  • [x] Update the CHANGES log.

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.

zth9 avatar May 07 '25 06:05 zth9

"""

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 Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting 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.

❤️ Share
🪧 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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

coderabbitai[bot] avatar May 07 '25 06:05 coderabbitai[bot]

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

zth9 avatar May 07 '25 06:05 zth9

All review suggestions have been completed.

There are some unresolved questions here:

  1. remove InterruptedIOException.class in default nonRetriableClasses. Is it reasonable?
  2. Is it reasonable to default to using safe http methods when users do not set idempotent HTTP methods?

zth9 avatar May 11 '25 14:05 zth9