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

feat: bridgecall metrics #600

Merged
merged 1 commit into from
Jul 25, 2024
Merged

feat: bridgecall metrics #600

merged 1 commit into from
Jul 25, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Jul 25, 2024

Summary by CodeRabbit

  • New Features
    • Introduced constants for telemetry labels to standardize logging and enhance readability.
    • Added telemetry metrics for monitoring financial tokens and coins, improving tracking capabilities.
    • Enhanced telemetry tracking for bridge call events, providing better insights into operations.
    • Implemented telemetry tracking for outgoing bridge calls, improving analytics of transactions.
    • Established a new set of constants for metrics related to cross-chain operations, aiding in observability.

Copy link

coderabbitai bot commented Jul 25, 2024

Walkthrough

The recent changes enhance telemetry capabilities across various components of the system by introducing structured metric tracking for bridge calls and outgoing transactions. New constants and functions improve consistency and observability in logging, fostering easier debugging. The modifications facilitate detailed monitoring by ensuring metrics are only recorded during relevant operations, thus promoting a more robust telemetry framework.

Changes

File Path Summary of Changes
telemetry/label.go Added constants for telemetry labels to standardize logging and enhance code maintainability.
telemetry/metrics.go Introduced functions to manage telemetry metrics for financial tokens, ensuring values stay within limits.
x/crosschain/keeper/bridge_call_in.go Enhanced telemetry tracking for bridge call events, logging metrics outside check transaction states.
x/crosschain/keeper/bridge_call_out.go Added telemetry metrics for outgoing bridge calls, capturing detailed transaction information.
x/crosschain/keeper/outgoing_pool.go Implemented telemetry tracking for outgoing transactions, improving transaction observability.
x/crosschain/types/metrics.go Defined constants for metrics related to cross-chain operations, facilitating consistent metric usage.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Keeper
    participant Telemetry

    User->>Keeper: Initiate Bridge Call
    Keeper->>Telemetry: Check ctx.IsCheckTx()
    alt Not CheckTx
        Keeper->>Telemetry: Log Bridge Call Metrics
    end
    Telemetry-->>Keeper: Return Metric Status
    Keeper-->>User: Complete Bridge Call
Loading

🐰 In the meadow, where the metrics grow,
A rabbit hops with data in tow.
With labels and logs, it leaps with glee,
Celebrating changes, as bright as can be!
"More insights for us, what a treat!"
Hopping along, our metrics are sweet! 🌼📊


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

Copy link

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

Caution

Inline review comments failed to post

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2ad7522 and 30fcb3a.

Files selected for processing (6)
  • telemetry/label.go (1 hunks)
  • telemetry/metrics.go (1 hunks)
  • x/crosschain/keeper/bridge_call_in.go (3 hunks)
  • x/crosschain/keeper/bridge_call_out.go (2 hunks)
  • x/crosschain/keeper/outgoing_pool.go (2 hunks)
  • x/crosschain/types/metrics.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • telemetry/label.go
Additional comments not posted (15)
x/crosschain/types/metrics.go (2)

3-7: LGTM!

The constants for metric keys are well-named and follow best practices.


9-13: LGTM!

The constants for metric labels are well-named and follow best practices.

telemetry/metrics.go (2)

24-26: LGTM!

The function is a straightforward wrapper around SetGaugeLabelsWithToken and appears correct.


28-31: LGTM!

The function is a straightforward loop that calls SetGaugeLabelsWithCoin for each coin and appears correct.

x/crosschain/keeper/bridge_call_in.go (5)

Line range hint 77-91: LGTM!

The function correctly handles minting and unlocking coins. Ensure that the bank keeper and ERC20 keeper are correctly integrated.


Line range hint 117-139: LGTM!

The function correctly handles token transfers and conversion. Ensure that the bank keeper and ERC20 keeper are correctly integrated.


Line range hint 141-160: LGTM!

The function correctly converts coins to bridge call tokens. Ensure that the ERC20 keeper is correctly integrated.


39-52: LGTM! Verify telemetry integration.

The telemetry integration appears correct. Ensure that the labels and metrics are correctly tracked.

Verification successful

The telemetry integration in the BridgeCallHandler function appears correct. The labels and metrics are properly tracked. Here are the relevant locations in the codebase:

  • x/crosschain/keeper/bridge_call_in.go: Implementation of BridgeCallHandler.
  • x/crosschain/keeper/attestation_handler.go: Invocation of BridgeCallHandler.
  • x/crosschain/keeper/bridge_call_in_test.go: Tests for BridgeCallHandler.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify telemetry integration for `BridgeCallHandler`.

# Test: Search for the function usage. Expect: Correct telemetry labels and metrics.
rg --type go -A 10 $'BridgeCallHandler'

Length of output: 3418


94-100: LGTM! Verify telemetry integration.

The telemetry integration appears correct. Ensure that the labels and metrics are correctly tracked.

Verification successful

Let's verify the telemetry integration by checking the definitions of types.MetricsKeyBridgeCallIn and types.MetricsLabelModule, and ensure they are correctly used in the code.


Telemetry integration verified.

The telemetry integration in the BridgeCallTransferAndCallEvm function is correct. The labels and metrics are appropriately defined and used.

  • MetricsKeyBridgeCallIn is defined as "bridge_call_in".
  • MetricsLabelModule is defined as "module".
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify telemetry integration for `BridgeCallTransferAndCallEvm`.

# Test: Search for the function usage. Expect: Correct telemetry labels and metrics.
rg --type go -A 10 $'BridgeCallTransferAndCallEvm'

Length of output: 1913


Script:

#!/bin/bash
# Description: Verify telemetry labels and metrics definitions.

# Search for the definition of MetricsKeyBridgeCallIn
rg --type go 'MetricsKeyBridgeCallIn'

# Search for the definition of MetricsLabelModule
rg --type go 'MetricsLabelModule'

Length of output: 1016

x/crosschain/keeper/bridge_call_out.go (3)

64-64: Ensure context check is necessary.

The context check !ctx.IsCheckTx() ensures that telemetry tracking is only performed during actual transactions, not during checks. This is a good practice to avoid unnecessary telemetry during transaction validation phases.


65-73: Telemetry tracking for tokens.

The code correctly sets gauge labels for each token involved in the outgoing bridge call. This helps in detailed monitoring and analytics.


74-83: Increment counter with labels.

The code increments a counter with specific labels indicating the module, sender, refund address, recipient address, and token labels. This is a good practice for detailed telemetry.

x/crosschain/keeper/outgoing_pool.go (3)

56-56: Ensure context check is necessary.

The context check !ctx.IsCheckTx() ensures that telemetry tracking is only performed during actual transactions, not during checks. This is a good practice to avoid unnecessary telemetry during transaction validation phases.


57-61: Telemetry tracking for outgoing amount.

The code correctly sets gauge labels for the outgoing amount. This helps in detailed monitoring and analytics.


63-72: Increment counter with labels.

The code increments a counter with specific labels indicating the module, sender, receiver, and token denomination. This is a good practice for detailed telemetry.

Comments failed to post (1)
telemetry/metrics.go

15-22: Handle potential errors in float32 conversion.

The conversion to float32 should handle potential errors to avoid unexpected behavior.

-	amountFloat32, _ := new(big.Float).SetInt(amount).Float32()
+	amountFloat32, accuracy := new(big.Float).SetInt(amount).Float32()
+	if accuracy != big.Exact {
+		return
+	}
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.

func SetGaugeLabelsWithToken(keys []string, token string, amount *big.Int, labels ...metrics.Label) {
	if amount.Cmp(maxFloat32) == 1 {
		return
	}
	amountFloat32, accuracy := new(big.Float).SetInt(amount).Float32()
	if accuracy != big.Exact {
		return
	}
	telemetry.SetGaugeWithLabels(append(keys, token), amountFloat32,
		append(labels, telemetry.NewLabel(LabelToken, token)))
}

@zakir-code zakir-code merged commit 69126e6 into main Jul 25, 2024
9 checks passed
@zakir-code zakir-code deleted the nulnut/bridgecall-metrics branch July 25, 2024 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants