Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

feat: API for writing metrics to InfluxDB file#23

Merged
ddd-mtl merged 2 commits intomainfrom
file-meter-provider
Aug 8, 2025
Merged

feat: API for writing metrics to InfluxDB file#23
ddd-mtl merged 2 commits intomainfrom
file-meter-provider

Conversation

@ddd-mtl
Copy link
Copy Markdown
Contributor

@ddd-mtl ddd-mtl commented Aug 7, 2025

Adds high level function influxive_file_meter_provider() with test and example.

Final PR for #17

Summary by CodeRabbit

  • New Features

    • Added support for writing metrics directly to a local InfluxDB line protocol file.
    • Introduced a new example in the documentation demonstrating file-based metric recording.
  • Documentation

    • Expanded the README with an example on writing metrics to a file.
  • Tests

    • Added a test to verify that metrics are correctly written to a file.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 7, 2025

Walkthrough

A new file-based metrics provider has been introduced to the influxive crate. This includes a public function to create a meter provider that writes metrics to a file, updated documentation with usage examples, and an asynchronous test verifying that metrics are correctly written to a file.

Changes

Cohort / File(s) Change Summary
README Documentation Update
crates/influxive/README.md
Added an example section demonstrating how to configure and use a file-based meter provider for writing metrics to a local InfluxDB line protocol file.
Public API Addition
crates/influxive/src/lib.rs
Introduced a new public function influxive_file_meter_provider for creating a file-based meter provider, with accompanying documentation and usage example. No existing logic was altered.
File-based Provider Test
crates/influxive/src/test.rs
Added an asynchronous test that verifies a metric value is correctly written to a file using the new file-based meter provider.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FileMeterProvider
    participant File
    User->>FileMeterProvider: Create with file path
    User->>FileMeterProvider: Register globally
    User->>FileMeterProvider: Create metric and record value
    FileMeterProvider->>File: Write metric value in InfluxDB line protocol
    User->>File: Read and verify metric data
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Output to disk #20: Implements the underlying file backend and factory in crates/influxive-writer that is directly used by the new file-based meter provider function.

Suggested reviewers

  • ThetaSinner

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch file-meter-provider

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

@ddd-mtl ddd-mtl marked this pull request as ready for review August 7, 2025 17:32
Copy link
Copy Markdown

@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 (3)
crates/influxive/src/test.rs (2)

29-29: Consider making the sleep duration configurable or use polling.

The hard-coded 200ms sleep might be insufficient in slower CI environments or cause unnecessary delays in fast environments.

Consider using a polling approach instead:

-    // Wait for the metric to be written
-    tokio::time::sleep(std::time::Duration::from_millis(200)).await;
+    // Wait for the metric to be written with polling
+    let mut attempts = 0;
+    while attempts < 20 && !test_path.exists() {
+        tokio::time::sleep(std::time::Duration::from_millis(10)).await;
+        attempts += 1;
+    }

37-39: Strengthen the assertion for line protocol format validation.

The current parsing assumes a specific space-separated format but could be more robust in validating the InfluxDB line protocol structure.

Consider a more comprehensive validation:

-    let split = line.split(' ').collect::<Vec<&str>>();
-    assert_eq!(split[0], "my.metric");
-    assert!(split[1].contains(&"3.14"));
+    // Validate InfluxDB line protocol format: measurement[,tags] fields [timestamp]
+    assert!(line.starts_with("my.metric"));
+    assert!(line.contains("value=3.14"));
+    // Could also validate timestamp presence if needed
crates/influxive/src/lib.rs (1)

142-143: Consider documenting the parameter usage more explicitly.

While the comment explains that host/bucket/token are not needed, it might be helpful to document this behavior more explicitly in the function's doc comment.

Consider enhancing the documentation:

 /// Create an opentelemetry_api MeterProvider ready to provide metrics
-/// to a file on disk.
+/// to a file on disk. Note that host, bucket, and token authentication
+/// parameters are not required for file-based writers.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bdbc00 and 8ac3e7d.

📒 Files selected for processing (3)
  • crates/influxive/README.md (1 hunks)
  • crates/influxive/src/lib.rs (2 hunks)
  • crates/influxive/src/test.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/influxive/src/test.rs (3)
crates/influxive/src/lib.rs (1)
  • influxive_file_meter_provider (138-145)
crates/influxive-writer/src/lib.rs (1)
  • create_with_influx_file (284-290)
crates/influxive-writer/src/test.rs (1)
  • reader (218-218)
🔇 Additional comments (5)
crates/influxive/README.md (1)

62-85: LGTM! Well-structured documentation example.

The new example section follows the established pattern of existing examples and clearly demonstrates the usage of the new file-based meter provider functionality. The code is consistent with the API design and includes a helpful note about reading the resulting data.

crates/influxive/src/test.rs (1)

4-40: Good test coverage for the new functionality.

The test effectively validates the core functionality of the file meter provider by creating a metric, recording a value, and verifying the output file contents. The use of temporary directories ensures proper cleanup.

crates/influxive/src/lib.rs (3)

62-89: LGTM! Comprehensive documentation example.

The documentation example is well-structured, follows the established pattern, and includes proper cleanup. The example effectively demonstrates the new file-based functionality.


136-145: Clean implementation that follows established patterns.

The function design is consistent with existing APIs and appropriately reuses the InfluxiveWriter::with_token_auth method. The approach of using empty strings for unused parameters maintains API consistency while serving the file-based use case.


147-148: Good addition of test module.

The test module inclusion enables proper testing of the new functionality.

@cocogitto-bot
Copy link
Copy Markdown

cocogitto-bot Bot commented Aug 7, 2025

❌ Found 1 compliant commit and 1 non-compliant commits in 8ac3e7d...6ffdc34.

Commit 6ffdc34 by @ddd-mtl is not conform to the conventional commit specification :

  • message: Merge branch 'main' into file-meter-provider
  • cause:
    Missing commit type separator `:`
    
    Caused by:
         --> 1:6
          |
        1 | Merge branch 'main' into file-meter-provider
          |      ^---
          |
          = expected scope or type_separator
    

@ddd-mtl ddd-mtl requested a review from a team August 7, 2025 18:56
@ddd-mtl ddd-mtl merged commit 8aed719 into main Aug 8, 2025
7 of 8 checks passed
@ddd-mtl ddd-mtl deleted the file-meter-provider branch August 8, 2025 13:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants