Skip to content

bugfixes #1395

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 2 commits into from
Jul 30, 2025
Merged

bugfixes #1395

merged 2 commits into from
Jul 30, 2025

Conversation

parmesant
Copy link
Contributor

@parmesant parmesant commented Jul 30, 2025

  • fixed state update

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

    • Improved alert state management with stricter state transition rules and enhanced notification handling.
    • Alert state updates now support asynchronous processing for better performance.
  • Refactor

    • Unified alert retrieval and state update logic to use trait objects, streamlining alert management.
    • Standardized JSON responses for alert-related API endpoints.
    • Query access for alerts is now consistently handled via getter methods.
  • Bug Fixes

    • More robust validation prevents invalid manual alert state transitions.

- fixed state update
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Walkthrough

This change refactors alert state management by introducing an asynchronous update_state method to the AlertTrait, removing the synchronous set_state method, and updating alert retrieval to return trait objects instead of configuration snapshots. State transition logic is delegated to alert implementations, and alert state updates now use trait methods throughout the codebase.

Changes

Cohort / File(s) Change Summary
AlertTrait and AlertManagerTrait Refactor
src/alerts/traits.rs
Added async update_state to AlertTrait, removed set_state, and changed get_alert_by_id to return boxed trait objects.
ThresholdAlert State Management
src/alerts/alert_types.rs
Replaced set_state with async update_state implementing stricter state transition rules, async persistence, and notification triggering.
Alert Manager and State Update Logic
src/alerts/mod.rs
Removed AlertState::update_state, refactored alert retrieval and state update to use trait objects, and removed persistence step from state update.
Alert Query Access and HTTP Handlers
src/handlers/http/alerts.rs
Switched to using get_query() for query access, updated state update flow to use trait methods, and standardized JSON responses.
Utility Function Refactor
src/alerts/alerts_utils.rs
Refactored array and object checks in convert_result_to_f64 for clearer control flow.

Sequence Diagram(s)

sequenceDiagram
    participant HTTP_Handler
    participant AlertManager
    participant Alert (Trait Object)
    participant Storage

    HTTP_Handler->>AlertManager: get_alert_by_id(alert_id)
    AlertManager->>Alert: (returns Box<dyn AlertTrait>)
    HTTP_Handler->>Alert: update_state(is_manual, new_state, trigger_notif)
    Alert->>Alert: Validate state transition
    Alert->>Storage: Persist updated state (async)
    Alert->>Alert: Trigger notification (if applicable)
    Alert-->>HTTP_Handler: Result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

  • Modularize Alerts #1390: Refactored alert traits and introduced modular alert structuring, which is directly extended and refined in this PR.

Suggested labels

for next release

Suggested reviewers

  • nikhilsinhaparseable

Poem

In the warren where alerts reside,
Async updates now hop in stride.
Trait objects leap, configs retire,
State changes checked, as rules require.
With every hop, a state persists—
The rabbit logs, and nothing’s missed!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

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


📜 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 384ecba and 26265e3.

📒 Files selected for processing (1)
  • src/alerts/mod.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/alerts/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: coverage
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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

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

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

1523-1523: Remove commented code.

The commented store variable should be removed since storage operations are now handled within the alert's update_state method.

-        // let store = PARSEABLE.storage.get_object_store();
-
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a8c1f80 and 384ecba.

📒 Files selected for processing (5)
  • src/alerts/alert_types.rs (2 hunks)
  • src/alerts/alerts_utils.rs (1 hunks)
  • src/alerts/mod.rs (2 hunks)
  • src/alerts/traits.rs (2 hunks)
  • src/handlers/http/alerts.rs (4 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: de-sh
PR: parseablehq/parseable#0
File: :0-0
Timestamp: 2025-03-20T15:50:45.435Z
Learning: Pay close attention to code comments for typos and semantic clarity during reviews for the Parseable project.
src/alerts/alerts_utils.rs (1)

Learnt from: nikhilsinhaparseable
PR: #1388
File: src/alerts/mod.rs:88-104
Timestamp: 2025-07-24T11:09:21.781Z
Learning: In the Parseable alert system (src/alerts/mod.rs), alert versions are server-generated and controlled via CURRENT_ALERTS_VERSION constant, not user input. The AlertVerison enum's From<&str> implementation correctly defaults unknown versions to V2 since the server only generates known versions (v1, v2). Unknown versions would only occur in exceptional cases like file corruption, making the current fallback approach appropriate.

src/handlers/http/alerts.rs (2)

Learnt from: nikhilsinhaparseable
PR: #1388
File: src/alerts/mod.rs:88-104
Timestamp: 2025-07-24T11:09:21.781Z
Learning: In the Parseable alert system (src/alerts/mod.rs), alert versions are server-generated and controlled via CURRENT_ALERTS_VERSION constant, not user input. The AlertVerison enum's From<&str> implementation correctly defaults unknown versions to V2 since the server only generates known versions (v1, v2). Unknown versions would only occur in exceptional cases like file corruption, making the current fallback approach appropriate.

Learnt from: nikhilsinhaparseable
PR: #1340
File: src/query/mod.rs:64-66
Timestamp: 2025-06-18T06:39:04.775Z
Learning: In src/query/mod.rs, QUERY_SESSION_STATE and QUERY_SESSION serve different architectural purposes: QUERY_SESSION_STATE is used for stats calculation and allows dynamic registration of individual parquet files from the staging path (files created every minute), while QUERY_SESSION is used for object store queries with the global schema provider. Session contexts with schema providers don't support registering individual tables/parquets, so both session objects are necessary for their respective use cases.

src/alerts/alert_types.rs (1)

Learnt from: nikhilsinhaparseable
PR: #1388
File: src/alerts/mod.rs:88-104
Timestamp: 2025-07-24T11:09:21.781Z
Learning: In the Parseable alert system (src/alerts/mod.rs), alert versions are server-generated and controlled via CURRENT_ALERTS_VERSION constant, not user input. The AlertVerison enum's From<&str> implementation correctly defaults unknown versions to V2 since the server only generates known versions (v1, v2). Unknown versions would only occur in exceptional cases like file corruption, making the current fallback approach appropriate.

src/alerts/traits.rs (1)

Learnt from: nikhilsinhaparseable
PR: #1388
File: src/alerts/mod.rs:88-104
Timestamp: 2025-07-24T11:09:21.781Z
Learning: In the Parseable alert system (src/alerts/mod.rs), alert versions are server-generated and controlled via CURRENT_ALERTS_VERSION constant, not user input. The AlertVerison enum's From<&str> implementation correctly defaults unknown versions to V2 since the server only generates known versions (v1, v2). Unknown versions would only occur in exceptional cases like file corruption, making the current fallback approach appropriate.

src/alerts/mod.rs (1)

Learnt from: nikhilsinhaparseable
PR: #1388
File: src/alerts/mod.rs:88-104
Timestamp: 2025-07-24T11:09:21.781Z
Learning: In the Parseable alert system (src/alerts/mod.rs), alert versions are server-generated and controlled via CURRENT_ALERTS_VERSION constant, not user input. The AlertVerison enum's From<&str> implementation correctly defaults unknown versions to V2 since the server only generates known versions (v1, v2). Unknown versions would only occur in exceptional cases like file corruption, making the current fallback approach appropriate.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: coverage
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
🔇 Additional comments (7)
src/alerts/alerts_utils.rs (1)

140-141: Good refactoring for clarity.

Separating the array check from the empty check improves code readability and makes the validation logic more explicit.

src/handlers/http/alerts.rs (2)

135-137: LGTM! Proper trait abstraction.

The changes correctly use the trait getter method and return the configuration representation, maintaining API compatibility while working with the new trait-based architecture.


194-220: Ignore the alert reinsertion optimization suggestion
The clone → mutate → reinsert pattern is intentional in our trait-based design.

  • get_alert_by_id returns a fresh Box<dyn AlertTrait> (via clone_box)
  • You then call alert.update_state(…) on that clone
  • Finally, alerts.update(&*alert) reinserts it, invoking clone_box() again

Avoiding these clones would require a major API change (e.g. storing mutable trait objects or changing method signatures to &mut self), which is out of scope. No action required.

Likely an incorrect or invalid review comment.

src/alerts/alert_types.rs (2)

214-237: State transition rules are well-defined.

The validation logic correctly enforces state transition rules for manual updates. The restrictions prevent invalid state transitions and maintain alert lifecycle integrity.


241-241: put_alert signature exists in ObjectStorage
I’ve confirmed that the async fn put_alert(&self, alert_id: Ulid, alert: &AlertConfig) method is declared in the ObjectStorage trait (see src/storage/object_storage.rs). No further changes are needed.

src/alerts/traits.rs (1)

33-38: Clean trait evolution for async state management.

The addition of the async update_state method and the change to return trait objects from get_alert_by_id properly support the new architecture. The method signature provides all necessary parameters for state validation, persistence, and notification handling.

Also applies to: 65-65

src/alerts/mod.rs (1)

1527-1549: Write-lock ensures atomic updates – no race here

The self.alerts.write().await guard serializes all mutations, so reading the entry, updating its state, and reinserting it happen under the same write lock. There is no interleaving that could leave the map in an inconsistent state.

If you later spot contention on this lock (e.g., slow update_state calls blocking readers), you can refactor the AlertTrait implementation to hold its mutable fields behind a finer-grained mutex or atomic, allowing in-place state changes without locking the entire alerts map.

Likely an incorrect or invalid review comment.

@nikhilsinhaparseable nikhilsinhaparseable merged commit ecdb27f into parseablehq:main Jul 30, 2025
13 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 4, 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.

2 participants