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

Backport PR #2535 to release/v1.7 for feat/add-otel-rust #2609

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

hlts2
Copy link
Collaborator

@hlts2 hlts2 commented Sep 11, 2024

Description

Backport: #2535

Related Issue

Versions

  • Vald Version: v1.7.13
  • Go Version: v1.23.0
  • Rust Version: v1.80.0
  • Docker Version: v27.1.1
  • Kubernetes Version: v1.30.3
  • Helm Version: v3.15.3
  • NGT Version: v2.2.4
  • Faiss Version: v1.8.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration module for observability, allowing users to customize settings such as endpoint and attributes.
    • Added macros to simplify telemetry span and metric management, enhancing ease of use for developers.
    • Implemented a core observability module that supports metrics and tracing capabilities using OpenTelemetry.
  • Documentation

    • Updated documentation to include new observability features and usage guidelines.

* feat: add observability crate

Signed-off-by: hlts2 <[email protected]>

* fix: fix crate name

Signed-off-by: hlts2 <[email protected]>

* feat: add module files

Signed-off-by: hlts2 <[email protected]>

* feat: create config

Signed-off-by: hlts2 <[email protected]>

* fix: implement from trait

Signed-off-by: hlts2 <[email protected]>

* feat: add tracer and meter macro

Signed-off-by: hlts2 <[email protected]>

* feat: add license

Signed-off-by: hlts2 <[email protected]>

* fix: use full module path

Signed-off-by: hlts2 <[email protected]>

* fix: add shutdown method

Signed-off-by: hlts2 <[email protected]>

* feat: add build method to crate tracer provider and meter provider

Signed-off-by: hlts2 <[email protected]>

* fix: module path

Signed-off-by: hlts2 <[email protected]>

* fix: add export timeout duration and comment

Signed-off-by: hlts2 <[email protected]>

* feat: update interface

Signed-off-by: hlts2 <[email protected]>

* feat: add endpint configuration to root configuration

Signed-off-by: hlts2 <[email protected]>

* fix: update deps

Signed-off-by: hlts2 <[email protected]>

* fix: small refactor

Signed-off-by: hlts2 <[email protected]>

* fix: deleted build method to create trace and metrics provider

Signed-off-by: hlts2 <[email protected]>

---------

Signed-off-by: hlts2 <[email protected]>
Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Walkthrough

Walkthrough

This pull request introduces a comprehensive observability module for a Rust application, encompassing configuration, macros, and core functionality for metrics and tracing using OpenTelemetry. Key components include a Config struct for settings, macros for instrumentation, and an Observability trait with an implementation that manages metrics and tracing providers. The changes establish a structured approach to observability, allowing for effective monitoring and performance tracking.

Changes

Files Change Summary
rust/libs/observability/src/config.rs Introduced a configuration module with a Config struct containing fields for observability settings. Implemented builder pattern methods for flexible configuration and the Default trait for sensible defaults. Added Tracer and Meter structs with their own configuration options and methods. Implemented From trait for converting Config to OpenTelemetry resource format.
rust/libs/observability/src/lib.rs Established a public interface for the observability module by declaring sub-modules: config, macros, and observability. Included standard licensing information.
rust/libs/observability/src/macros.rs Defined macros for telemetry spans and metrics, including tracer!, ctx_span!, and meter!. Introduced the instrument! macro for creating various instrument types based on InstrumentKind. Utilized the paste crate for dynamic naming of metric functions.
rust/libs/observability/src/observability.rs Implemented the Observability trait and its ObservabilityImpl struct, which manages configuration and optional providers for metrics and tracing. Included methods for initializing observability features and gracefully shutting them down.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Config
    participant ObservabilityImpl
    participant MetricsProvider
    participant TracerProvider

    App->>Config: Create new Config
    App->>ObservabilityImpl: Initialize with Config
    ObservabilityImpl->>MetricsProvider: Setup metrics pipeline
    ObservabilityImpl->>TracerProvider: Setup tracer pipeline
    App->>ObservabilityImpl: Shutdown
    ObservabilityImpl->>MetricsProvider: Flush and shutdown
    ObservabilityImpl->>TracerProvider: Flush and shutdown
Loading

Suggested labels

priority/low, area/internal, size/XXXL


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 97dc524 and 5fb9102.

Files selected for processing (4)
  • rust/libs/observability/src/config.rs (1 hunks)
  • rust/libs/observability/src/lib.rs (1 hunks)
  • rust/libs/observability/src/macros.rs (1 hunks)
  • rust/libs/observability/src/observability.rs (1 hunks)
Additional comments not posted (9)
rust/libs/observability/src/lib.rs (1)

1-19: LGTM!

The code is well-structured and follows Rust's module conventions. The file serves as the library's entry point, exporting the necessary modules.

rust/libs/observability/src/config.rs (1)

1-142: LGTM!

The configuration code is well-structured and provides a fluent API for customization. The use of the builder pattern and the From trait implementation enhances usability and integration with the opentelemetry library.

rust/libs/observability/src/macros.rs (1)

1-150: LGTM!

The instrumentation macros provide a high-level and expressive API for tracing and metrics. They abstract away the complexity of the opentelemetry library and offer a concise way to create spans and metric instruments. The use of the paste crate for dynamic method name generation is a clever approach.

rust/libs/observability/src/observability.rs (6)

1-15: LGTM!

The Apache License 2.0 header is correct and consistent with the rest of the codebase.


29-31: LGTM!

The Observability trait provides a clean interface for the observability functionality.


33-37: LGTM!

The ObservabilityImpl struct encapsulates the necessary components for the observability functionality.


40-94: LGTM!

The new method correctly initializes the ObservabilityImpl struct based on the provided configuration. It sets up the meter provider and tracer provider using the opentelemetry_otlp crate and sets the global meter and tracer providers.


96-98: LGTM!

The config method provides a simple getter for the Config field of the ObservabilityImpl struct.


101-124: LGTM!

The Observability trait implementation for the ObservabilityImpl struct correctly defines the shutdown method based on the configuration. It flushes and shuts down the meter and tracer providers using their respective force_flush and shutdown methods.


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

@hlts2 hlts2 requested a review from vankichi September 11, 2024 03:44
@hlts2 hlts2 self-assigned this Sep 11, 2024
@hlts2 hlts2 requested a review from kpango September 11, 2024 03:50
@vdaas-ci
Copy link
Collaborator

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

@vankichi vankichi merged commit 626873f into release/v1.7 Sep 11, 2024
24 of 25 checks passed
@vankichi vankichi deleted the backport/add-otel-rust branch September 11, 2024 04:31
@kpango kpango mentioned this pull request Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants