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

RFQ Relayer: add request status count metric #2856

Merged
merged 19 commits into from
Jul 9, 2024
Merged

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Jul 8, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new metrics recording system using OpenTelemetry.
    • Added new metrics to track the status counts of quote requests.
    • Enhanced the relayer dashboard with updated configurations and new panels for better metric visualization.
  • Documentation

    • Updated documentation to include a new metric representing the distribution of non-terminal QuoteRequestStatus values over time.
  • Bug Fixes

    • Fixed identifiers and data sources in the relayer dashboard configuration for improved accuracy and usability.

55ed21b: docs preview link
c827962: docs preview link

Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Walkthrough

These changes introduce metrics recording with OpenTelemetry into the RFQ (Request For Quote) service's relayer component. A new otelRecorder is implemented along with methods to retrieve and record the status counts of quote requests. The relayer has been modified to periodically record these metrics, and new panels have been added to the dashboard JSON configuration.

Changes

File(s) Summary
services/rfq/go.mod Added github.com/cornelk/hashmap v1.0.8 as a direct dependency, removing it as an indirect dependency.
services/rfq/relayer/reldb/base/quote.go Added GetStatusCounts method to Store type to retrieve quote request counts by status.
services/rfq/relayer/reldb/db.go Added GetStatusCounts method to Reader interface to retrieve quote request counts by status.
services/rfq/relayer/service/otel.go (both changesets) Introduced otelRecorder for metrics recording with OpenTelemetry, including initialization and methods.
services/rfq/relayer/service/otel_generated.go Added iOtelRecorder interface with RecordStatusCount method for status count recording.
services/rfq/relayer/service/relayer.go Updated Relayer struct and NewRelayer function; added recordMetrics method.
docs/bridge/docs/rfq/Relayer/Relayer.md Documented new status_count metric for relayer.
services/rfq/relayer/dashboards/dashboard.json Updated multiple fields and added new panels for metrics monitoring.

Poem

In the land of code where numbers soar,
Metrics whisper, "Record me more!" 📊
With OpenTelemetry's guiding light,
Status counts in metrics' flight. 🌠
This relayer's metrics now refined,
Dashboards glow, insights aligned.
Oh, the tales our data tells,
In quote requests where logic dwells. 🐇✨


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/s labels Jul 8, 2024
Copy link

cloudflare-workers-and-pages bot commented Jul 8, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3e0dc86
Status: ✅  Deploy successful!
Preview URL: https://04759448.sanguine-fe.pages.dev
Branch Preview URL: https://feat-status-metric.sanguine-fe.pages.dev

View logs

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

  • services/rfq/relayer/reldb/base/quote.go: Added GetStatusCounts function to retrieve counts of quote requests by status.
  • services/rfq/relayer/reldb/db.go: Introduced GetStatusCounts method in the Reader interface for status count metrics.
  • services/rfq/relayer/service/otel.go: Added otelRecorder struct for recording request status counts as metrics.
  • services/rfq/relayer/service/otel_generated.go: Introduced iOtelRecorder interface with RecordStatusCount method.
  • services/rfq/relayer/service/relayer.go: Integrated otelRecorder in NewRelayer and added periodic recording of status counts in Start function.

5 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings

services/rfq/relayer/service/otel.go Show resolved Hide resolved

_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status gauge")
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in error message: should be 'could not register callback for status count gauge'

Suggested change
return nil, fmt.Errorf("could not register callback for status gauge")
return nil, fmt.Errorf("could not register callback for status count gauge")

return nil
}

// RecordstatusCounts records the request status count.
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in method name: should be 'RecordStatusCount'

Suggested change
// RecordstatusCounts records the request status count.
func (o *otelRecorder) RecordStatusCount(status, count int) {

Comment on lines 7 to 8
// RecordStatuses records the request status count.
RecordStatusCount(status, count int)
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Method name in comment should match the method name.

Suggested change
// RecordStatuses records the request status count.
RecordStatusCount(status, count int)
// RecordStatusCount records the request status count.

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)

  • Renamed gauge from status to status_count
  • Updated methods and variables to reflect the new gauge name in services/rfq/relayer/service/otel.go

1 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings


or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create last block gauge")
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in error message: should be 'could not create status count gauge'


_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status gauge")
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in error message: should be 'could not register callback for status count gauge'

return nil
}

// RecordstatusCounts records the request status count.
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in method name: should be 'RecordStatusCount'

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 otelRecorder struct for status count tracking
  • Set up gauge metric and callback for status counts
  • Implemented RecordStatusCount method for updating counts
  • Observing and recording status counts via recordStatusCounts method
  • Renamed gauge from status to status_count

1 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings


or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create last block gauge")
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in error message: should be 'could not create status count gauge'


_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status gauge")
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in error message: should be 'could not register callback for status count gauge'

return nil
}

// RecordStatusCounts records the request status count.
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in method name: should be 'RecordStatusCount'

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 31b5f8f and ce386ec.

Files selected for processing (5)
  • services/rfq/relayer/reldb/base/quote.go (1 hunks)
  • services/rfq/relayer/reldb/db.go (1 hunks)
  • services/rfq/relayer/service/otel.go (1 hunks)
  • services/rfq/relayer/service/otel_generated.go (1 hunks)
  • services/rfq/relayer/service/relayer.go (5 hunks)
Files skipped from review due to trivial changes (1)
  • services/rfq/relayer/service/otel_generated.go
Additional context used
GitHub Check: Lint (services/rfq)
services/rfq/relayer/service/otel.go

[failure] 68-68:
unnecessary conversion (unconvert)

Additional comments not posted (5)
services/rfq/relayer/service/otel.go (2)

79-82: LGTM!

The RecordStatusCount method looks good to me.


1-12: LGTM!

The file-level comments and imports look good to me.

services/rfq/relayer/reldb/db.go (1)

51-52: LGTM!

The addition of the GetStatusCounts method to the Reader interface looks good to me.

services/rfq/relayer/service/relayer.go (2)

146-150: LGTM!

The initialization of the otelRecorder in the NewRelayer function looks good to me.


65-66: LGTM!

The addition of the otelRecorder field to the Relayer struct looks good to me.

