10000 RFQ API: fix prometheus setup by dwasse · Pull Request #2701 · synapsecns/sanguine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

RFQ API: fix prometheus setup #2701

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

Merged
merged 22 commits into from
Jun 25, 2024
Merged

RFQ API: fix prometheus setup #2701

merged 22 commits into from
Jun 25, 2024

Conversation

dwasse
Copy link
Collaborator
@dwasse dwasse commented Jun 10, 2024

Summary by CodeRabbit

  • Bug Fixes

    • Handled potential nil values in API server tests to prevent errors when closing response bodies.
  • Chores

    • Added indirect dependency on github.com/cornelk/hashmap v1.0.8 across multiple modules for better performance and compatibility.
  • Refactor

    • Updated metrics handling for better performance and accuracy in transaction and quote management.

Copy link
Contributor
coderabbitai bot commented Jun 10, 2024

Walkthrough

The recent changes primarily focus on refactoring and enhancing metric handling across multiple files, optimizing transaction submission processes, and improving error handling in test cases. Metrics-related fields and methods were added to various structs, ensuring efficient recording and tracking. Dependencies for github.com/cornelk/hashmap were introduced as an indirect dependency to several modules.

Changes

Files/Paths Summary
ethergo/submitter/chain_queue.go Refactored handling of current nonces and pending transactions, updated data structures, added methods for metrics recording, and removed several redundant functions.
ethergo/submitter/submitter.go Added metrics-related fields and methods, introduced a call to setupMetrics, and modified existing methods for better interaction with metrics.
services/rfq/relayer/inventory/manager.go Removed error handling logic related to balance gauge creation in NewInventoryManager.
services/rfq/relayer/quoter/quoter.go Replaced quoteAmountHist with quoteAmountGauge, added currentQuotes slice, and made changes to metrics handling to record quote metrics.
Various go.mod files Added github.com/cornelk/hashmap v1.0.8 as an indirect dependency across multiple modules (agents, contrib/opbot, contrib/promexporter, ethergo, services/*).
services/rfq/relayer/relapi/server_test.go Enhanced error handling in test cases to check for nil values before closing the response body.

Poem

In the code's vast land, metrics grow,
With nonce and pending queues in tow,
Refactored paths, dependencies new,
For cleaner flows and clearer view.
A rabbit hops in fields of change,
With modern metrics, we rearrange.
🌟📊🐇


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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

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

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Jun 10, 2024
Copy link
cloudflare-workers-and-pages bot commented Jun 10, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1aef5ad
Status: ✅  Deploy successful!
Preview URL: https://e7fe55d0.sanguine-fe.pages.dev
Branch Preview URL: https://feat-rfq-prom-fix.sanguine-fe.pages.dev

View logs

Copy link
codecov bot commented Jun 10, 2024

Codecov Report

Attention: Patch coverage is 31.53153% with 76 lines in your changes missing coverage. Please review.

Project coverage is 25.70207%. Comparing base (9d19326) to head (1aef5ad).

Files Patch % Lines
services/rfq/relayer/quoter/quoter.go 22.50000% 29 Missing and 2 partials ⚠️
ethergo/submitter/chain_queue.go 7.69231% 24 Missing ⚠️
ethergo/submitter/submitter.go 44.44444% 10 Missing and 5 partials ⚠️
services/rfq/api/rest/server.go 66.66667% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2701         +/-   ##
===================================================
- Coverage   25.71371%   25.70207%   -0.01164%     
===================================================
  Files            759         759                 
  Lines          54469       54482         +13     
  Branches          80          80                 
===================================================
- Hits           14006       14003          -3     
- Misses         39020       39034         +14     
- Partials        1443        1445          +2     
Flag Coverage Δ
cctp-relayer 31.93780% <ø> (ø)
ethergo 48.67657% <26.41509%> (-0.21201%) ⬇️
explorer 4.97877% <ø> (ø)
omnirpc 33.08129% <ø> (ø)
opbot 0.22305% <ø> (ø)
promexporter 9.86717% <ø> (ø)
rfq 27.12163% <36.20690%> (+0.09831%) ⬆️
scribe 18.11159% <ø> (ø)
tools 30.55118% <ø> (ø)

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.

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: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d79b82a and 1e1c6b0.

Files selected for processing (1)
  • services/rfq/api/rest/server.go (3 hunks)
Additional comments not posted (2)
services/rfq/api/rest/server.go (2)

34-35: Added a constant meterName for Prometheus metrics.

This is a good practice as it centralizes the metric's name, making it easier to modify in the future if needed.


120-120: Initialization of meter using handler.Meter(meterName).

This change aligns with the new struct definition and properly initializes the meter field. Ensure that the handler is correctly configured to provide a Meter instance.

Comment on lines +129 to +137
q.latestQuoteAgeGauge, err = q.meter.Float64ObservableGauge("latest_quote_age")
if err != nil {
return nil, fmt.Errorf("could not create latest quote age gauge: %w", err)
}

_, err = q.meter.RegisterCallback(q.recordLatestQuoteAge, q.latestQuoteAgeGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Setup of latestQuoteAgeGauge and registration of callback.

- q.latestQuoteAgeGauge, err = q.meter.Float64ObservableGauge("latest_quote_age")
+ q.latestQuoteAgeGauge, err = metric.Float64ObservableGauge(q.meter, "latest_quote_age")

The method call seems incorrect as per the typical OpenTelemetry pattern. Please verify the correct method signature and adjust accordingly.

Committable suggestion was skipped due to low confidence.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1e1c6b0 and 016fd24.

Files selected for processing (2)
  • services/rfq/api/rest/server.go (5 hunks)
  • services/rfq/relayer/inventory/manager.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • services/rfq/relayer/inventory/manager.go
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/api/rest/server.go

@trajan0x
Copy link
Contributor

bumping

Copy link
@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Introduced Prometheus metrics to monitor latest quote age
  • Replaced handler field with meter field for better metric handling
  • Removed redundant error handling logic in inventory manager setup

2 file(s) reviewed, no comment(s)

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: 1

Outside diff range and nitpick comments (1)
services/rfq/api/rest/server.go (1)

Line range hint 328-355: Logging and printing statements in recordLatestQuoteAge should be reviewed for production readiness.

The method recordLatestQuoteAge contains logging and printing statements that may not be suitable for a production environment due to potential performance impacts or unnecessary output. Consider revising these statements or implementing a more sophisticated logging framework that can be dynamically adjusted based on the environment.

-	logger.Warnf("recordLatestQuoteAge")
-	fmt.Printf("recording latest quote age")
+	if debugEnabled {
+		logger.Warnf("recordLatest QuoteAge")
+		fmt.Printf("recording latest quote age")
+	}

This change ensures that logs are only produced when debugging is explicitly enabled, reducing potential clutter and performance overhead in production.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 016fd24 and 42e3570.

Files selected for processing (1)
  • services/rfq/api/rest/server.go (5 hunks)
Additional comments not posted (1)
services/rfq/api/rest/server.go (1)

129-137: Verify the correct method signature for Prometheus metrics setup.

The method call to q.meter.Float64ObservableGauge and q.meter.RegisterCallback in the Prometheus metrics setup appears to be potentially incorrect. Please ensure that the method signatures match the expected patterns in OpenTelemetry or Prometheus libraries.

@@ -39,6 +41,7 @@
engine *gin.Engine
omnirpcClient omniClient.RPCClient
handler metrics.Handler
meter metric.Meter
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Ensure all references to handler are updated to meter.

The search results show multiple occurrences of handler in the file services/rfq/api/rest/server.go. These references should be reviewed and updated to meter if necessary:

  • services/rfq/api/rest/server.go:handler metrics.Handler
  • services/rfq/api/rest/server.go:handler metrics.Handler,
  • services/rfq/api/rest/server.go:if handler == nil {
  • services/rfq/api/rest/server.go:handler: handler,
  • services/rfq/api/rest/server.go:meter: handler.Meter(meterName),
  • services/rfq/api/rest/server.go:if r.handler == nil || r.latestQuoteAgeGauge == nil {

Please review these lines and update the references to meter where applicable.

Analysis chain

Ensure all references to handler are updated to meter.

The replacement of the handler field with meter in the QuoterAPIServer struct has been noted. It is crucial to ensure that all references in the codebase to the old handler field are updated accordingly to prevent any runtime errors.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all references to `handler` have been updated to `meter`.

# Test: Search for the usage of `handler`. Expect: No occurrences of `handler` outside of historical comments or documentation.
rg --type go $'handler'

Length of output: 64290

Copy link
@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Introduced Prometheus metrics in the quoting API server for better monitoring.
  • Exposed Prometheus metrics via a new endpoint.
  • Set up a gauge to record the age of the latest quote.
  • Added logging for enhanced traceability of the latest quote age.

1 file(s) reviewed, 1 comment(s)

@@ -307,6 +328,9 @@ func (r *QuoterAPIServer) PutRelayAck(c *gin.Context) {
}

func (r *QuoterAPIServer) recordLatestQuoteAge(ctx context.Context, observer metric.Observer) (err error) {
logger.Warnf("recordLatestQuoteAge")
Copy link

Choose a reason for hiding this comment

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

Consider using a more descriptive log level than 'Warn' for regular operations.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 42e3570 and 5117241.

Files selected for processing (1)
  • services/rfq/api/rest/server.go (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/api/rest/server.go

6D40

Copy link
@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Introduced Prometheus metrics to monitor the latest quote age in QuoterAPIServer
  • Enhanced recordLatestQuoteAge method with logging and printing for better monitoring
  • Removed redundant error handling logic in NewInventoryManager function for efficiency
  • Cleaned up recordLatestQuoteAge method by removing redundant logging and printing statements

1 file(s) reviewed, no comment(s)

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5117241 and 54d3c11.

Files selected for processing (1)
  • services/rfq/api/rest/server.go (4 hunks)
Files skipped from review due to trivial changes (1)
  • services/rfq/api/rest/server.go

@github-actions github-actions bot added size/s and removed size/xs labels Jun 24, 2024
Copy link
@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Enhanced metrics tracking with Prometheus integration
  • Improved error handling in NewInventoryManager
  • Refactored nonce and pending transaction handling for different chain IDs
  • Replaced various metrics registration methods with direct metrics recording
  • Optimized metrics setup for better performance tracking

1 file(s) reviewed, no comment(s)

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: 5

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 668a8eb and 3218f64.

Files selected for processing (2)
  • ethergo/submitter/chain_queue.go (6 hunks)
  • ethergo/submitter/submitter.go (6 hunks)
Additional context used
GitHub Check: codecov/patch
ethergo/submitter/chain_queue.go

[warning] 150-153: ethergo/submitter/chain_queue.go#L150-L153
Added lines #L150 - L153 were not covered by tests


[warning] 155-157: ethergo/submitter/chain_queue.go#L155-L157
Added lines #L155 - L157 were not covered by tests


[warning] 159-160: ethergo/submitter/chain_queue.go#L159-L160
Added lines #L159 - L160 were not covered by tests


[warning] 163-163: ethergo/submitter/chain_queue.go#L163
Added line #L163 was not covered by tests


[warning] 166-169: ethergo/submitter/chain_queue.go#L166-L169
Added lines #L166 - L169 were not covered by tests


[warning] 171-173: ethergo/submitter/chain_queue.go#L171-L173
Added lines #L171 - L173 were not covered by tests


[warning] 175-177: ethergo/submitter/chain_queue.go#L175-L177
Added lines #L175 - L177 were not covered by tests

ethergo/submitter/submitter.go

[warning] 126-127: ethergo/submitter/submitter.go#L126-L127
Added lines #L126 - L127 were not covered by tests


[warning] 146-147: ethergo/submitter/submitter.go#L146-L147
Added lines #L146 - L147 were not covered by tests


[warning] 151-152: ethergo/submitter/submitter.go#L151-L152
Added lines #L151 - L152 were not covered by tests


[warning] 156-157: ethergo/submitter/submitter.go#L156-L157
Added lines #L156 - L157 were not covered by tests


[warning] 161-162: ethergo/submitter/submitter.go#L161-L162
Added lines #L161 - L162 were not covered by tests

GitHub Check: Lint (ethergo)
ethergo/submitter/chain_queue.go

[failure] 150-150:
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 166-166:
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Additional comments not posted (2)
ethergo/submitter/chain_queue.go (1)

136-136: Potential race condition in updating numPendingTxes.

The assignment to numPendingTxes is not protected by a mutex, which could lead to race conditions if multiple goroutines modify it concurrently. Consider using a mutex to synchronize access to numPendingTxes.

ethergo/submitter/submitter.go (1)

80-80: Unused fields and method in txSubmitterImpl.

The fields numPendingGauge and nonceGauge, and the method setupMetrics are flagged as unused. If these are not expected to be used in the future, consider removing them to clean up the codebase.

Also applies to: 82-82, 143-143

nonceHist, err := meter.Int64Histogram("current_nonce")
if err != nil {
return fmt.Errorf("error creating nonce histogram: %w", err)
func (t *txSubmitterImpl) recordNumPending(ctx context.Context, observer metric.Observer) (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Renaming unused parameter 'ctx' to underscore.

The parameter ctx is not used within the recordNumPending and recordNonces methods. According to static analysis, it should be renamed to _ to indicate it's intentionally unused.

- func (t *txSubmitterImpl) recordNumPending(ctx context.Context, observer metric.Observer) (err error) {
+ func (t *txSubmitterImpl) recordNumPending(_ context.Context, observer metric.Observer) (err error) {
- func (t *txSubmitterImpl) recordNonces(ctx context.Context, observer metric.Observer) (err error) {
+ func (t *txSubmitterImpl) recordNonces(_ context.Context, observer metric.Observer) (err error) {

Also applies to: 166-166

Tools
GitHub Check: codecov/patch

[warning] 150-153: ethergo/submitter/chain_queue.go#L150-L153
Added lines #L150 - L153 were not covered by tests

GitHub Check: Lint (ethergo)

[failure] 150-150:
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Comment on lines 150 to 153
func (t *txSubmitterImpl) recordNumPending(ctx context.Context, observer metric.Observer) (err error) {
if t.metrics == nil || t.numPendingGauge == nil || t.numPendingTxes == nil {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for newly added lines.

Several lines related to metric recording and observer operations lack test coverage. Consider adding unit tests to ensure these functionalities work as expected and to maintain a high code coverage standard.

Also applies to: 155-157, 159-160, 163-163, 166-169, 171-173, 175-177

Tools
GitHub Check: codecov/patch

[warning] 150-153: ethergo/submitter/chain_queue.go#L150-L153
Added lines #L150 - L153 were not covered by tests

GitHub Check: Lint (ethergo)

[failure] 150-150:
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Comment on lines +126 to +127
return fmt.Errorf("could not setup metrics: %w", err)
}
10000
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for newly added lines.

Several lines related to metric setup and error handling lack test coverage. Consider adding unit tests to ensure these functionalities work as expected and to maintain a high code coverage standard.

Also applies to: 146-147, 151-152, 156-157, 161-162

Tools
GitHub Check: codecov/patch

[warning] 126-127: ethergo/submitter/submitter.go#L126-L127
Added lines #L126 - L127 were not covered by tests

"go.opentelemetry.io/otel/trace"
"golang.org/x/sync/errgroup"
)

var logger = log.Logger("ethergo-submitter")

const meterName = "github.com/synapsecns/sanguine/services/rfq/api/rest"
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider encapsulating meterName within txSubmitterImpl.

The meterName constant is globally defined but only used within the txSubmitterImpl struct. Consider moving it inside the struct to encapsulate it properly and to enhance readability and maintainability.

- const meterName = "github.com/synapsecns/sanguine/services/rfq/api/rest"
+ // Now inside the txSubmitterImpl struct.

Committable suggestion was skipped due to low confidence.

Copy link
@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Enhanced metrics tracking for transaction submissions, including pending transactions and current nonces.
  • Improved internal structure for handling and recording metrics.
  • Revamped metrics handling for quote requests in the Manager struct.
  • Removed redundant error handling in the NewInventoryManager function.

2 file(s) reviewed, no comment(s)

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3218f64 and f4a3af4.

Files selected for processing (2)
  • ethergo/submitter/chain_queue.go (6 hunks)
  • services/rfq/relayer/quoter/quoter.go (6 hunks)
Additional context used
GitHub Check: codecov/patch
ethergo/submitter/chain_queue.go

[warning] 151-153: ethergo/submitter/chain_queue.go#L151-L153
Added lines #L151 - L153 were not covered by tests


[warning] 155-160: ethergo/submitter/chain_queue.go#L155-L160
Added lines #L155 - L160 were not covered by tests


[warning] 163-163: ethergo/submitter/chain_queue.go#L163
Added line #L163 was not covered by tests


[warning] 167-169: ethergo/submitter/chain_queue.go#L167-L169
Added lines #L167 - L169 were not covered by tests


[warning] 171-177: ethergo/submitter/chain_queue.go#L171-L177
Added lines #L171 - L177 were not covered by tests

services/rfq/relayer/quoter/quoter.go

[warning] 126-127: services/rfq/relayer/quoter/quoter.go#L126-L127
Added lines #L126 - L127 were not covered by tests


[warning] 131-132: services/rfq/relayer/quoter/quoter.go#L131-L132
Added lines #L131 - L132 were not covered by tests


[warning] 402-402: services/rfq/relayer/quoter/quoter.go#L402
Added line #L402 was not covered by tests


[warning] 406-414: services/rfq/relayer/quoter/quoter.go#L406-L414
Added lines #L406 - L414 were not covered by tests


[warning] 416-429: services/rfq/relayer/quoter/quoter.go#L416-L429
Added lines #L416 - L429 were not covered by tests

Comment on lines 150 to 153
func (t *txSubmitterImpl) recordNumPending(_ context.Context, observer metric.Observer) (err error) {
if t.metrics == nil || t.numPendingGauge == nil || t.numPendingTxes == nil {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for newly added lines.

Several lines related to metric recording and observer operations lack test coverage. Consider adding unit tests to ensure these functionalities work as expected and to maintain a high code coverage standard.

Would you like me to help draft some unit tests for these new functionalities?

Tools
GitHub Check: codecov/patch

[warning] 151-153: ethergo/submitter/chain_queue.go#L151-L153
Added lines #L151 - L153 were not covered by tests

Comment on lines 166 to 169
func (t *txSubmitterImpl) recordNonces(_ context.Context, observer metric.Observer) (err error) {
if t.metrics == nil || t.nonceGauge == nil || t.currentNonces == nil {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for newly added lines.

Several lines related to metric recording and observer operations lack test coverage. Consider adding unit tests to ensure these functionalities work as expected and to maintain a high code coverage standard.

Would you like me to help draft some unit tests for these new functionalities?

Tools
GitHub Check: codecov/patch

[warning] 167-169: ethergo/submitter/chain_queue.go#L167-L169
Added lines #L167 - L169 were not covered by tests

if registerErr != nil {
span.AddEvent("could not register pending txes", trace.WithAttributes(attribute.String("error", registerErr.Error())))
}
t.numPendingTxes[uint32(chainID.Int64())] = len(cq.reprocessQueue)
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential race condition in updating numPendingTxes.

The assignment to numPendingTxes is not protected by a mutex, which could lead to race conditions if multiple goroutines modify it concurrently. Consider using a mutex to synchronize access to numPendingTxes.

- t.numPendingTxes[uint32(chainID.Int64())] = len(cq.reprocessQueue)
+ t.numPendingTxesMux.Lock()
+ t.numPendingTxes[uint32(chainID.Int64())] = len(cq.reprocessQueue)
+ t.numPendingTxesMux.Unlock()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
t.numPendingTxes[uint32(chainID.Int64())] = len(cq.reprocessQueue)
t.numPendingTxesMux.Lock()
t.numPendingTxes[uint32(chainID.Int64())] = len(cq.reprocessQueue)
t.numPendingTxesMux.Unlock()

if registerErr != nil {
span.AddEvent("could not register nonce", trace.WithAttributes(attribute.String("error", registerErr.Error())))
}
t.currentNonces[uint32(chainID.Int64())] = currentNonce
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 a mutex for thread-safe updates to currentNonces.

Direct assignment to currentNonces without synchronization could lead to race conditions in a concurrent environment. Consider using a mutex to protect these writes.

- t.currentNonces[uint32(chainID.Int64())] = currentNonce
+ t.currentNoncesMux.Lock()
+ t.currentNonces[uint32(chainID.Int64())] = currentNonce
+ t.currentNoncesMux.Unlock()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
t.currentNonces[uint32(chainID.Int64())] = currentNonce
t.currentNoncesMux.Lock()
t.currentNonces[uint32(chainID.Int64())] = currentNonce
t.currentNoncesMux.Unlock()

Comment on lines +126 to +127
return nil, fmt.Errorf("error creating quote amount gauge: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for error handling in metric setup.

The error handling branches during metric setup are not covered by tests. Adding unit tests for these cases would ensure robustness and prevent potential runtime issues.

Would you like me to assist in creating these tests?

Tools
GitHub Check: codecov/patch

[warning] 126-127: services/rfq/relayer/quoter/quoter.go#L126-L127
Added lines #L126 - L127 were not covered by tests

Comment on lines +131 to +132
return nil, fmt.Errorf("could not register callback: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for error handling in metric callback registration.

The error handling branches during the registration of metric callbacks are not covered by tests. It is crucial to test these to ensure that the metric system behaves as expected under all conditions.

Would you like me to assist in creating these tests?

Tools
GitHub Check: codecov/patch

[warning] 131-132: services/rfq/relayer/quoter/quoter.go#L131-L132
Added lines #L131 - L132 were not covered by tests

if m.meter == nil || m.quoteAmountHist == nil {
// recordQuoteAmounts records the latest quotes from the relayer.
func (m *Manager) recordQuoteAmounts(_ context.Context, observer metric.Observer) (err error) {
if m.meter == nil || m.quoteAmountGauge == nil || m.currentQuotes == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for the recordQuoteAmounts method.

The recordQuoteAmounts method lacks test coverage, especially for its error handling paths. Ensuring this method is well-tested is critical for the reliability of metric recording.

Would you like me to help draft some unit tests for this method?

Tools
GitHub Check: codecov/patch

[warning] 402-402: services/rfq/relayer/quoter/quoter.go#L402
Added line #L402 was not covered by tests

@trajan0x trajan0x requested a review from ChiTimesChi as a code owner June 25, 2024 15:21
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: 5

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f4a3af4 and 8ddc208.

Files ignored due to path filters (7)
  • agents/go.sum is excluded by !**/*.sum
  • contrib/opbot/go.sum is excluded by !**/*.sum
  • contrib/promexporter/go.sum is excluded by !**/*.sum
  • ethergo/go.sum is excluded by !**/*.sum
  • services/cctp-relayer/go.sum is excluded by !**/*.sum
  • services/omnirpc/go.sum is excluded by !**/*.sum
  • services/rfq/go.sum is excluded by !**/*.sum
Files selected for processing (9)
  • agents/go.mod (1 hunks)
  • contrib/opbot/go.mod (1 hunks)
  • contrib/promexporter/go.mod (1 hunks)
  • ethergo/go.mod (1 hunks)
  • ethergo/submitter/chain_queue.go (5 hunks)
  • ethergo/submitter/submitter.go (7 hunks)
  • services/cctp-relayer/go.mod (1 hunks)
  • services/omnirpc/go.mod (1 hunks)
  • services/rfq/go.mod (1 hunks)
Files skipped from review due to trivial changes (7)
  • agents/go.mod
  • contrib/opbot/go.mod
  • contrib/promexporter/go.mod
  • ethergo/go.mod
  • services/cctp-relayer/go.mod
  • services/omnirpc/go.mod
  • services/rfq/go.mod
Files skipped from review as they are similar to previous changes (1)
  • ethergo/submitter/submitter.go

Comment on lines +159 to +172
func (t *txSubmitterImpl) recordNonces(_ context.Context, observer metric.Observer) (err error) {
if t.metrics == nil || t.nonceGauge == nil || t.currentNonces == nil {
return nil
}
attributes := attribute.NewSet(
attribute.Int(metrics.ChainID, chainID),
attribute.String("wallet", t.signer.Address().Hex()),
)
nonceHist.Record(ctx, int64(nonce), metric.WithAttributeSet(attributes))

t.currentNonces.Range(func(chainID uint32, nonce uint64) bool {
opts := metric.WithAttributes(
attribute.Int(metrics.ChainID, int(chainID)),
attribute.String("wallet", t.signer.Address().Hex()),
)
observer.ObserveInt64(t.nonceGauge, int64(nonce), opts)
return true
})

Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for newly added lines.

Several lines related to metric recording and observer operations lack test coverage. Consider adding unit tests to ensure these functionalities work as expected and to maintain a high code coverage standard.

Would you like me to help draft some unit tests for these new functionalities?


Enhance error handling for incomplete nonce metrics setup.

Like the previous method, consider providing explicit error handling or logging for cases where the nonce metrics setup is incomplete.

- return nil
+ return fmt.Errorf("nonce metrics setup is incomplete")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (t *txSubmitterImpl) recordNonces(_ context.Context, observer metric.Observer) (err error) {
if t.metrics == nil || t.nonceGauge == nil || t.currentNonces == nil {
return nil
}
attributes := attribute.NewSet(
attribute.Int(metrics.ChainID, chainID),
attribute.String("wallet", t.signer.Address().Hex()),
)
nonceHist.Record(ctx, int64(nonce), metric.WithAttributeSet(attributes))
t.currentNonces.Range(func(chainID uint32, nonce uint64) bool {
opts := metric.WithAttributes(
attribute.Int(metrics.ChainID, int(chainID)),
attribute.String("wallet", t.signer.Address().Hex()),
)
observer.ObserveInt64(t.nonceGauge, int64(nonce), opts)
return true
})
func (t *txSubmitterImpl) recordNonces(_ context.Context, observer metric.Observer) (err error) {
if t.metrics == nil || t.nonceGauge == nil || t.currentNonces == nil {
return fmt.Errorf("nonce metrics setup is incomplete")
}
t.currentNonces.Range(func(chainID uint32, nonce uint64) bool {
opts := metric.WithAttributes(
attribute.Int(metrics.ChainID, int(chainID)),
attribute.String("wallet", t.signer.Address().Hex()),
)
observer.ObserveInt64(t.nonceGauge, int64(nonce), opts)
return true
})

if registerErr != nil {
span.AddEvent("could not register nonce", trace.WithAttributes(attribute.String("error", registerErr.Error())))
}
t.currentNonces.Set(uint32(chainID.Int64()), currentNonce)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using thread-safe updates for currentNonces.

Direct assignment to currentNonces without synchronization could lead to race conditions in a concurrent environment. Consider using a mutex to protect these writes.

- t.currentNonces.Set(uint32(chainID.Int64()), currentNonce)
+ t.currentNoncesMux.Lock()
+ t.currentNonces.Set(uint32(chainID.Int64()), currentNonce)
+ t.currentNoncesMux.Unlock()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
t.currentNonces.Set(uint32(chainID.Int64()), currentNonce)
t.currentNoncesMux.Lock()
t.currentNonces.Set(uint32(chainID.Int64()), currentNonce)
t.currentNoncesMux.Unlock()

if registerErr != nil {
span.AddEvent("could not register pending txes", trace.WithAttributes(attribute.String("error", registerErr.Error())))
}
t.numPendingTxes.Set(uint32(chainID.Int64()), len(cq.reprocessQueue))
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential race condition in updating numPendingTxes.

The assignment to numPendingTxes is not protected by a mutex, which could lead to race conditions if multiple goroutines modify it concurrently. Consider using a mutex to synchronize access to numPendingTxes.

- t.numPendingTxes.Set(uint32(chainID.Int64()), len(cq.reprocessQueue))
+ t.numPendingTxesMux.Lock()
+ t.numPendingTxes.Set(uint32(chainID.Int64()), len(cq.reprocessQueue))
+ t.numPendingTxesMux.Unlock()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
t.numPendingTxes.Set(uint32(chainID.Int64()), len(cq.reprocessQueue))
t.numPendingTxesMux.Lock()
t.numPendingTxes.Set(uint32(chainID.Int64()), len(cq.reprocessQueue))
t.numPendingTxesMux.Unlock()

Comment on lines +141 to +156
func (t *txSubmitterImpl) recordNumPending(_ context.Context, observer metric.Observer) (err error) {
if t.metrics == nil || t.numPendingGauge == nil || t.numPendingTxes == nil {
return nil
}
return meter

t.numPendingTxes.Range(func(chainID uint32, numPending int) bool {
opts := metric.WithAttributes(
attribute.Int(metrics.ChainID, int(chainID)),
attribute.String("wallet", t.signer.Address().Hex()),
)
observer.ObserveInt64(t.numPendingGauge, int64(numPending), opts)

return true
})

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for metrics setup.

Currently, the method exits without any error if the metrics setup is not complete. Consider logging or handling this scenario more explicitly to avoid silent failures in metrics recording.

- return nil
+ return fmt.Errorf("metrics setup is incomplete")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (t *txSubmitterImpl) recordNumPending(_ context.Context, observer metric.Observer) (err error) {
if t.metrics == nil || t.numPendingGauge == nil || t.numPendingTxes == nil {
return nil
}
return meter
t.numPendingTxes.Range(func(chainID uint32, numPending int) bool {
opts := metric.WithAttributes(
attribute.Int(metrics.ChainID, int(chainID)),
attribute.String("wallet", t.signer.Address().Hex()),
)
observer.ObserveInt64(t.numPendingGauge, int64(numPending), opts)
return true
})
return nil
func (t *txSubmitterImpl) recordNumPending(_ context.Context, observer metric.Observer) (err error) {
if t.metrics == nil || t.numPendingGauge == nil || t.numPendingTxes == nil {
return fmt.Errorf("metrics setup is incomplete")
}
t.numPendingTxes.Range(func(chainID uint32, numPending int) bool {
opts := metric.WithAttributes(
attribute.Int(metrics.ChainID, int(chainID)),
attribute.String("wallet", t.signer.Address().Hex()),
)
observer.ObserveInt64(t.numPendingGauge, int64(numPending), opts)
return true
})
return nil

Copy link
@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Introduced new metrics for tracking pending transactions and current nonces.
  • Simplified code for updating data structures and metrics recording.
  • Added stripLinks function for input sanitization in OpBot commands.
  • Updated dependencies in multiple go.mod files, including github.com/cornelk/hashmap.
  • Enhanced error handling and middleware in Screener API.

26 file(s) reviewed, no comment(s)

@github-actions github-actions bot added size/m and removed size/s labels Jun 25, 2024
Copy link
@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Enhanced metrics handling for current nonces and pending transactions
  • Updated metrics for quote requests to a gauge-based system
  • Improved error handling in inventory manager by removing unnecessary checks
  • Added github.com/cornelk/hashmap v1.0.8 as a new indirect dependency
  • Added null checks for resp and resp.Body in server_test.go to prevent runtime errors

1 file(s) reviewed, no comment(s)

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8ddc208 and 1aef5ad.

Files selected for processing (1)
  • services/rfq/relayer/relapi/server_test.go (5 hunks)
Additional comments not posted (5)
services/rfq/relayer/relapi/server_test.go (5)

30-33: Good practice to ensure resources are properly released

Adding checks to ensure resp and resp.Body are not nil before attempting to close the response body is a good practice to avoid potential nil pointer dereferences.


54-57: Proper resource management

The addition of nil checks before closing the response body in the deferred function helps prevent runtime panics due to nil dereferences. This is a crucial step in handling HTTP responses properly.


93-96: Consistent resource handling across test cases

The pattern of checking for non-nil resp and resp.Body before closure is consistently applied here, which is good for maintaining uniform error handling and resource management within the test suite.


131-134: Ensuring clean-up in test cases

The consistent application of nil checks before resource release across different tests in this file helps ensure that resources are always properly cleaned up, reducing the risk of resource leaks in tests.


171-171: Consider adding error handling for the response closure

While it's good to close the response body, consider handling potential errors from resp.Body.Close() to ensure that all aspects of resource management are covered.

- closeErr := resp.Body.Close()
+ closeErr := resp.Body.Close()
+ c.NoError(closeErr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0