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

Improve RFQ propogation #1973

Closed
wants to merge 16 commits into from
Closed

Improve RFQ propogation #1973

wants to merge 16 commits into from

Conversation

trajan0x
Copy link
Contributor

@trajan0x trajan0x commented Feb 4, 2024

Description

Fix tracingbetween req-relayer and rfq-api

Summary by CodeRabbit

  • New Features

    • Introduced a new option to enhance tracing capabilities in API clients.
    • Added middleware to improve request handling in the API server.
    • Enhanced error handling and traceability in quote generation and submission processes.
    • Implemented a new test for end-to-end validation of ETH transactions.
  • Refactor

    • Modified error handling in inventory management to improve reliability.
  • Chores

    • Updated linter configuration to include testifylint for improved code quality checks.

Copy link
Contributor

coderabbitai bot commented Feb 4, 2024

Walkthrough

The recent updates focus on enhancing traceability, error handling, and testing within the RFQ service. Key modifications include the introduction of OpenTelemetry propagators, middleware for improved server functionality, refined context and error handling in quote generation and submission, adjustments in inventory management error handling, and the addition of a new linting tool for better code quality assurance. An integration test for ETH to ETH transactions has also been introduced, emphasizing the project's commitment to robustness and reliability.

Changes

File Path Summary
services/rfq/api/client/client.go Added WithPropagators option to otelresty.TraceClient calls.
services/rfq/api/rest/server.go Added middleware to Gin engine.
services/rfq/relayer/quoter/quoter.go Enhanced context and error handling in quote functions; adjusted function signatures.
services/rfq/relayer/inventory/manager.go Modified defer function signature in initializeTokens.
.golangci.yml Added testifylint to linters.
services/rfq/e2e/rfq_test.go Added TestETHtoETH() with conditional skip; included cyclop nolint directive.

🐇✨
In the code garden, changes bloom,
With traces and tests, no doom and gloom.
Middleware and lint, in harmony,
For ETH trades, a testimony.
Through errors and contexts, we finely groom.
🌟🐰💻

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Feb 4, 2024
@trajan0x trajan0x force-pushed the fix/propogator-rfq-api branch from 3c9b245 to a4658d8 Compare February 4, 2024 16:27
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7e30b1e and 3c9b245ff08c4f5586517123b9561af049b12f07.
Files selected for processing (1)
  • services/rfq/api/client/client.go (2 hunks)
Additional comments: 13
services/rfq/api/client/client.go (13)
  • 83-83: The otelresty.TraceClient call correctly adds the WithPropagators option to enhance tracing. Ensure that metrics.Propagator() is properly configured to return a compatible propagator for OpenTelemetry.
  • 100-100: The otelresty.TraceClient call in NewUnauthenticaedClient correctly includes the WithPropagators option. Verify that metricHandler.Propagator() returns the expected propagator instance for tracing.
  • 80-87: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The package declaration and file comments are clear and relevant to the file's purpose.

  • 80-87: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [7-14]

Imports are correctly organized and relevant to the functionality provided by this client file. No unused imports are detected.

  • 80-87: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [16-29]

Interface definitions for AuthenticatedClient and UnauthenticatedClient are clear and well-documented. Ensure that all methods are implemented as required.

  • 80-87: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [31-37]

The unauthenticatedClient struct and its resty method are correctly implemented. This method provides encapsulated access to the resty.Client.

  • 80-87: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [39-45]

The clientImpl struct correctly embeds the UnauthenticatedClient interface and holds a *resty.Client. This design supports both authenticated and unauthenticated client functionalities.

  • 80-87: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [47-84]

In NewAuthenticatedClient, the error handling, request signing, and tracing setup are correctly implemented. Pay attention to the TODO comment about GET requests not requiring authentication, which might need further action or removal based on current API requirements.

  • 97-103: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [86-100]

NewUnauthenticaedClient function correctly initializes a new resty.Client, sets the base URL, and adds a request ID header to each request. The tracing enhancement is appropriately applied.

  • 97-103: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [102-118]

The PutQuote method correctly performs a PUT request to the RFQ API. The TODO comment about handling the response should be addressed or removed if no action is deemed necessary.

  • 80-87: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [120-138]

GetAllQuotes method correctly retrieves all quotes from the RFQ API, with proper error handling and response parsing.

  • 80-87: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [140-160]

GetSpecificQuote method correctly retrieves a specific quote based on the provided request parameters, with appropriate error handling and response parsing.

  • 80-87: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [162-182]

GetQuoteByRelayerAddress method correctly retrieves quotes by relayer address, with proper error handling and response parsing.

Copy link

codecov bot commented Feb 4, 2024

Codecov Report

Attention: Patch coverage is 40.74074% with 16 lines in your changes are missing coverage. Please review.

Project coverage is 47.76756%. Comparing base (fdef3fa) to head (826a4f8).
Report is 100 commits behind head on master.

Files Patch % Lines
services/rfq/relayer/quoter/quoter.go 23.80952% 16 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #1973         +/-   ##
===================================================
- Coverage   48.80073%   47.76756%   -1.03317%     
===================================================
  Files            370         371          +1     
  Lines          27225       26966        -259     
  Branches          83          83                 
===================================================
- Hits           13286       12881        -405     
- Misses         12554       12748        +194     
+ Partials        1385        1337         -48     
Flag Coverage Δ
cctp-relayer ?
packages 90.51808% <ø> (ø)
promexporter ?
rfq 37.96200% <40.74074%> (-0.01577%) ⬇️
stiprelayer 3.33333% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@trajan0x trajan0x force-pushed the fix/propogator-rfq-api branch from 49f1873 to 85f95fe Compare February 4, 2024 16:49
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7e30b1e and 7308da6.
Files selected for processing (3)
  • services/rfq/api/client/client.go (2 hunks)
  • services/rfq/api/rest/server.go (1 hunks)
  • services/rfq/relayer/quoter/quoter.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/api/client/client.go
Additional comments: 3
services/rfq/api/rest/server.go (1)
  • 91-91: Ensure that the middleware added for tracing (r.handler.Gin()) properly handles all scenarios, including error states and non-200 responses, to ensure comprehensive trace coverage.
services/rfq/relayer/quoter/quoter.go (2)
  • 248-252: The use of defer for ending the span in generateQuotes is correct and ensures that the span is ended properly even if an error occurs or the function returns early. This is a good practice for consistent trace handling.
  • 248-252: Verify that all error messages returned from generateQuotes are clear and provide enough context for debugging. Avoid exposing internal implementation details or sensitive information in error messages.

Comment on lines 248 to 252
func (m *Manager) generateQuotes(parentCtx context.Context, chainID int, address common.Address, balance *big.Int) (_ []model.PutQuoteRequest, err error) {
ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "isProfitableQuote", trace.WithAttributes(attribute.Int(metrics.ChainID, chainID)))
defer func() {
metrics.EndSpanWithErr(span, err)
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding more detailed trace attributes before returning errors or at critical decision points within generateQuotes to enhance traceability and debugging capabilities.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7308da6 and 62ce2cb.
Files selected for processing (2)
  • services/rfq/relayer/inventory/manager.go (1 hunks)
  • services/rfq/relayer/quoter/quoter.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/relayer/quoter/quoter.go
Additional comments: 1
services/rfq/relayer/inventory/manager.go (1)
  • 243-245: The change in the defer function signature from func(err error) to func() removes the direct handling of errors within the defer statement. Verify the intention behind this change, especially considering the impact on error handling and tracing. Ensure that this modification aligns with the desired error reporting and tracing strategy.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 62ce2cb and 7275748.
Files selected for processing (3)
  • .golangci.yml (1 hunks)
  • services/rfq/e2e/rfq_test.go (1 hunks)
  • services/rfq/relayer/quoter/quoter.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/relayer/quoter/quoter.go
Additional comments: 2
.golangci.yml (1)
  • 96-96: Added testifylint to the linters list. Ensure that existing tests comply with testifylint rules to avoid a surge in linting errors.
services/rfq/e2e/rfq_test.go (1)
  • 202-202: Conditional skip based on an environment variable (CI) is used in TestETHtoETH. Ensure that this approach aligns with the project's testing strategy, especially for CI environments.

@@ -199,6 +199,7 @@ func (i *IntegrationSuite) TestUSDCtoUSDC() {
})
}

// nolint: cyclop
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of nolint: cyclop disables cyclomatic complexity checks for TestETHtoETH. Consider refactoring to reduce complexity or justify the need for complexity in this test.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7275748 and 4e51ba0.
Files selected for processing (2)
  • services/rfq/relayer/inventory/manager.go (1 hunks)
  • services/rfq/relayer/quoter/quoter.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • services/rfq/relayer/inventory/manager.go
  • services/rfq/relayer/quoter/quoter.go

Copy link

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Feb 23, 2024
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.

Review Status

Actionable comments generated: 5

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 4e51ba0 and 3381aa6.
Files selected for processing (1)
  • services/rfq/relayer/quoter/quoter.go (3 hunks)

Comment on lines +199 to +206
func (m *Manager) SubmitAllQuotes(parentCtx context.Context) (err error) {
timeCtx, cancel := context.WithTimeout(parentCtx, time.Minute*2)

ctx, span := m.metricsHandler.Tracer().Start(timeCtx, "submitQuotes")
defer func() {
logger.Error(err)
metrics.EndSpanWithErr(span, err)
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

The introduction of a new time context (timeCtx) in the SubmitAllQuotes function is a good practice for managing long-running operations. However, logging the error directly within the defer function (logger.Error(err)) might not be ideal as it could log nil errors or errors from outside the scope of this function due to the named return value pattern. Consider logging errors where they occur to ensure clarity and accuracy in error reporting.

Comment on lines +218 to +223
func (m *Manager) prepareAndSubmitQuotes(parentCtx context.Context, inv map[int]map[common.Address]*big.Int) (err error) {
ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "prepareAndSubmitQuotes")
defer func() {
logger.Error(err)
metrics.EndSpanWithErr(span, err)
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

In the prepareAndSubmitQuotes function, the same issue with error logging within the defer function is observed. This could lead to logging nil or unrelated errors. It's recommended to handle and log errors closer to where they occur, which can provide more context and make the logs more meaningful.

Comment on lines +253 to +258
// nolint: nestif, cyclop
func (m *Manager) generateQuotes(parentCtx context.Context, chainID int, address common.Address, balance *big.Int) (_ []model.PutQuoteRequest, err error) {
ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "generateQuotes", trace.WithAttributes(attribute.Int(metrics.ChainID, chainID)))
defer func() {
metrics.EndSpanWithErr(span, err)
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

The generateQuotes function correctly sets up a new context and span for tracing. However, the comment // nolint: nestif, cyclop indicates a potential complexity issue within the function. While disabling lint warnings might be necessary in some cases, it's generally a good practice to refactor complex functions to reduce their cognitive load and improve maintainability. Consider breaking down this function into smaller, more manageable pieces if possible.

defer func() {
logger.Error(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Logging errors directly within a defer function can lead to misleading error logs, especially when using named return values. It's possible for the err variable to be nil or to reflect an error from a different scope. Consider moving error logging to the specific error handling blocks where the context of the error is clear.

func (m *Manager) prepareAndSubmitQuotes(parentCtx context.Context, inv map[int]map[common.Address]*big.Int) (err error) {
ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "prepareAndSubmitQuotes")
defer func() {
logger.Error(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the previous comment, logging within a defer block in the prepareAndSubmitQuotes function can lead to inaccurate error logging. It's advisable to log errors closer to their source to ensure the logs accurately reflect the operation's outcome and context.

@github-actions github-actions bot removed the Stale label Feb 24, 2024
Copy link

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Mar 13, 2024
@github-actions github-actions bot closed this Mar 19, 2024
@github-actions github-actions bot deleted the fix/propogator-rfq-api branch June 1, 2024 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant