Skip to content

Conversation

nikhilsinhaparseable
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Oct 3, 2025

state history for an alert is saved at path .alerts/alert_state_{alertid}.json details to save - state, last_updated_at
use to show full track of a lifecycle of an alert
not triggered -> triggered -> disabled (if disabled by user) -> not triggered (when issue is resolved)

Summary by CodeRabbit

  • New Features
    • Added persistent alert state history with timestamps, enabling accurate tracking of state changes over time.
    • Alerts now create and remove corresponding state entries on add/delete, keeping stored state aligned with in-memory status.
  • Bug Fixes
    • Local file storage now correctly reports object metadata, improving reliability for storage operations.
  • Chores
    • Backend metastore expanded to support listing, retrieving, updating, and deleting alert state records, reducing unnecessary writes by only persisting real state changes.

state history for an alert is saved at path .alerts/alert_state_{alertid}.json
details to save - state, last_updated_at
use to show full track of a lifecycle of an alert
not triggered -> triggered -> disabled (if disabled by user) -> not triggered (when issue is resolved)
Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Adds persistent alert state tracking via new AlertStateEntry/StateTransition types, metastore trait methods and object-store implementations, integrates state creation/update/delete in HTTP handlers and alert logic, introduces alert_state_json_path, and implements LocalFS head to enable presence checks for alert state files.

Changes

Cohort / File(s) Summary
Alert state data structures
src/alerts/alert_structs.rs
Adds StateTransition and AlertStateEntry types with constructors, state-update logic, current_state accessor, MetastoreObject impl; imports alert_state_json_path.
Alert logic integration
src/alerts/alert_types.rs
Persists alert state by creating/updating AlertStateEntry via metastore in ThresholdAlert state updates, including disabled branch.
Alerts public exports
src/alerts/mod.rs
Re-exports AlertStateEntry and StateTransition.
HTTP handlers alignment
src/handlers/http/alerts.rs
On POST creates initial AlertStateEntry (NotTriggered) and stores to metastore; on DELETE removes corresponding state entry; imports MetastoreObject.
Metastore trait surface
src/metastore/metastore_traits.rs
Adds get_alert_states, get_alert_state_entry(Ulid), put_alert_state(&dyn MetastoreObject), delete_alert_state(&dyn MetastoreObject); imports Ulid and AlertStateEntry.
Object store metastore impl
src/metastore/metastores/object_store_metastore.rs
Implements the four new alert-state methods; reads/writes alert_state_*.json, updates only on state change, deletes by path; imports alert_state_json_path and AlertStateEntry.
Object storage helper
src/storage/object_storage.rs
Adds alert_state_json_path(Ulid) -> RelativePathBuf.
Local filesystem backend
src/storage/localfs.rs
Implements head(path) to return ObjectMeta using fs metadata; replaces previous unimplemented error.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant HTTP as HTTP Alerts Handler
  participant Alerts as Alerts Logic
  participant Meta as Metastore
  participant Store as Object Storage

  rect rgba(230,245,255,0.6)
    note over Client,HTTP: Create Alert
    Client->>HTTP: POST /alerts
    HTTP->>Meta: put_alert_state(AlertStateEntry{NotTriggered})
    Meta->>Store: write alert_state_{id}.json
    HTTP->>Alerts: create + start task
    HTTP-->>Client: 201 Created
  end

  rect rgba(230,255,230,0.6)
    note over Alerts,Meta: Runtime State Update
    Alerts->>Meta: put_alert_state(updated state)
    alt state changed
      Meta->>Store: read current state
      Meta->>Store: write updated alert_state_{id}.json
    else no change
      Meta-->>Alerts: OK (no write)
    end
  end

  rect rgba(255,235,230,0.6)
    note over Client,HTTP: Delete Alert
    Client->>HTTP: DELETE /alerts/{id}
    HTTP->>Meta: delete_alert_state(entry for {id})
    Meta->>Store: delete alert_state_{id}.json
    HTTP-->>Client: 204 No Content
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Feat: Metastore #1424 — Extends Metastore/MetastoreObject integration; closely related to adding AlertStateEntry persistence and new metastore methods.
  • bugfixes #1395 — Touches alert state update logic in src/alerts; related to this PR’s persistence of state updates.
  • Modularize Alerts #1390 — Modifies alert subsystem structure/flow; complements new alert-state management and exports.

Suggested labels

for next release

Suggested reviewers

  • parmesant

Poem

Hop, tap—an alert takes flight,
I jot its states by moonlit byte.
Little JSON burrows store the tale,
From calm to ring to muted hail.
I prune old paths with gentle care—
Thump! The metastore knows I was there. 🐇📜

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description does not follow the repository’s required template: it lacks a “Fixes #XXXX” section, the “### Description” header, detailed rationale or key changes, and the completion checklist for testing, comments, and documentation. Please update the PR description to include the “Fixes #XXXX” header if relevant, add a “### Description” section outlining the goal, rationale, and key changes, and mark the checklist items for testing, comments, and documentation as specified in the template.
Docstring Coverage ⚠️ Warning Docstring coverage is 72.73% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary feature added by this changeset, namely saving alert state history, using a clear and concise phrasing that aligns with the conventional commit style without adding unnecessary detail.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 f1ef68b and 514a9e3.

📒 Files selected for processing (8)
  • src/alerts/alert_structs.rs (2 hunks)
  • src/alerts/alert_types.rs (3 hunks)
  • src/alerts/mod.rs (1 hunks)
  • src/handlers/http/alerts.rs (3 hunks)
  • src/metastore/metastore_traits.rs (2 hunks)
  • src/metastore/metastores/object_store_metastore.rs (3 hunks)
  • src/storage/localfs.rs (1 hunks)
  • src/storage/object_storage.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
src/handlers/http/alerts.rs (2)
src/alerts/alert_structs.rs (5)
  • new (63-75)
  • new (101-115)
  • new (126-132)
  • new (541-546)
  • new (551-556)
src/parseable/mod.rs (1)
  • new (178-192)
src/storage/localfs.rs (5)
src/storage/object_storage.rs (1)
  • head (269-269)
src/storage/gcs.rs (1)
  • head (441-453)
src/storage/s3.rs (3)
  • head (605-617)
  • from (993-1001)
  • from (1005-1007)
src/storage/azure_blob.rs (1)
  • head (460-472)
src/storage/metrics_layer.rs (1)
  • head (251-265)
src/alerts/alert_structs.rs (3)
src/storage/object_storage.rs (3)
  • alert_json_path (1131-1133)
  • alert_state_json_path (1148-1153)
  • new (77-86)
src/alerts/alert_types.rs (3)
  • update_state (196-273)
  • get_object_id (75-77)
  • get_object_path (71-73)
src/metastore/metastore_traits.rs (2)
  • get_object_id (178-178)
  • get_object_path (177-177)
src/metastore/metastores/object_store_metastore.rs (3)
src/storage/object_storage.rs (9)
  • alert_json_path (1131-1133)
  • alert_state_json_path (1148-1153)
  • to_bytes (1073-1077)
  • new (77-86)
  • serde_json (540-540)
  • serde_json (584-584)
  • serde_json (619-619)
  • serde_json (645-645)
  • serde_json (692-692)
src/metastore/metastore_traits.rs (4)
  • get_alert_states (53-53)
  • get_alert_state_entry (54-57)
  • put_alert_state (58-58)
  • delete_alert_state (59-59)
src/alerts/alert_structs.rs (5)
  • new (63-75)
  • new (101-115)
  • new (126-132)
  • new (541-546)
  • new (551-556)
src/metastore/metastore_traits.rs (1)
src/metastore/metastores/object_store_metastore.rs (4)
  • get_alert_states (119-138)
  • get_alert_state_entry (140-156)
  • put_alert_state (158-203)
  • delete_alert_state (206-212)
src/alerts/alert_types.rs (1)
src/alerts/alert_structs.rs (5)
  • new (63-75)
  • new (101-115)
  • new (126-132)
  • new (541-546)
  • new (551-556)
⏰ 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: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • 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
🔇 Additional comments (1)
src/storage/object_storage.rs (1)

1145-1153: Path helper looks good.
Produces the expected .parseable/alerts/alert_state_{alert_id}.json path; nothing else to flag.


Comment @coderabbitai help to get the list of available commands and usage tips.

@nitisht nitisht merged commit 4c3b85d into parseablehq:main Oct 4, 2025
13 checks passed
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