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: obsy prometheus exporter #579

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

mojtaba-esk
Copy link
Member

@mojtaba-esk mojtaba-esk commented Nov 14, 2024

There was a bug that I was trying to find and the culprit is in the obsy sidecar. It prevented to set Prometheus as an exporter in the Otel collector. This PR proposes a fix for that.

Summary by CodeRabbit

  • New Features

    • Introduced a new telemetry configuration feature for enhanced observability.
    • Added support for Prometheus exporter configuration validation.
  • Bug Fixes

    • Improved logic for creating the Prometheus exporter based on updated configuration checks.
  • Documentation

    • Updated documentation to reflect changes in telemetry and exporter configuration handling.

@mojtaba-esk mojtaba-esk added the bug Something isn't working label Nov 14, 2024
@mojtaba-esk mojtaba-esk requested a review from a team November 14, 2024 11:07
@mojtaba-esk mojtaba-esk self-assigned this Nov 14, 2024
Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

Walkthrough

The changes introduce a new Telemetry field in the Service struct within the OTelConfig type, which holds telemetry configuration details. This includes a Metrics field that specifies Address and Level. The createService method has been updated to initialize this new field. Additionally, the logic for creating the Prometheus exporter has been modified to check for a non-empty prometheusExporterEndpoint instead of a non-zero port, affecting how exporters are handled in the metrics and traces preparation methods.

Changes

File Path Change Summary
pkg/sidecars/observability/otel.go - Added Telemetry struct to OTelConfig with MetricsTelemetry fields.
- Updated createService method to initialize Telemetry with default values.
- Modified exporter creation logic to check for non-empty prometheusExporterEndpoint.
- Updated prepareMetricsForServicePipeline and prepareTracesForServicePipeline methods to append prometheusExporterName based on new conditions.

Possibly related PRs

  • fix: obsy tests #578: The changes in this PR involve modifications to the prepareMetricsForServicePipeline and prepareTracesForServicePipeline methods in pkg/sidecars/observability/otel.go, which are also updated in the main PR to handle the new Telemetry field and the logic for exporters.

Suggested reviewers

  • sysrex
  • tty47
  • smuu
  • MSevey

🐇 In the meadow where bunnies play,
A new Telemetry brightens the day.
With metrics in hand, we hop with glee,
Exporters now dance, as happy as can be!
So let’s celebrate this joyful change,
In our code, a new path we’ll arrange! 🌼


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.

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

🧹 Outside diff range and nitpick comments (2)
pkg/sidecars/observability/otel.go (2)

Line range hint 193-204: LGTM! Consider adding documentation for the Telemetry struct.

The new Telemetry and MetricsTelemetry structs are well-defined. The Level field's comment is helpful, but consider adding godoc comments for the structs themselves to explain their purpose and usage.

Add documentation like:

// Telemetry defines the configuration for OpenTelemetry's own telemetry data
type Telemetry struct {
    Metrics MetricsTelemetry `yaml:"metrics,omitempty"`
}

// MetricsTelemetry configures how OpenTelemetry's own metrics are exposed
type MetricsTelemetry struct {
    Address string `yaml:"address,omitempty"` // The address where telemetry metrics are exposed
    Level   string `yaml:"level,omitempty"`   // Options are basic, normal, detailed
}

Line range hint 437-452: LGTM! Consider making telemetry configuration more flexible.

The telemetry configuration is properly initialized with default values. However, consider making the address and level configurable through obsyConfig instead of using hardcoded constants.

Consider modifying the code to allow configuration:

 telemetry := Telemetry{
     Metrics: MetricsTelemetry{
-        Address: internalTelemetryEndpoint,
-        Level:   basicTelemetryLevel,
+        Address: o.obsyConfig.telemetryAddress,
+        Level:   o.obsyConfig.telemetryLevel,
     },
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c730164 and b31395f.

📒 Files selected for processing (1)
  • pkg/sidecars/observability/otel.go (1 hunks)
🔇 Additional comments (2)
pkg/sidecars/observability/otel.go (2)

346-349: LGTM! Improved Prometheus exporter configuration.

The change from checking port to checking endpoint is more flexible and consistent with how other exporters are configured. This fix properly addresses the PR objective of enabling Prometheus as an exporter.


346-349: Verify backward compatibility for existing users.

The change from port-based to endpoint-based configuration for Prometheus exporter might affect existing users. Please ensure:

  1. Documentation is updated to reflect this change
  2. Migration guide is provided if needed
  3. Default values are handled appropriately

Also applies to: 437-452

✅ Verification successful

No breaking changes detected in Prometheus configuration

The codebase shows a clean transition:

  • The old prometheusEndpointPort is still maintained alongside the new prometheusExporterEndpoint
  • Both configurations are handled independently with proper null checks
  • Test files demonstrate proper default values and configuration options
  • The changes are additive rather than replacing existing functionality

No documentation updates are required as this appears to be a new feature addition rather than a breaking change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing usages of prometheusEndpointPort to identify potential breaking changes
rg "prometheusEndpointPort" --type go

# Search for documentation files that might need updates
fd -e md -e rst -e txt | xargs rg -l "prometheus.*port"

Length of output: 756


Script:

#!/bin/bash
# Check for the new prometheusExporterEndpoint configuration
rg "prometheusExporterEndpoint" --type go -A 2

# Check for any configuration or setup examples in documentation
fd . -e md -e yaml -e yml | xargs rg -l "prometheus"

# Look for test files to understand default behavior
rg "createPrometheusExporter|NewObservability" --type go -A 5

Length of output: 2389

@mojtaba-esk mojtaba-esk merged commit 23bffd9 into main Nov 14, 2024
18 checks passed
@mojtaba-esk mojtaba-esk deleted the mojtaba/fix-obsy-prometheus-exporter branch November 14, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants