Skip to content

refactor: specialized flatten happens at the same semantic location #1177

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

Merged
merged 8 commits into from
Feb 18, 2025

Conversation

de-sh
Copy link
Contributor

@de-sh de-sh commented Feb 9, 2025

Fixes #XXXX.

Description


This PR has:

  • been tested to ensure log ingestion and log query works.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

Summary by CodeRabbit

  • New Features

    • Enhanced the telemetry ingestion process by integrating log, metric, and trace data into a unified workflow, improving performance and reliability.
  • Refactor

    • Simplified the data processing pipeline to reduce redundancy while preserving robust error handling, maintaining a smooth and efficient operational flow for telemetry data ingestion.
    • Updated the visibility of the push_logs function to private, streamlining the function's access.

Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

The changes simplify the ingestion process for OpenTelemetry data by consolidating the logic used in handling OTEL logs, metrics, and traces. In the HTTP handler, custom deserialization and flattening have been removed and replaced with a unified call to flatten_and_push_logs. In the utility module, the new function now distinguishes between different OTEL log sources—handling each with its respective flattening function—while updating the visibility of push_logs to private and adjusting necessary imports.

Changes

File(s) Summary of Changes
src/handlers/http/ingest.rs Removed custom deserialization/flattening for OTEL LogsData, MetricsData, and TracesData; replaced individual logic with a unified call to flatten_and_push_logs.
src/handlers/http/modal/utils/ingest_utils.rs Enhanced flatten_and_push_logs to handle OTEL logs, metrics, and traces with dedicated flatten functions; changed push_logs from public to private and updated imports.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client Request
    participant Handler as HTTP Handler (ingest.rs)
    participant Utils as Ingestion Utils (flatten_and_push_logs)
    participant Flattener as OTEL Flatten Functions
    participant Stream as Log Stream (push_logs)

    Client->>Handler: Send OTEL ingestion request
    Handler->>Utils: Call flatten_and_push_logs(json, stream, log source)
    Utils->>Flattener: Deserialize & flatten based on log source
    Flattener-->>Utils: Return flattened data
    Utils->>Stream: push_logs(flattened data)
    Stream-->>Utils: Acknowledge log push
    Utils-->>Handler: Return result
    Handler-->>Client: Send response
Loading

Suggested reviewers

  • nikhilsinhaparseable

Poem

I'm a bouncing rabbit in the code field so green,
Hopping over redundant logic, neat and clean.
With one unified call to flatten and push logs quick,
OTEL data now flows smooth—no more tricks!
In every line I find a cozy, optimized bliss.
🐇✨
Code hops on in springtime bliss!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a46e4db and b0b663d.

📒 Files selected for processing (2)
  • src/handlers/http/ingest.rs (6 hunks)
  • src/handlers/http/modal/utils/ingest_utils.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: coverage
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
🔇 Additional comments (9)
src/handlers/http/modal/utils/ingest_utils.rs (4)

22-24: LGTM!

The OpenTelemetry protobuf imports are correctly specified and necessary for the new functionality.


38-38: LGTM!

The OTEL flattening functions import is correctly specified and necessary for the new functionality.


58-78: LGTM!

The implementation of OTEL handling is well-structured with:

  • Consistent pattern for each OTEL type
  • Proper error handling
  • Clear comments
  • Type-safe deserialization

86-86:

❓ Verification inconclusive

Verify the impact of making push_logs private.

The visibility change aligns with encapsulation principles since the function is only used within this module. However, this is a breaking change that might affect external users.

Run the following script to verify if push_logs is used outside this module:


🏁 Script executed:

#!/bin/bash
# Description: Search for external usage of `push_logs` function.

# Test: Search for function usage. Expect: Only occurrences within this module.
rg -A 5 $'pub fn push_logs'

Length of output: 28


Action Required: Confirm that push_logs is not referenced externally before merging.

The visibility change to push_logs aligns with encapsulation principles since the function appears to be used only within its module. However, our initial automated check (using a regex search for pub fn push_logs) produced no output, which isn’t conclusive enough to guarantee that there aren’t any external references. Please manually verify or run an extended search (e.g., searching for any calls to push_logs( outside of src/handlers/http/modal/utils/ingest_utils.rs) to ensure that this breaking change does not impact external usage.

src/handlers/http/ingest.rs (5)

41-41: LGTM!

The flatten_and_push_logs import is correctly specified and necessary for the new functionality.


68-73: LGTM!

The OTEL error handling is well-implemented:

  • Prevents OTEL ingestion through the general endpoint
  • Provides clear guidance to users about the correct endpoints

138-138: LGTM!

The OTEL logs ingestion is simplified using the unified flatten_and_push_logs function, making the code more maintainable.


169-169: LGTM!

The OTEL metrics ingestion is simplified using the unified flatten_and_push_logs function, making the code more maintainable.


197-197: LGTM!

The OTEL traces ingestion is simplified using the unified flatten_and_push_logs function, making the code more maintainable.


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

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.

@de-sh de-sh force-pushed the ingest-without-refactor branch from 66f231a to a46e4db Compare February 13, 2025 05:50
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 (3)
src/handlers/http/modal/utils/ingest_utils.rs (2)

46-48: Consider partial success or error aggregation
Currently, if one record fails to be pushed, the entire loop exits with an error. If partial success is desired, you could collect errors while continuing to process the remaining records.

Would you like me to propose a pattern for error aggregation or partial success handling?


50-56: Potential logging enhancement
It may be helpful to log how many Otel logs were processed or flattened to support observability.

src/handlers/http/ingest.rs (1)

44-44: Unused import?
push_logs appears to be imported here but not actually used. Consider removing it if it’s truly unused to keep imports clean.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 20e66a4 and 66f231a.

📒 Files selected for processing (2)
  • src/handlers/http/ingest.rs (3 hunks)
  • src/handlers/http/modal/utils/ingest_utils.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: coverage
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
🔇 Additional comments (8)
src/handlers/http/modal/utils/ingest_utils.rs (5)

22-24: No issues with the new imports
Imports for OTEL data structures look appropriate and provide the necessary context for processing logs, metrics, and traces.


32-35: Approved changes to import references
The expanded imports of OTEL flatten methods seem correct and well-integrated.


57-63: Consistent OtelTraces approach
The code mirrors the OtelLogs logic; no issues spotted.


64-70: Consistent OtelMetrics approach
Implementation aligns with the existing patterns for logs and traces.


78-78:

❌ Incorrect review comment

Confirm non-public visibility
Removing pub may limit its usage to this module only. Verify that no external calls require push_logs.


🏁 Script executed:

#!/bin/bash
# Searching for usage of push_logs throughout the codebase
rg 'push_logs' -A 2

Length of output: 3932


Keep push_logs as public.
Our search results confirm that push_logs is being imported and used externally (e.g., in src/handlers/http/ingest.rs), so removing pub would break these external references. Please ensure that its public visibility is maintained.

Likely an incorrect or invalid review comment.

src/handlers/http/ingest.rs (3)

133-133: Unified ingestion call
Calling flatten_and_push_logs here neatly removes duplication. Nicely done.


164-164: Streamlined OTEL metrics ingestion
Consistent with the updated architecture for OTEL ingestion; looks good.


192-192: Consistent traces ingestion
Aligns with the new flattening approach. No concerns.

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)
src/handlers/http/ingest.rs (1)

332-825: Consider adding tests for the unified flattening logic.

While the test coverage is comprehensive for data transformation and schema validation, it would be beneficial to add specific tests for the unified flatten_and_push_logs function to ensure it correctly handles all OTEL log sources (logs, metrics, and traces).

Would you like me to help generate test cases for the unified flattening logic?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66f231a and a46e4db.

📒 Files selected for processing (2)
  • src/handlers/http/ingest.rs (4 hunks)
  • src/handlers/http/modal/utils/ingest_utils.rs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/handlers/http/modal/utils/ingest_utils.rs
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: coverage
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
🔇 Additional comments (2)
src/handlers/http/ingest.rs (2)

41-41: LGTM!

The import is correctly placed and follows Rust's module system conventions.


130-130: Great refactoring!

The consolidation of flattening logic into flatten_and_push_logs across all OTEL handlers improves code maintainability while preserving the specific validation requirements for each log source.

Also applies to: 161-161, 189-189

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 13, 2025
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable left a comment

Choose a reason for hiding this comment

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

LGTM

@nitisht nitisht merged commit 54d06a8 into parseablehq:main Feb 18, 2025
14 checks passed
@de-sh de-sh deleted the ingest-without-refactor branch February 18, 2025 18:02
@coderabbitai coderabbitai bot mentioned this pull request Mar 22, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jul 29, 2025
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.

3 participants