Skip to content

add dataset name and type to home api response #1271

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 1 commit into from
Mar 26, 2025

Conversation

nikhilsinhaparseable
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Mar 26, 2025

added field

"datasets": [
        {
            "title": "otel-logs",
            "dataset_type": "Logs"
        },
        {
            "title": "otel-metrics1",
            "dataset_type": "Metrics"
        },
        {
            "title": "otel-traces12",
            "dataset_type": "Traces"
        },
        {
            "title": "test10",
            "dataset_type": "Logs"
        },
        {
            "title": "test11",
            "dataset_type": "Logs"
        },
        {
            "title": "test12",
            "dataset_type": "Logs"
        }
    ],

Summary by CodeRabbit

  • New Features

    • The Home view now offers organized dataset displays by categorizing data streams as Logs, Metrics, or Traces with clear titles.
  • Refactor

    • Stream processing and dataset formation have been streamlined to enhance clarity and ensure consistent presentation across the Home interface.

Copy link
Contributor

coderabbitai bot commented Mar 26, 2025

Walkthrough

The pull request introduces a new enumeration (DataSetType) and a new structure (DataSet) to represent dataset types (Logs, Metrics, Traces) alongside their titles. The HomeResponse struct now includes a datasets vector to hold multiple DataSet entries. The generate_home_response function is updated to create dataset entries based on the log source's format from the stream JSON data. Additionally, some variable names related to stream JSON handling are simplified and the function call to stats_for_date is updated accordingly.

Changes

File Change Summary
src/.../home/mod.rs - Added DataSetType enum and DataSet struct.
- Updated HomeResponse to include a new datasets field.
- Modified generate_home_response to build dataset entries based on stream JSON data and simplified variable names.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant HomeResponseGenerator
    participant StreamDataProcessor
    participant StatsService

    Caller->>HomeResponseGenerator: Request HomeResponse
    HomeResponseGenerator->>StreamDataProcessor: Process stream_jsons
    StreamDataProcessor-->>HomeResponseGenerator: Return DataSet (title, type)
    HomeResponseGenerator->>StatsService: Call stats_for_date with stream_wise_stream_json
    StatsService-->>HomeResponseGenerator: Return stats
    HomeResponseGenerator-->>Caller: Return HomeResponse with datasets & stats
Loading

Possibly related PRs

  • feat: prism post datasets API #1236: Relates to adding a new API endpoint for handling datasets, which has a strong code-level connection with the introduction of dataset structures and modifications in the HomeResponse struct.

Suggested labels

for next release

Suggested reviewers

  • praveen5959

Poem

I'm a rabbit in a code-filled glen,
Hopping through changes again and again.
Datasets sprout like carrots so bright,
Logs, Metrics, and Traces come to light.
With every function and variable renaming in sight,
I celebrate this update with pure delight! 🐰
Cheers to the code, crisp and light!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0f7e92c and c56b28c.

📒 Files selected for processing (1)
  • src/prism/home/mod.rs (6 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/prism/home/mod.rs (5)
src/alerts/mod.rs (3)
  • new (99-105)
  • new (140-152)
  • new (163-169)
src/handlers/http/cluster/utils.rs (4)
  • new (35-47)
  • new (61-77)
  • new (92-110)
  • new (122-129)
src/storage/mod.rs (3)
  • new (182-184)
  • new (195-201)
  • default (205-225)
src/parseable/mod.rs (1)
  • new (140-162)
src/metadata.rs (1)
  • new (95-130)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: coverage
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
🔇 Additional comments (7)
src/prism/home/mod.rs (7)

65-70: New Enum: DataSetType

The enum properly categorizes dataset types as Logs, Metrics, or Traces. Good use of the Debug and Serialize derive macros for debugging and JSON serialization.


72-76: New Struct: DataSet

Clean implementation of the DataSet struct with title and type fields. The structure aligns well with the PR objective of adding dataset name and type to the API response.


86-86: HomeResponse Update

The HomeResponse struct is properly updated to include the new datasets field, which will allow the API to return dataset information to clients.


178-178: Initialize Datasets Collection

Appropriate initialization of the datasets vector before populating it in the loop.


182-182: Variable Naming Improvement

Good renaming of variables to be more concise while maintaining clarity:

  • stream_wise_stream_json (from likely stream_wise_ingestor_stream_json)
  • stream_jsons (from likely ingestor_stream_jsons)

The simplified naming makes the code more readable while preserving functionality.

Also applies to: 194-194, 203-203, 205-205


227-227: Updated Function Call

The function call is correctly updated to use the renamed variable.


238-240: Including Datasets in Response

The datasets vector is properly included in the HomeResponse, fulfilling the PR objective of including dataset information in the API response.

Comment on lines +207 to 224
let log_source = &stream_jsons[0].clone().log_source;

// if log_source_format is otel-metrics, set DataSetType to metrics
//if log_source_format is otel-traces, set DataSetType to traces
//else set DataSetType to logs

let dataset_type = match log_source[0].log_source_format {
LogSource::OtelMetrics => DataSetType::Metrics,
LogSource::OtelTraces => DataSetType::Traces,
_ => DataSetType::Logs,
};

let dataset = DataSet {
title: stream.clone(),
dataset_type,
};
datasets.push(dataset);
}
Copy link
Contributor

@coderabbitai coderabbitai bot Mar 26, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add Missing Error Handling for Empty Collections

The code assumes stream_jsons and log_source always have at least one element, which could cause panic if empty.

Add error handling to prevent panic:

-let log_source = &stream_jsons[0].clone().log_source;
+if stream_jsons.is_empty() {
+    continue;
+}
+let log_source = &stream_jsons[0].clone().log_source;
+
+if log_source.is_empty() {
+    continue;
+}

let dataset_type = match log_source[0].log_source_format {
    LogSource::OtelMetrics => DataSetType::Metrics,
    LogSource::OtelTraces => DataSetType::Traces,
    _ => DataSetType::Logs,
};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let log_source = &stream_jsons[0].clone().log_source;
// if log_source_format is otel-metrics, set DataSetType to metrics
//if log_source_format is otel-traces, set DataSetType to traces
//else set DataSetType to logs
let dataset_type = match log_source[0].log_source_format {
LogSource::OtelMetrics => DataSetType::Metrics,
LogSource::OtelTraces => DataSetType::Traces,
_ => DataSetType::Logs,
};
let dataset = DataSet {
title: stream.clone(),
dataset_type,
};
datasets.push(dataset);
}
if stream_jsons.is_empty() {
continue;
}
let log_source = &stream_jsons[0].clone().log_source;
if log_source.is_empty() {
continue;
}
let dataset_type = match log_source[0].log_source_format {
LogSource::OtelMetrics => DataSetType::Metrics,
LogSource::OtelTraces => DataSetType::Traces,
_ => DataSetType::Logs,
};
let dataset = DataSet {
title: stream.clone(),
dataset_type,
};
datasets.push(dataset);
}

Copy link
Contributor Author

@nikhilsinhaparseable nikhilsinhaparseable Mar 26, 2025

Choose a reason for hiding this comment

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

if the stream is found, stream_json always exists, and for a stream_json, log_source always exists, do we still need a check?

Copy link
Contributor

Choose a reason for hiding this comment

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

@nikhilsinhaparseable Thank you for this clarification. I understand now that these are system invariants - if a stream is found, stream_jsons will always exist with at least one element, and for any valid stream_json, the log_source array will always have at least one element as well. This explains why the additional null checks aren't necessary in this context.


✏️ Learnings added
Learnt from: nikhilsinhaparseable
PR: parseablehq/parseable#1271
File: src/prism/home/mod.rs:207-224
Timestamp: 2025-03-26T06:13:48.529Z
Learning: In the Parseable codebase, if a stream is found, the stream_jsons array will always have at least one element. Additionally, for any valid stream_json object, the log_source array will always have at least one element. This is a design invariant that makes additional null checks unnecessary.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@nitisht nitisht merged commit 474dcd2 into parseablehq:main Mar 26, 2025
14 checks passed
@coderabbitai coderabbitai bot mentioned this pull request May 6, 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.

2 participants