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

fix(server/v2/api/telemetry): avoid panic due to no telemetry address #23022

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

mmsqe
Copy link
Contributor

@mmsqe mmsqe commented Dec 20, 2024

Description

Closes #23021


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Enhanced telemetry configuration options for improved server setup.
    • Introduced a telemetry server with a dedicated port for better monitoring in the testnet setup.
  • Bug Fixes

    • Adjusted server initialization to incorporate telemetry server correctly.
  • Documentation

    • Updated comments to reflect new telemetry functionalities and configuration options.

@mmsqe mmsqe requested review from kocubinski, julienrbrt, a team and hieuvubk as code owners December 20, 2024 00:14
Copy link
Contributor

coderabbitai bot commented Dec 20, 2024

📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the telemetry configuration system in the Cosmos SDK. It adds new configuration options for the telemetry server, allowing more flexible initialization and control. The changes include creating a new configuration option type, updating the server constructor to accept configuration options, and modifying the testnet command to integrate telemetry server initialization with a default port.

Changes

File Change Summary
server/v2/api/telemetry/config.go Added CfgOption type and two new functions: OverwriteDefaultConfig() and Disable() for flexible telemetry configuration
server/v2/api/telemetry/server.go Updated Server struct with cfgOptions field, modified New() method to accept configuration options, added NewWithConfigOptions() method
simapp/v2/simdv2/cmd/testnet.go Added telemetry import, introduced telemetryPort constant, updated server initialization to include telemetry server

Sequence Diagram

sequenceDiagram
    participant User
    participant TelemetryConfig
    participant TelemetryServer
    
    User->>TelemetryConfig: Create configuration options
    User->>TelemetryServer: Initialize with config options
    TelemetryServer->>TelemetryConfig: Apply configuration
    TelemetryServer-->>User: Return configured server
Loading

Possibly related PRs

Suggested labels

C:Store

Suggested reviewers

  • kocubinski
  • julienrbrt
  • tac0turtle

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@github-actions github-actions bot added C:server/v2 Issues related to server/v2 C:server/v2 api labels Dec 20, 2024
@julienrbrt julienrbrt changed the title feat(systemtests): avoid panic due to no telemetry address fix(server/v2/api/telemetry): avoid panic due to no telemetry address Dec 20, 2024
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

utACK, but i still don't get why isn't failing on my machine 😅
Adding the backport label for the simapp/v2 changes

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Dec 20, 2024
@mmsqe
Copy link
Contributor Author

mmsqe commented Dec 20, 2024

utACK, but i still don't get why isn't failing on my machine 😅 Adding the backport label for the simapp/v2 changes

maybe try TestValidatorDoubleSign, when add a new node

@julienrbrt
Copy link
Member

Yes, thanks! I can reproduce, COSMOS_BUILD_OPTIONS was unset from my bash profile it seems.

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

🧹 Nitpick comments (5)
simapp/v2/simdv2/cmd/testnet.go (3)

187-191: Consider short comments explaining these port constants.
Adding these port constants is a beneficial step for clarity. It might be helpful to add short inline comments describing each port’s purpose, especially for new contributors.


202-202: Check if telemetry configuration should be customizable.
Calling telemetry.DefaultConfig() is straightforward; however, if the testnet environment needs custom telemetry settings (e.g., enable/disable, different address), consider making them configurable via command flags, similar to the other components (gRPC, REST).


227-231: Recommended to validate user-input address before assigning.
This code sets a local IP address with a port offset. You might consider verifying whether the resulting address is valid, especially when the user sets a custom address, to prevent subtle errors.

server/v2/api/telemetry/server.go (1)

87-93: Consider caching the final merged configuration.
When Config() is called repeatedly, you are re-building a new default config each time. You might store that merged config in s.config after applying cfgOptions to avoid reapplying them on each call.

server/v2/api/telemetry/config.go (1)

62-78: Enable advanced customization through CfgOption.
These helper functions (OverwriteDefaultConfig and Disable) nicely separate default setting and dynamic overrides. One minor suggestion: if the user calls Disable(), consider setting “Address” to an empty string or adding a note that the port remains allocated even when telemetry is disabled.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f5c3d8 and 3841c19.

📒 Files selected for processing (3)
  • server/v2/api/telemetry/config.go (1 hunks)
  • server/v2/api/telemetry/server.go (3 hunks)
  • simapp/v2/simdv2/cmd/testnet.go (5 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
server/v2/api/telemetry/config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/simdv2/cmd/testnet.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/api/telemetry/server.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🔇 Additional comments (5)
simapp/v2/simdv2/cmd/testnet.go (2)

25-25: Good use of the telemetry import.
The addition of "telemetry" import is aligned with the broader server configurability changes. Ensure that all references to this import are indeed necessary and used.


367-368: Telemetry server integration looks consistent.
You properly configured telemetry as one of the components in “serverv2.NewServer”. Ensure that the rest of the stack can gracefully handle cases when the telemetry server fails to start or is disabled.

server/v2/api/telemetry/server.go (3)

24-28: Well-structured fields in the Server struct.
The introduction of cfgOptions provides a flexible approach to supply configuration overrides. This design choice aligns well with the rest of the server’s modular approach.


Line range hint 32-41: Ensure consistent error handling and concurrency.
The code sets srv.cfgOptions but does not apply them if the server’s config is already populated. Double-check concurrency scenarios or repeated calls to New() from different goroutines are managed safely, especially if server creation is invoked dynamically.


71-79: Good approach to partial server creation for config manipulation.
The “NewWithConfigOptions” method is handy for retrieving and customizing the telemetry configuration without fully starting the server. Documenting that it’s not fully operational should help reduce confusion.

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

🧹 Nitpick comments (1)
server/v2/api/telemetry/config.go (1)

66-71: Consider adding validation for the new configuration

While the implementation is correct, consider adding validation to ensure the new configuration meets minimum requirements.

 func OverwriteDefaultConfig(newCfg *Config) CfgOption {
 	return func(cfg *Config) {
+		if newCfg == nil {
+			return
+		}
 		*cfg = *newCfg
 	}
 }
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f5c3d8 and 3841c19.

📒 Files selected for processing (3)
  • server/v2/api/telemetry/config.go (1 hunks)
  • server/v2/api/telemetry/server.go (3 hunks)
  • simapp/v2/simdv2/cmd/testnet.go (5 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
server/v2/api/telemetry/config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/simdv2/cmd/testnet.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/api/telemetry/server.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🔇 Additional comments (9)
server/v2/api/telemetry/server.go (4)

24-28: LGTM: Good addition of configuration options

The addition of cfgOptions field to the Server struct enables flexible configuration management.


Line range hint 32-41: LGTM: Constructor properly handles configuration options

The constructor correctly accepts and assigns configuration options while maintaining backward compatibility.


71-78: LGTM: Well-documented config-only constructor

The function is well-documented about its limitations and provides a clean way to create a server instance for configuration purposes only.


86-93: LGTM: Robust configuration handling

The method properly handles nil config cases and correctly applies configuration options, effectively preventing panics due to missing telemetry address.

server/v2/api/telemetry/config.go (2)

63-64: LGTM: Well-defined configuration option type

The CfgOption type provides a type-safe way to modify configurations.


73-78: LGTM: Clean implementation of telemetry disable function

The function provides a simple way to disable telemetry functionality.

simapp/v2/simdv2/cmd/testnet.go (3)

187-191: LGTM: Well-organized port definitions

The telemetry port is properly defined alongside other service ports.


228-231: LGTM: Proper telemetry configuration for single machine setup

The telemetry configuration correctly handles port offsets for multiple instances on a single machine.


367-368: LGTM: Clean integration of telemetry server

The telemetry server is properly initialized and integrated with other server components.

@julienrbrt julienrbrt mentioned this pull request Dec 20, 2024
12 tasks
@julienrbrt julienrbrt added this pull request to the merge queue Dec 20, 2024
Merged via the queue into cosmos:main with commit 422be70 Dec 20, 2024
79 of 87 checks passed
mergify bot pushed a commit that referenced this pull request Dec 20, 2024
…#23022)

(cherry picked from commit 422be70)

# Conflicts:
#	server/v2/api/telemetry/config.go
#	server/v2/api/telemetry/server.go
julienrbrt added a commit that referenced this pull request Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:server/v2 api C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: panic in systemtest with v2 binary
3 participants