Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE-636-backwards-compatibility | Backwards compatibility support #582

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

deividaspetraitis
Copy link
Collaborator

@deividaspetraitis deividaspetraitis commented Dec 4, 2024

Adds backwards compatibility support for /pools endpoint allowing independent deployment of SQS

Summary by CodeRabbit

  • New Features

    • Introduced a method to check for legacy query parameters in pool requests, enhancing backward compatibility.
    • Updated response handling to accommodate both legacy and new request types, improving user experience.
  • Bug Fixes

    • Clarified deprecated query parameters in the request handling to guide users toward updated usage.
  • Refactor

    • Modified function signatures to include context for improved request processing and compatibility checks.

Adds backwards compatibility support for /pools endpoint allowing
independent deployment of SQS
@deividaspetraitis deividaspetraitis self-assigned this Dec 4, 2024
Copy link

sonarqubecloud bot commented Dec 4, 2024

Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The changes introduce a new method IsLegacy to the GetPoolsRequest struct, enabling checks for deprecated query parameters in HTTP requests. The UnmarshalHTTPRequest method has been updated with comments on deprecated parameters, guiding users towards new filter parameters. Additionally, modifications to pools_handler.go include an updated convertPoolsToResponse function, which now accepts the echo.Context for legacy checks and returns a flexible type. These updates enhance the handling of pool requests, particularly regarding backward compatibility.

Changes

File Path Change Summary
pkg/api/v1beta1/pools/http.go Added method IsLegacy to GetPoolsRequest to check for deprecated query parameters. Updated comments in UnmarshalHTTPRequest regarding deprecated parameters.
pools/delivery/http/pools_handler.go Updated GetPools and convertPoolsToResponse functions to include echo.Context. Modified return type of convertPoolsToResponse to any and added legacy request handling.

Possibly related PRs

Suggested labels

A:backport/v27.x

Suggested reviewers

  • cryptomatictrader
  • p0mvn

Poem

In the land of pools where the queries flow,
A legacy check helps us know,
With parameters old, we now can see,
The path to new filters, as clear as can be.
So hop along, dear friends, with glee,
For our code's now better, just wait and see! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
pkg/api/v1beta1/pools/http.go (2)

Line range hint 14-29: LGTM! Consider adding deprecation documentation.

The deprecation notices and their replacements are clearly marked. However, it would be beneficial to document the deprecation timeline and migration guide for users.

Consider adding:

  1. When these parameters will be fully deprecated
  2. A migration guide in the API documentation
  3. Deprecation warnings in the API response headers

60-66: Consider adding telemetry for legacy parameter usage.

While the implementation correctly identifies legacy requests, adding telemetry would help monitor the usage of deprecated parameters and inform future deprecation decisions.

Consider adding metrics:

 func (r *GetPoolsRequest) IsLegacy(c echo.Context) bool {
+    // Track usage of deprecated parameters
+    if c.QueryParam(queryIDs) != "" {
+        metrics.IncDeprecatedParameterUsage("pools_ids")
+    }
+    if c.QueryParam(queryMinLiquidityCap) != "" {
+        metrics.IncDeprecatedParameterUsage("pools_min_liquidity_cap")
+    }
+    if c.QueryParam(queryWithMarketIncentives) != "" {
+        metrics.IncDeprecatedParameterUsage("pools_with_market_incentives")
+    }
     return c.QueryParam(queryIDs) != "" ||
         c.QueryParam(queryMinLiquidityCap) != "" ||
         c.QueryParam(queryWithMarketIncentives) != ""
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5982389 and 7154796.

📒 Files selected for processing (2)
  • pkg/api/v1beta1/pools/http.go (1 hunks)
  • pools/delivery/http/pools_handler.go (2 hunks)
🔇 Additional comments (2)
pools/delivery/http/pools_handler.go (2)

108-108: LGTM! Clean integration of backwards compatibility check.

The change maintains the existing error handling while elegantly introducing the backwards compatibility check.


213-222: 🛠️ Refactor suggestion

Consider improving type safety and response validation.

While the implementation achieves backwards compatibility, there are some concerns:

  1. Using any as return type reduces type safety
  2. No validation of the response structure against API schema

Consider this alternative approach:

-func convertPoolsToResponse(c echo.Context, req *api.GetPoolsRequest, p []sqsdomain.PoolI, total uint64) any {
+func convertPoolsToResponse(c echo.Context, req *api.GetPoolsRequest, p []sqsdomain.PoolI, total uint64) (interface{}, error) {
     pools := make([]PoolResponse, 0, len(p))
     for _, pool := range p {
         pools = append(pools, convertPoolToResponse(pool))
     }

     if req.IsLegacy(c) {
-        return pools // backward compatibility
+        // Validate against legacy API schema
+        if err := validateLegacyResponse(pools); err != nil {
+            return nil, fmt.Errorf("invalid legacy response: %w", err)
+        }
+        return pools, nil
     }

-    return &GetPoolsResponse{
+    response := &GetPoolsResponse{
         Data: pools,
         Meta: v1beta1.NewPaginationResponse(req.Pagination, total),
     }
+    // Validate against current API schema
+    if err := validateResponse(response); err != nil {
+        return nil, fmt.Errorf("invalid response: %w", err)
+    }
+    return response, nil
 }

Let's verify the impact of this change on error handling:

@deividaspetraitis deividaspetraitis merged commit 16e9207 into v27.x Dec 4, 2024
9 checks passed
@deividaspetraitis deividaspetraitis deleted the BE-636-backwards-compatibility branch December 4, 2024 09:27
@deividaspetraitis deividaspetraitis added the A:backport/v28.x Backport to v28.x branch label Dec 4, 2024
mergify bot pushed a commit that referenced this pull request Dec 4, 2024
Adds backwards compatibility support for /pools endpoint allowing independent deployment of SQS

(cherry picked from commit 16e9207)
deividaspetraitis added a commit that referenced this pull request Dec 4, 2024
… (#583)

Adds backwards compatibility support for /pools endpoint allowing independent deployment of SQS

(cherry picked from commit 16e9207)

Co-authored-by: Deividas Petraitis <hi@deividaspetraitis.lt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v28.x Backport to v28.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant