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/telemetry #810

Merged
merged 3 commits into from
Nov 11, 2024
Merged

Feat/telemetry #810

merged 3 commits into from
Nov 11, 2024

Conversation

ccamel
Copy link
Member

@ccamel ccamel commented Nov 10, 2024

Adds telemetry features to the logic module, enabling tracking of predicate call counts and execution durations. Primarily intended for statistical data collection and limited to the node.

Ex:

# HELP logic_vm_predicate logic_vm_predicate
# TYPE logic_vm_predicate counter
logic_vm_predicate{predicate="chain_id/1"} 6
logic_vm_predicate{predicate="op/3"} 51
 HELP logic_vm_predicate_chain_id_1 logic_vm_predicate_chain_id_1
# TYPE logic_vm_predicate_chain_id_1 summary
logic_vm_predicate_chain_id_1{quantile="0.5"} 0.004000000189989805
logic_vm_predicate_chain_id_1{quantile="0.9"} 0.004999999888241291
logic_vm_predicate_chain_id_1{quantile="0.99"} 0.004999999888241291
logic_vm_predicate_chain_id_1_sum 0.06899999966844916
logic_vm_predicate_chain_id_1_count 6
# HELP logic_vm_predicate_op_3 logic_vm_predicate_op_3
# TYPE logic_vm_predicate_op_3 summary
logic_vm_predicate_op_3{quantile="0.5"} 0.004999999888241291
logic_vm_predicate_op_3{quantile="0.9"} 0.01600000075995922
logic_vm_predicate_op_3{quantile="0.99"} 0.210999995470047
logic_vm_predicate_op_3_sum 0.674000000115484
logic_vm_predicate_op_3_count 51

Summary by CodeRabbit

  • New Features

    • Introduced telemetry tracking for predicate calls, including counters and duration measurements.
    • Added new utility for converting operands to string representation for better predicate handling.
  • Bug Fixes

    • Improved logic for checking registered predicates, streamlining permission checks.
  • Refactor

    • Simplified predicate handling logic by replacing the previous interface with direct string conversion.

@ccamel ccamel self-assigned this Nov 10, 2024
Copy link
Contributor

coderabbitai bot commented Nov 10, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces significant enhancements to the keeper package, specifically within the interpreter.go and the newly created metrics.go. It adds telemetry hooks to monitor predicate call counts and durations, modifies existing predicate handling logic for improved efficiency, and introduces a utility function for operand stringification. The changes aim to streamline the interpreter's functionality while maintaining existing gas consumption logic.

Changes

File Path Change Summary
x/logic/keeper/interpreter.go - Added telemetry hooks: telemetryPredicateCallCounterHookFn, telemetryPredicateDurationHookFn.
- Updated whitelistBlacklistHookFn and gasMeterHookFn to use stringifyOperand for predicate handling.
x/logic/keeper/metrics.go - Introduced new file with telemetry functions: telemetryPredicateCallCounterHookFn, telemetryPredicateDurationHookFn, and utility function stringifyOperand.

Possibly related PRs

  • Fix/predicate gas consumption #756: The changes in this PR involve the gasMeterHookFn and whitelistBlacklistHookFn, which are directly related to the modifications made in the main PR regarding gas consumption tracking and predicate handling.

Suggested reviewers

  • amimart
  • bdeneux

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

codecov bot commented Nov 10, 2024

Codecov Report

Attention: Patch coverage is 89.65517% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
x/logic/keeper/metrics.go 86.36% 4 Missing and 2 partials ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #810      +/-   ##
==========================================
+ Coverage   42.73%   43.04%   +0.30%     
==========================================
  Files         111      112       +1     
  Lines        6273     6317      +44     
==========================================
+ Hits         2681     2719      +38     
- Misses       3468     3472       +4     
- Partials      124      126       +2     
Files with missing lines Coverage Δ
x/logic/keeper/interpreter.go 92.02% <100.00%> (ø)
x/logic/keeper/metrics.go 86.36% <86.36%> (ø)

@ccamel ccamel marked this pull request as ready for review November 10, 2024 14:01
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: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d0722b2 and f550a53.

📒 Files selected for processing (2)
  • x/logic/keeper/interpreter.go (3 hunks)
  • x/logic/keeper/metrics.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
x/logic/keeper/interpreter.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/logic/keeper/metrics.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

🪛 GitHub Check: codecov/patch
x/logic/keeper/metrics.go

[warning] 30-31: x/logic/keeper/metrics.go#L30-L31
Added lines #L30 - L31 were not covered by tests


[warning] 64-65: x/logic/keeper/metrics.go#L64-L65
Added lines #L64 - L65 were not covered by tests


[warning] 79-79: x/logic/keeper/metrics.go#L79
Added line #L79 was not covered by tests

🔇 Additional comments (6)
x/logic/keeper/metrics.go (2)

3-20: LGTM! Well-structured imports and constants.

The imports are properly organized and the metric key structure provides a clear hierarchical naming scheme.


22-47: Add test coverage for error paths and enhance error handling.

While the implementation is solid, there are a few areas for improvement:

  1. The error path when stringifyOperand fails lacks test coverage
  2. Consider adding debug logging for failed predicate conversions to aid troubleshooting
 func telemetryPredicateCallCounterHookFn() engine.HookFunc {
     return func(opcode engine.Opcode, operand engine.Term, _ *engine.Env) error {
         if opcode != engine.OpCall {
             return nil
         }
 
         predicate, ok := stringifyOperand(operand)
         if !ok {
+            // Log failed conversion for debugging
+            logger.Debug("failed to stringify predicate operand", "operand", fmt.Sprintf("%+v", operand))
             return nil
         }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 30-31: x/logic/keeper/metrics.go#L30-L31
Added lines #L30 - L31 were not covered by tests

x/logic/keeper/interpreter.go (4)

108-109: Addition of Telemetry Hooks Enhances Monitoring

The inclusion of telemetryPredicateCallCounterHookFn() and telemetryPredicateDurationHookFn() effectively adds telemetry capabilities for tracking predicate calls and execution durations, aligning with the PR's objective to improve monitoring in the logic module.


145-147: Confirm Intentional Bypass for Unregistered Predicates

When a predicate is not registered (!interpreter.IsRegistered(predicate)), the function returns nil, allowing execution to proceed. Please confirm that this behavior is intentional and does not introduce security risks by permitting unregistered predicates to bypass permission checks.


149-155: Proper Permission Error Handling for Disallowed Predicates

The implementation correctly returns a PermissionError when a predicate is not found in the allowed list, ensuring that unauthorized predicates are appropriately blocked. This aligns with best practices for access control.


172-174: Consistent Use of stringifyOperand in gasMeterHookFn

Utilizing stringifyOperand in gasMeterHookFn aligns predicate handling with whitelistBlacklistHookFn, enhancing code consistency. Ensure that stringifyOperand adequately handles all operand types to avoid potential syntax errors.

x/logic/keeper/metrics.go Show resolved Hide resolved
x/logic/keeper/metrics.go Show resolved Hide resolved
x/logic/keeper/interpreter.go Show resolved Hide resolved
@ccamel
Copy link
Member Author

ccamel commented Nov 10, 2024

@coderabbitai resolve

Copy link
Contributor

coderabbitai bot commented Nov 10, 2024

✅ Actions performed

Comments resolved and changes approved.

@ccamel ccamel merged commit f6c1d1b into main Nov 11, 2024
21 checks passed
@ccamel ccamel deleted the feat/telemetry branch November 11, 2024 10:28
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.

1 participant