Skip to content

Revert "[CLOB-1014] [CLOB-1004] Unify metrics library, un-modularize … #967

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 6 commits into from
Jan 16, 2024

Conversation

jonfung-dydx
Copy link
Contributor

@jonfung-dydx jonfung-dydx commented Jan 16, 2024

Metrics are not showing up due to commit 9e08e81/ pr #792 . Revert.

EDIT: this was not the issue.

Copy link

linear bot commented Jan 16, 2024

Copy link
Contributor

coderabbitai bot commented Jan 16, 2024

Walkthrough

The codebase has undergone a metrics system overhaul, shifting from an in-house metrics package and cosmos/cosmos-sdk/telemetry to armon/go-metrics for improved measurement and monitoring. This transition involves the introduction of new constants, functions, and methods to facilitate the collection and emission of metrics. Changes have been made across various modules, including the insurance fund balance, deleveraging processes, liquidation logic, and MEV calculations, to integrate with the new telemetry strategy.

Changes

File Path Change Summary
.../metrics/constants.go Added InsuranceFundBalance constant for insurance fund metrics.
.../metrics/util.go Introduced ModuleMeasureSinceWithLabels function for time measure metrics with labels.
.../clob/abci.go Replaced metrics package with telemetry for counter increments and gauge settings.
.../clob/keeper/deleveraging.go
.../clob/keeper/liquidations.go
.../clob/keeper/mev.go
Shifted from cosmos/cosmos-sdk/telemetry to armon/go-metrics for metrics and telemetry, updated metric names, labels, and error handling.
.../clob/types/order_id.go Updated GetOrderIdLabels method return type to []gometrics.Label, added armon/go-metrics import.

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.

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 3035168 and 63f2da5.
Files selected for processing (7)
  • protocol/lib/metrics/constants.go (1 hunks)
  • protocol/lib/metrics/util.go (2 hunks)
  • protocol/x/clob/abci.go (3 hunks)
  • protocol/x/clob/keeper/deleveraging.go (8 hunks)
  • protocol/x/clob/keeper/liquidations.go (6 hunks)
  • protocol/x/clob/keeper/mev.go (9 hunks)
  • protocol/x/clob/types/order_id.go (2 hunks)
Additional comments: 31
protocol/lib/metrics/util.go (2)
  • 6-6: The import of the time package is necessary for the new functionality introduced in the ModuleMeasureSinceWithLabels function.
  • 71-88: The new function ModuleMeasureSinceWithLabels is correctly defined and follows the established pattern of other functions in the file. It uses the gometrics.MeasureSinceWithLabels function to emit a time measure metric, which is consistent with the metrics package's usage.
protocol/x/clob/types/order_id.go (2)
  • 9-9: The new import github.com/armon/go-metrics is necessary due to the change in the return type of the GetOrderIdLabels method from []metrics.Label to []gometrics.Label.
  • 177-178: The change in the return type of the GetOrderIdLabels method from []metrics.Label to []gometrics.Label is consistent with the new import and the rest of the changes in the PR related to metrics handling.
protocol/x/clob/abci.go (3)
  • 7-7: The new import github.com/armon/go-metrics is consistent with the changes in metrics handling throughout the PR.
  • 76-79: The replacement of the metrics package with the telemetry package for incrementing counters is consistent with the PR's objective to revert changes to the metrics system.
  • 121-124: The use of telemetry.SetGaugeWithLabels to set the gauge for the insurance fund balance is consistent with the changes in metrics handling and the addition of the InsuranceFundBalance constant.
protocol/lib/metrics/constants.go (1)
  • 316-316: The addition of the InsuranceFundBalance constant is consistent with the changes in the abci.go file and the PR's objectives to update metrics handling.
protocol/x/clob/keeper/deleveraging.go (7)
  • 9-14: The import changes are consistent with the PR's objective to revert the metrics handling.
  • 81-87: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [84-96]

The labels are correctly updated to use gometrics.Label and the IncrCounterWithLabels function is replaced with gometrics.SetGaugeWithLabels, which aligns with the PR objectives.

  • 103-111: The telemetry.IncrCounterWithLabels and gometrics.AddSampleWithLabels functions are used appropriately to record metrics, consistent with the PR's goal.
  • 120-123: The gometrics.AddSampleWithLabels function is used correctly to record the percent filled of the deleveraging operation.
  • 291-295: The telemetry.ModuleMeasureSince function is replaced with defer to ensure the metric is recorded after the function execution, which is a good practice for timing metrics.
  • 431-453: The gometrics.AddSampleWithLabels function is used correctly to record various metrics related to the deleveraging process.
  • 587-595: The gometrics.AddSampleWithLabels function is used correctly to record the stat quantums deleveraged in quote quantums.
protocol/x/clob/keeper/mev.go (9)
  • 9-10: The import changes reflect the switch from armon/go-metrics to cosmos/cosmos-sdk/telemetry, which is consistent with the PR's objective to revert the metrics handling.
  • 73-73: The defer statement has been updated to use the telemetry package for metric recording, aligning with the revert of the metrics system.
  • 112-112: The error handling within the RecordMevMetrics function now correctly uses the telemetry package to increment the error counter.
  • 124-124: The error counter incrementation after failing to calculate PnL for block proposer MEV matches has been updated to use the telemetry package.
  • 138-138: The error handling for creating MEV matches for validator operations has been updated to use the telemetry package for incrementing the error counter.
  • 150-150: The error handling for calculating match PnL for the validator has been updated to use the telemetry package for incrementing the error counter.
  • 223-223: The error counter incrementation after failing to get the consensus round has been updated to use the telemetry package.
  • 235-235: The error handling for failing to get the proposer by consensus address now correctly uses the telemetry package to increment the error counter.
  • 290-302: The gauge setting for MEV metrics has been updated to use the telemetry package, which is consistent with the changes made throughout the file.
protocol/x/clob/keeper/liquidations.go (7)
  • 13-13: The import alias gometrics for github.com/armon/go-metrics is correctly defined.
  • 45-50: The change from metrics.AddSample to gometrics.AddSample with the updated metric names and labels is correct and aligns with the PR objectives.
  • 285-285: The update from metrics.Label to gometrics.Label is consistent with the changes made throughout the file.
  • 299-302: The replacement of metrics.AddSampleWithLabels with gometrics.AddSampleWithLabels and the adjustment of the metric names and labels are correct.
  • 325-328: The switch from metrics.IncrCounterWithLabels to telemetry.IncrCounterWithLabels with the updated metric names and labels is consistent with the PR objectives.
  • 330-333: The change from metrics.AddSampleWithLabels to gometrics.AddSampleWithLabels for the distribution metric is correct.
  • 593-605: The update from metrics.IncrCounterWithLabels to telemetry.IncrCounterWithLabels with the new labels is consistent with the changes made in other parts of the file.

Comment on lines +56 to +60
telemetry.IncrCounter(
1,
types.ModuleName,
metrics.PrepareCheckState,
metrics.CannotDeleverageSubaccount,
Copy link
Contributor

Choose a reason for hiding this comment

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

The telemetry.IncrCounter function is being used, but according to the PR summary, the usage of cosmos/cosmos-sdk/telemetry should be replaced with armon/go-metrics. This instance was not updated.

- telemetry.IncrCounter(
+ gometrics.SetGaugeWithLabels(

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.

Suggested change
telemetry.IncrCounter(
1,
types.ModuleName,
metrics.PrepareCheckState,
metrics.CannotDeleverageSubaccount,
gometrics.SetGaugeWithLabels(
1,
types.ModuleName,
metrics.PrepareCheckState,
metrics.CannotDeleverageSubaccount,

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 63f2da5 and e2250b9.
Files ignored due to path filters (2)
  • protocol/go.mod is excluded by: !**/*.mod
  • protocol/go.sum is excluded by: !**/*.sum
Files selected for processing (1)
  • protocol/lib/metrics/lib.go (1 hunks)
Additional comments: 1
protocol/lib/metrics/lib.go (1)
  • 69-71: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [1-48]

The removal of ModuleMeasureSinceWithLabels aligns with the PR's objective to revert changes related to metrics handling. The existing functions provide similar functionality and the TODO comments suggest future improvements for custom calculations.

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 e2250b9 and 71ff821.
Files selected for processing (5)
  • protocol/x/clob/abci.go (3 hunks)
  • protocol/x/clob/keeper/deleveraging.go (8 hunks)
  • protocol/x/clob/keeper/liquidations.go (6 hunks)
  • protocol/x/clob/keeper/mev.go (10 hunks)
  • protocol/x/clob/types/order_id.go (2 hunks)
Files skipped from review as they are similar to previous changes (5)
  • protocol/x/clob/abci.go
  • protocol/x/clob/keeper/deleveraging.go
  • protocol/x/clob/keeper/liquidations.go
  • protocol/x/clob/keeper/mev.go
  • protocol/x/clob/types/order_id.go

@jonfung-dydx jonfung-dydx merged commit 86e50c4 into main Jan 16, 2024
@jonfung-dydx jonfung-dydx deleted the jonfung/revertMetricsChange branch January 16, 2024 22:52
jonfung-dydx added a commit that referenced this pull request Jan 19, 2024
jonfung-dydx added a commit that referenced this pull request Jan 19, 2024
#994)

* Revert "Revert "[CLOB-1014] [CLOB-1004] Unify metrics library, un-modularize … (#967)"

This reverts commit 86e50c4.

* remove jonfung/ build and push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants