Skip to content

optimise server start #1277

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 28, 2025

Conversation

nikhilsinhaparseable
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Mar 28, 2025

parallelise stream migration
load calls - correlations, filters, dashboards, alerts in parallel
remove file migration - deprecate for migrations < 1.0.0

Summary by CodeRabbit

  • New Features

    • Introduced a concurrent startup process that loads key components together, resulting in faster initialization and improved reliability.
  • Bug Fixes

    • Enhanced system stability by verifying external service availability before data retrieval, reducing unnecessary errors.
  • Refactor

    • Streamlined error handling and consolidated initialization logic for a more robust operation.
    • Optimized migration procedures to run concurrently with improved error reporting, while retiring legacy routines.

parallelise stream migration
load calls - correlations, filters, dashboards, alerts in parallel
remove file migration - deprecate for migrations < 1.0.0
Copy link
Contributor

coderabbitai bot commented Mar 28, 2025

Walkthrough

This PR enhances error handling and control flow across several modules. A new Anyhow variant is added to the AlertError enum, and the load method in alerts now returns an anyhow::Result<()>. In the HTTP handlers, a liveness check is introduced for ingestors, and a new asynchronous function load_on_init is implemented to concurrently load components. The initialization flows in the modal query and server modules are streamlined by removing redundant imports and using load_on_init. The migration process is also updated to run concurrently with improved error reporting.

Changes

File(s) Change Summary
src/alerts/mod.rs Added Anyhow variant to AlertError; updated status_code to return INTERNAL_SERVER_ERROR for Anyhow; changed Alerts::load to return anyhow::Result<()> with error mapping via map_err.
src/handlers/http/cluster/mod.rs Introduced a liveness check in fetch_cluster_metrics to verify ingestor status and log warnings when not live.
src/handlers/http/modal/mod.rs Added new async function load_on_init that concurrently loads CORRELATIONS, FILTERS, DASHBOARDS, and ALERTS using future::join4 with improved error logging.
src/handlers/http/modal/query_server.rs
src/handlers/http/modal/server.rs
Removed unused component imports; replaced individual error checks with a unified call to load_on_init in the init methods; in the server module, commented out deprecated file migration in load_metadata.
src/migration/mod.rs Modified run_migration to perform stream migrations concurrently using futures::future::join_all, with enhanced error logging for individual stream failures; removed the run_file_migration function.

Sequence Diagram(s)

sequenceDiagram
    participant S as Initialization Caller
    participant L as load_on_init
    participant C as CORRELATIONS
    participant F as FILTERS
    participant D as DASHBOARDS
    participant A as ALERTS

    S->>L: Call load_on_init()
    L->>C: Load CORRELATIONS
    L->>F: Load FILTERS
    L->>D: Load DASHBOARDS
    L->>A: Load ALERTS
    C-->>L: Return result
    F-->>L: Return result
    D-->>L: Return result
    A-->>L: Return result
    L-->>S: Return overall result
Loading
sequenceDiagram
    participant M as run_migration
    participant Streams as Stream Migrations

    M->>Streams: Dispatch concurrent migration tasks (using join_all)
    Streams-->>M: Return individual statuses/warnings
    M->>M: Aggregate results and report errors if any
Loading

Possibly related PRs

Suggested labels

for next release

Poem

Hoppin' through the code with care,
I found new flows floating in the air.
Errors now dance in a unified way,
With concurrent hops to seize the day.
I'm a rabbit coding in a whimsical spree,
Celebrating changes with a joyful glee!
🐰✨

✨ 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: 0

🧹 Nitpick comments (1)
src/migration/mod.rs (1)

134-179: Consider bounding concurrency and returning detailed errors.

While running stream migrations in parallel with join_all is efficient, be mindful of large-scale scenarios where unbounded concurrency can overwhelm system resources. Also consider returning or logging a more detailed error list for troubleshooting, rather than aggregating the total count of failures into a single message.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b32aa56 and 56d277f.

📒 Files selected for processing (6)
  • src/alerts/mod.rs (4 hunks)
  • src/handlers/http/cluster/mod.rs (1 hunks)
  • src/handlers/http/modal/mod.rs (3 hunks)
  • src/handlers/http/modal/query_server.rs (3 hunks)
  • src/handlers/http/modal/server.rs (3 hunks)
  • src/migration/mod.rs (3 hunks)
🧰 Additional context used
🧬 Code Definitions (4)
src/handlers/http/cluster/mod.rs (1)
src/handlers/http/cluster/utils.rs (1)
  • check_liveness (172-192)
src/handlers/http/modal/mod.rs (3)
src/hottier.rs (1)
  • futures (755-757)
src/parseable/mod.rs (1)
  • storage (235-237)
src/rbac/map.rs (1)
  • users (39-45)
src/handlers/http/modal/server.rs (1)
src/handlers/http/modal/mod.rs (1)
  • load_on_init (167-200)
src/alerts/mod.rs (4)
src/handlers/http/query.rs (1)
  • from (346-348)
src/users/dashboards.rs (1)
  • load (113-178)
src/users/filters.rs (1)
  • load (76-131)
src/correlation.rs (1)
  • load (55-75)
⏰ 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 Default x86_64-unknown-linux-gnu
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: coverage
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
🔇 Additional comments (12)
src/handlers/http/cluster/mod.rs (1)

723-727: Great addition of liveness check before fetching metrics.

This change improves error handling by preventing unnecessary network requests to unavailable ingestors, which can enhance performance and provide clearer logs about the system state.

src/alerts/mod.rs (4)

708-709: Good addition of Anyhow variant to standardize error handling.

Adding the Anyhow variant to AlertError enables better integration with other components that use anyhow for error handling, supporting the migration to a more consistent error handling approach across the codebase.


724-725: Consistent error handling for the new Anyhow variant.

Good implementation of the status code handling for the new Anyhow variant, maintaining consistency with other error variants by returning an appropriate INTERNAL_SERVER_ERROR status code.


737-737: Updated return type to use anyhow::Result.

Changing the return type to anyhow::Result<()> aligns with the broader initiative to standardize error handling across the codebase using the anyhow crate.


750-751: Improved error mapping with anyhow.

Using map_err to convert errors to anyhow::Error with a meaningful message improves error context and makes debugging easier.

src/handlers/http/modal/mod.rs (1)

167-200: Excellent implementation of parallel loading to optimize startup.

The new load_on_init function implements concurrent loading of multiple components using future::join4, which should significantly improve server startup time. Key strengths:

  1. Each component (correlations, filters, dashboards, alerts) loads in parallel
  2. Error handling is robust - failures in one component won't stop others from loading
  3. All errors are properly logged without halting execution
  4. The function leverages context from anyhow to provide clearer error messages

This implementation directly supports the PR objective of optimizing server startup by parallelizing component loading.

src/handlers/http/modal/server.rs (2)

102-107: Removed deprecated file migration support as intended.

The commented code and TODO note clearly indicate the removal of file migration support for deployments less than version 1.0.0, which aligns with the PR objectives.


121-121: Simplified initialization with concurrent loading.

Replaced individual component loading with a single call to load_on_init(), leveraging the new concurrent loading mechanism. This change streamlines the code while improving performance through parallelization.

src/migration/mod.rs (1)

24-31: Imports look fine and align with new usage.

No issues found here.

Also applies to: 40-40

src/handlers/http/modal/query_server.rs (3)

36-36: Updated imports are consistent with the revised initialization flow.

No concerns with these added imports.

Also applies to: 42-42


107-108: Consolidate initialization logic.

Invoking load_on_init() centralizes loading tasks, enhancing maintainability. No issues found.


134-139: Returning the result properly ensures reliable error propagation.

Switching to Ok(result) helps maintain consistency in your async error handling.

@nitisht nitisht merged commit 63bbf9d into parseablehq:main Mar 28, 2025
14 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 3, 2025
3 tasks
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