Comment on lines 66 to 68
o.statusCounts.Range(func(status int, count int) bool {
opts := metric.WithAttributes(
attribute.Int("status", int(status)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unnecessary conversion.

The conversion to int is unnecessary here.

-	attribute.Int("status", int(status)),
+	attribute.Int("status", status),
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
o.statusCounts.Range(func(status int, count int) bool {
opts := metric.WithAttributes(
attribute.Int("status", int(status)),
o.statusCounts.Range(func(status int, count int) bool {
opts := metric.WithAttributes(
attribute.Int("status", status),
Tools
GitHub Check: Lint (services/rfq)

[failure] 68-68:
unnecessary conversion (unconvert)

Comment on lines 40 to 58
func newOtelRecorder(meterHandler metrics.Handler, signer signer.Signer) (_ iOtelRecorder, err error) {
or := otelRecorder{
metrics: meterHandler,
meter: meterHandler.Meter(meterName),
statusCounts: hashmap.New[int, int](),
signer: signer,
}

or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create last block gauge")
}

_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status gauge")
}

return &or, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve error messages for better debugging.

The error messages in the newOtelRecorder method could be more specific to aid in debugging.

-	return nil, fmt.Errorf("could not create last block gauge")
+	return nil, fmt.Errorf("could not create status count gauge: %w", err)

-	return nil, fmt.Errorf("could not register callback for status gauge")
+	return nil, fmt.Errorf("could not register callback for status count gauge: %w", err)
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 newOtelRecorder(meterHandler metrics.Handler, signer signer.Signer) (_ iOtelRecorder, err error) {
or := otelRecorder{
metrics: meterHandler,
meter: meterHandler.Meter(meterName),
statusCounts: hashmap.New[int, int](),
signer: signer,
}
or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create last block gauge")
}
_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status gauge")
}
return &or, nil
func newOtelRecorder(meterHandler metrics.Handler, signer signer.Signer) (_ iOtelRecorder, err error) {
or := otelRecorder{
metrics: meterHandler,
meter: meterHandler.Meter(meterName),
statusCounts: hashmap.New[int, int](),
signer: signer,
}
or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create status count gauge: %w", err)
}
_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status count gauge: %w", err)
}
return &or, nil

services/rfq/relayer/reldb/base/quote.go Show resolved Hide resolved
Comment on lines 380 to 395
func (r *Relayer) recordMetrics(ctx context.Context) (err error) {
for {
select {
case <-ctx.Done():
return fmt.Errorf("could not record metrics: %w", ctx.Err())
case <-time.After(defaultMetricsInterval * time.Second):
statusCounts, err := r.db.GetStatusCounts(ctx)
if err != nil {
return fmt.Errorf("could not get status counts: %w", err)
}
for status, count := range statusCounts {
r.otelRecorder.RecordStatusCount(int(status.Int()), count)
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve error messages for better debugging.

The error messages in the recordMetrics method could be more specific to aid in debugging.

-	return fmt.Errorf("could not record metrics: %w", ctx.Err())
+	return fmt.Errorf("context done while recording metrics: %w", ctx.Err())

-	return fmt.Errorf("could not get status counts: %w", err)
+	return fmt.Errorf("could not get status counts from database: %w", err)
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 (r *Relayer) recordMetrics(ctx context.Context) (err error) {
for {
select {
case <-ctx.Done():
return fmt.Errorf("could not record metrics: %w", ctx.Err())
case <-time.After(defaultMetricsInterval * time.Second):
statusCounts, err := r.db.GetStatusCounts(ctx)
if err != nil {
return fmt.Errorf("could not get status counts: %w", err)
}
for status, count := range statusCounts {
r.otelRecorder.RecordStatusCount(int(status.Int()), count)
}
}
}
}
func (r *Relayer) recordMetrics(ctx context.Context) (err error) {
for {
select {
case <-ctx.Done():
return fmt.Errorf("context done while recording metrics: %w", ctx.Err())
case <-time.After(defaultMetricsInterval * time.Second):
statusCounts, err := r.db.GetStatusCounts(ctx)
if err != nil {
return fmt.Errorf("could not get status counts from database: %w", err)
}
for status, count := range statusCounts {
r.otelRecorder.RecordStatusCount(int(status.Int()), count)
}
}
}
}

Copy link

codecov bot commented Jul 8, 2024

Codecov Report

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

Project coverage is 25.61864%. Comparing base (9779cda) to head (3e0dc86).

Files Patch % Lines
services/rfq/relayer/service/otel.go 0.00000% 31 Missing ⚠️
services/rfq/relayer/service/relayer.go 0.00000% 24 Missing ⚠️
services/rfq/relayer/reldb/base/quote.go 0.00000% 21 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2856         +/-   ##
===================================================
+ Coverage   25.35936%   25.61864%   +0.25928%     
===================================================
  Files            784         769         -15     
  Lines          56350       55323       -1027     
  Branches          80          80                 
===================================================
- Hits           14290       14173        -117     
+ Misses         40581       39677        -904     
+ Partials        1479        1473          -6     
Flag Coverage Δ
opbot 0.18564% <ø> (ø)
promexporter ?

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

@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)

  • Added otelRecorder struct for status count tracking
  • Initialized gauge metric for status counts
  • Registered callback to record status counts
  • Implemented RecordStatusCount method
  • Renamed gauge from status to status_count

1 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings


or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create last block gauge")
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in error message: should be 'could not create status count gauge'


_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status gauge")
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in error message: should be 'could not register callback for status count gauge'

return nil
}

// RecordStatusCounts records the request status count.
Copy link

Choose a reason for hiding this comment

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

📚 spelling: Typo in method name: should be 'RecordStatusCount'

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 ce386ec and 5fa7fa8.

Files selected for processing (1)
  • services/rfq/relayer/service/otel.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/relayer/service/otel.go

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 otelRecorder struct for OpenTelemetry metrics recording (ethergo/listener/otel.go)
  • Added RecordLastBlock method for metrics recording (ethergo/listener/otel_generated.go)
  • Enhanced error handling and added GetStatusCounts method (services/rfq/relayer/reldb/base/quote.go)
  • Added setRelayRaceLost method for status updates (services/rfq/relayer/service/chainindexer.go)
  • Modified semaphore acquisition logic and added metrics recording (services/rfq/relayer/service/relayer.go)

6 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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)

  • Added metrics recording for quote request statuses using OpenTelemetry (services/rfq/relayer/service/relayer.go)
  • Introduced method to retrieve quote request counts based on status (services/rfq/relayer/service/relayer.go)
  • Enhanced Relayer struct to include OpenTelemetry metrics recorder (services/rfq/relayer/service/relayer.go)
  • Periodic recording of metrics for improved monitoring (services/rfq/relayer/service/relayer.go)

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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 5fa7fa8 and f19af1b.

Files selected for processing (2)
  • services/rfq/relayer/reldb/base/quote.go (1 hunks)
  • services/rfq/relayer/service/relayer.go (5 hunks)
Files skipped from review as they are similar to previous changes (2)
  • services/rfq/relayer/reldb/base/quote.go
  • services/rfq/relayer/service/relayer.go

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)

  • Updated services/rfq/go.mod to add github.com/cornelk/hashmap v1.0.8 as a direct dependency
  • Removed github.com/cornelk/hashmap v1.0.8 from indirect dependencies in services/rfq/go.mod

No major changes found since last review.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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)

  • Added metrics recording functionality using OpenTelemetry to monitor quote request statuses (services/rfq/relayer/service/otel.go)
  • Introduced RecordStatusCount method in iOtelRecorder interface for metrics monitoring (services/rfq/relayer/service/otel_generated.go)
  • Enhanced Relayer struct with otelRecorder field for periodic metrics recording (services/rfq/relayer/service/relayer.go)

3 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings

}

o.statusCounts.Range(func(status int, count int) bool {
fmt.Printf("recordStatusCounts with status: %d and count: %d\n", status, count)
Copy link

Choose a reason for hiding this comment

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

🪶 style: Remove or replace debug print statements with proper logging.


// RecordStatusCounts records the request status count.
func (o *otelRecorder) RecordStatusCount(status, count int) {
fmt.Printf("RecordStatusCount with status: %d and count: %d\n", status, count)
Copy link

Choose a reason for hiding this comment

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

🪶 style: Remove or replace debug print statements with proper logging.

if err != nil {
return fmt.Errorf("could not get status counts: %w", err)
}
fmt.Printf("got status counts: %v\n", statusCounts)
Copy link

Choose a reason for hiding this comment

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

🪶 style: Consider removing or replacing this debug print statement before merging.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f19af1b and b437e64.

Files selected for processing (4)
  • services/rfq/go.mod (2 hunks)
  • services/rfq/relayer/service/otel.go (1 hunks)
  • services/rfq/relayer/service/otel_generated.go (1 hunks)
  • services/rfq/relayer/service/relayer.go (5 hunks)
Files skipped from review due to trivial changes (1)
  • services/rfq/go.mod
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/relayer/service/otel_generated.go
Additional context used
GitHub Check: codecov/patch
services/rfq/relayer/service/otel.go

[warning] 40-49: services/rfq/relayer/service/otel.go#L40-L49
Added lines #L40 - L49 were not covered by tests


[warning] 51-51: services/rfq/relayer/service/otel.go#L51
Added line #L51 was not covered by tests


[warning] 53-54: services/rfq/relayer/service/otel.go#L53-L54
Added lines #L53 - L54 were not covered by tests


[warning] 56-56: services/rfq/relayer/service/otel.go#L56
Added line #L56 was not covered by tests


[warning] 58-58: services/rfq/relayer/service/otel.go#L58
Added line #L58 was not covered by tests


[warning] 61-62: services/rfq/relayer/service/otel.go#L61-L62
Added lines #L61 - L62 were not covered by tests


[warning] 64-65: services/rfq/relayer/service/otel.go#L64-L65
Added lines #L64 - L65 were not covered by tests


[warning] 67-67: services/rfq/relayer/service/otel.go#L67
Added line #L67 was not covered by tests


[warning] 69-76: services/rfq/relayer/service/otel.go#L69-L76
Added lines #L69 - L76 were not covered by tests


[warning] 78-78: services/rfq/relayer/service/otel.go#L78
Added line #L78 was not covered by tests


[warning] 82-82: services/rfq/relayer/service/otel.go#L82
Added line #L82 was not covered by tests


[warning] 84-84: services/rfq/relayer/service/otel.go#L84
Added line #L84 was not covered by tests

services/rfq/relayer/service/relayer.go

[warning] 146-149: services/rfq/relayer/service/relayer.go#L146-L149
Added lines #L146 - L149 were not covered by tests


[warning] 168-168: services/rfq/relayer/service/relayer.go#L168
Added line #L168 was not covered by tests


[warning] 290-295: services/rfq/relayer/service/relayer.go#L290-L295
Added lines #L290 - L295 were not covered by tests


[warning] 380-389: services/rfq/relayer/service/relayer.go#L380-L389
Added lines #L380 - L389 were not covered by tests


[warning] 391-393: services/rfq/relayer/service/relayer.go#L391-L393
Added lines #L391 - L393 were not covered by tests

Additional comments not posted (2)
services/rfq/relayer/service/otel.go (1)

27-38: LGTM! Struct definition looks good.

The otelRecorder struct is well-defined and aligns with the purpose of metrics recording.

services/rfq/relayer/service/relayer.go (1)

65-66: LGTM! Struct definition looks good.

The addition of the otelRecorder field is appropriate for recording metrics.

Comment on lines 61 to 78
func (o *otelRecorder) recordStatusCounts(_ context.Context, observer metric.Observer) (err error) {
if o.metrics == nil || o.statusCountGauge == nil || o.statusCounts == nil {
fmt.Println("something is nil")
return nil
}

o.statusCounts.Range(func(status int, count int) bool {
fmt.Printf("recordStatusCounts with status: %d and count: %d\n", status, count)
opts := metric.WithAttributes(
attribute.Int("status", status),
attribute.String("wallet", o.signer.Address().Hex()),
)
observer.ObserveInt64(o.statusCountGauge, int64(count), 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.

Add tests for the recordStatusCounts method.

These lines are not covered by tests. Ensure that this method is tested to verify its functionality.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 61-62: services/rfq/relayer/service/otel.go#L61-L62
Added lines #L61 - L62 were not covered by tests


[warning] 64-65: services/rfq/relayer/service/otel.go#L64-L65
Added lines #L64 - L65 were not covered by tests


[warning] 67-67: services/rfq/relayer/service/otel.go#L67
Added line #L67 was not covered by tests


[warning] 69-76: services/rfq/relayer/service/otel.go#L69-L76
Added lines #L69 - L76 were not covered by tests


[warning] 78-78: services/rfq/relayer/service/otel.go#L78
Added line #L78 was not covered by tests

Comment on lines 82 to 85
func (o *otelRecorder) RecordStatusCount(status, count int) {
fmt.Printf("RecordStatusCount with status: %d and count: %d\n", status, count)
o.statusCounts.Set(status, count)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add tests for the RecordStatusCount method.

These lines are not covered by tests. Ensure that this method is tested to verify its functionality.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 82-82: services/rfq/relayer/service/otel.go#L82
Added line #L82 was not covered by tests


[warning] 84-84: services/rfq/relayer/service/otel.go#L84
Added line #L84 was not covered by tests

Comment on lines 40 to 58
func newOtelRecorder(meterHandler metrics.Handler, signer signer.Signer) (_ iOtelRecorder, err error) {
or := otelRecorder{
metrics: meterHandler,
meter: meterHandler.Meter(meterName),
statusCounts: hashmap.New[int, int](),
signer: signer,
}

or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create status count gauge")
}

_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status count gauge")
}

return &or, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve error messages and add tests.

The error messages could be more specific to aid in debugging. Additionally, these lines are not covered by tests.

-	return nil, fmt.Errorf("could not create status count gauge")
+	return nil, fmt.Errorf("could not create status count gauge: %w", err)

-	return nil, fmt.Errorf("could not register callback for status count gauge")
+	return nil, fmt.Errorf("could not register callback for status count gauge: %w", err)

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

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 newOtelRecorder(meterHandler metrics.Handler, signer signer.Signer) (_ iOtelRecorder, err error) {
or := otelRecorder{
metrics: meterHandler,
meter: meterHandler.Meter(meterName),
statusCounts: hashmap.New[int, int](),
signer: signer,
}
or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create status count gauge")
}
_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status count gauge")
}
return &or, nil
func newOtelRecorder(meterHandler metrics.Handler, signer signer.Signer) (_ iOtelRecorder, err error) {
or := otelRecorder{
metrics: meterHandler,
meter: meterHandler.Meter(meterName),
statusCounts: hashmap.New[int, int](),
signer: signer,
}
or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create status count gauge: %w", err)
}
_, err = or.meter.RegisterCallback(or.recordStatusCounts, or.statusCountGauge)
if err != nil {
return nil, fmt.Errorf("could not register callback for status count gauge: %w", err)
}
return &or, nil
}
Tools
GitHub Check: codecov/patch

[warning] 40-49: services/rfq/relayer/service/otel.go#L40-L49
Added lines #L40 - L49 were not covered by tests


[warning] 51-51: services/rfq/relayer/service/otel.go#L51
Added line #L51 was not covered by tests


[warning] 53-54: services/rfq/relayer/service/otel.go#L53-L54
Added lines #L53 - L54 were not covered by tests


[warning] 56-56: services/rfq/relayer/service/otel.go#L56
Added line #L56 was not covered by tests


[warning] 58-58: services/rfq/relayer/service/otel.go#L58
Added line #L58 was not covered by tests

Comment on lines 380 to 393
func (r *Relayer) recordMetrics(ctx context.Context) (err error) {
for {
select {
case <-ctx.Done():
return fmt.Errorf("could not record metrics: %w", ctx.Err())
case <-time.After(defaultMetricsInterval * time.Second):
statusCounts, err := r.db.GetStatusCounts(ctx, reldb.Seen, reldb.NotEnoughInventory, reldb.CommittedPending, reldb.CommittedConfirmed, reldb.RelayStarted, reldb.RelayCompleted, reldb.ProvePosting, reldb.ProvePosted, reldb.ClaimPending)
if err != nil {
return fmt.Errorf("could not get status counts: %w", err)
}
fmt.Printf("got status counts: %v\n", statusCounts)
for status, count := range statusCounts {
r.otelRecorder.RecordStatusCount(int(status.Int()), count)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! But add tests for the recordMetrics method.

The method implementation is well-structured and aligns with its purpose. However, these lines are not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 380-389: services/rfq/relayer/service/relayer.go#L380-L389
Added lines #L380 - L389 were not covered by tests


[warning] 391-393: services/rfq/relayer/service/relayer.go#L391-L393
Added lines #L391 - L393 were not covered by tests

Comment on lines +146 to +149
otelRecorder, err := newOtelRecorder(metricHandler, sg)
if err != nil {
return nil, fmt.Errorf("could not get otel recorder: %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.

Improve error messages and add tests.

The error messages could be more specific to aid in debugging. Additionally, these lines are not covered by tests.

-	return nil, fmt.Errorf("could not get otel recorder: %w", err)
+	return nil, fmt.Errorf("could not initialize otel recorder: %w", err)

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

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
otelRecorder, err := newOtelRecorder(metricHandler, sg)
if err != nil {
return nil, fmt.Errorf("could not get otel recorder: %w", err)
}
otelRecorder, err := newOtelRecorder(metricHandler, sg)
if err != nil {
return nil, fmt.Errorf("could not initialize otel recorder: %w", err)
}
Tools
GitHub Check: codecov/patch

[warning] 146-149: services/rfq/relayer/service/relayer.go#L146-L149
Added lines #L146 - L149 were not covered by tests

Comment on lines +290 to +295
g.Go(func() error {
err = r.recordMetrics(ctx)
if err != nil {
return fmt.Errorf("could not record metrics: %w", err)
}
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.

Improve error messages and add tests.

The error messages could be more specific to aid in debugging. Additionally, these lines are not covered by tests.

-	return fmt.Errorf("could not record metrics: %w", err)
+	return fmt.Errorf("error recording metrics: %w", err)

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

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
g.Go(func() error {
err = r.recordMetrics(ctx)
if err != nil {
return fmt.Errorf("could not record metrics: %w", err)
}
return nil
g.Go(func() error {
err = r.recordMetrics(ctx)
if err != nil {
return fmt.Errorf("error recording metrics: %w", err)
}
return nil
Tools
GitHub Check: codecov/patch

[warning] 290-295: services/rfq/relayer/service/relayer.go#L290-L295
Added lines #L290 - L295 were not covered by tests

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)

  • Updated docs/bridge/docs/rfq/Relayer/Relayer.md to include new status_count metric for tracking QuoteRequestStatus.
  • Added a new panel in services/rfq/relayer/dashboards/dashboard.json to display non-terminal QuoteRequestStatus counts.
  • Introduced OpenTelemetry support in services/rfq/relayer/service/otel.go for recording status count metrics.
  • Enhanced services/rfq/relayer/service/relayer.go with OpenTelemetry metrics recording for quote request statuses.

4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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 b437e64 and 616feb5.

Files selected for processing (4)
  • docs/bridge/docs/rfq/Relayer/Relayer.md (1 hunks)
  • services/rfq/relayer/dashboards/dashboard.json (13 hunks)
  • services/rfq/relayer/service/otel.go (1 hunks)
  • services/rfq/relayer/service/relayer.go (5 hunks)
Files skipped from review as they are similar to previous changes (2)
  • services/rfq/relayer/service/otel.go
  • services/rfq/relayer/service/relayer.go
Additional comments not posted (8)
services/rfq/relayer/dashboards/dashboard.json (7)

21-21: Verify the uniqueness of the dashboard ID.

Ensure that the updated ID 770 does not conflict with other existing dashboards.


28-28: LGTM!

The datasource uid is correctly set to prometheus.


54-54: LGTM!

The datasource uid is correctly set to prometheus.


133-133: LGTM!

The datasource uid is correctly set to prometheus.


149-149: LGTM!

The datasource uid is correctly set to prometheus.


418-418: LGTM!

The datasource uid is correctly set to prometheus.


Line range hint 431-543:
LGTM!

The new panel configuration to display the count of non-terminal QuoteRequestStatus values over time is correctly set up.

docs/bridge/docs/rfq/Relayer/Relayer.md (1)

234-234: LGTM!

The documentation correctly describes the new status_count metric and its purpose.


or.statusCountGauge, err = or.meter.Int64ObservableGauge("status_count")
if err != nil {
return nil, fmt.Errorf("could not create status count gauge")
Copy link
Contributor

Choose a reason for hiding this comment

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

error should be wrapped here (e.g. fmt.Errorf("could not create status count gauge: %w") but in cases where it's not it's idiomatic to use errors.New() instead of fmt.Errorf

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)

  • Added status count metric to services/rfq/relayer/service/otel.go
  • Registered callback for recording status counts in otelRecorder
  • Enhanced relayer dashboard in services/rfq/relayer/dashboards/dashboard.json with new panels
  • Updated docs/bridge/docs/rfq/Relayer/Relayer.md to include status_count metric

No major changes found since last review.

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

Comment on lines +61 to +63
func (o *otelRecorder) recordStatusCounts(_ context.Context, observer metric.Observer) (err error) {
if o.metrics == nil || o.statusCountGauge == nil || o.statusCounts == nil {
return nil
Copy link

Choose a reason for hiding this comment

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

🪶 style: Consider logging an error or warning if any of these conditions are true.

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 616feb5 and 3e0dc86.

Files selected for processing (1)
  • services/rfq/relayer/service/otel.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • services/rfq/relayer/service/otel.go

@dwasse dwasse merged commit 15d18e8 into master Jul 9, 2024
32 of 33 checks passed
@dwasse dwasse deleted the feat/status-metric branch July 9, 2024 16:19
@trajan0x trajan0x mentioned this pull request Jul 11, 2024
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 M-docs size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants