Skip to content

add alert query mode metadata#1707

Open
nikhilsinhaparseable wants to merge 8 commits into
parseablehq:mainfrom
nikhilsinhaparseable:alert-promql
Open

add alert query mode metadata#1707
nikhilsinhaparseable wants to merge 8 commits into
parseablehq:mainfrom
nikhilsinhaparseable:alert-promql

Conversation

@nikhilsinhaparseable

@nikhilsinhaparseable nikhilsinhaparseable commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

persist queryType for alerts: builder, code, or promql
defaults old alerts to builder
accepts legacy queryType=sql as code
reserves old creationType keys
treats builder/code as SQL modes for auth and dataset resolution

Summary by CodeRabbit

  • New Features

    • Added support for selecting Builder, Code, and PromQL query types when configuring alerts.
    • PromQL alerts can specify datasets directly, with dataset access validated during alert operations.
    • Alert responses now show the configured query type.
  • Bug Fixes

    • Improved authorization checks to account for alert query type and datasets across alert actions.
    • Preserved compatibility with the legacy sql query type value.
    • Prevented unsupported PromQL threshold alerts from being scheduled in OSS deployments.

persist queryType for alerts: builder, code, or promql
defaults old alerts to builder
accepts legacy queryType=sql as code
reserves old creationType keys
treats builder/code as SQL modes for auth and dataset resolution.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 795266a1-a342-46d1-929c-78a701030e11

📥 Commits

Reviewing files that changed from the base of the PR and between 39d85b4 and 8f962e4.

📒 Files selected for processing (1)
  • src/handlers/http/alerts.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/handlers/http/alerts.rs

Walkthrough

Adds AlertQueryType support across alert requests, configurations, threshold alerts, loading, OSS validation, authorization, and HTTP handlers. PromQL alerts use explicit datasets, while builder and code alerts continue resolving datasets from their query.

Changes

Alert query type and contracts

Layer / File(s) Summary
Query type and alert data contracts
src/alerts/alert_enums.rs, src/alerts/alert_structs.rs, src/alerts/alert_traits.rs
Defines builder, code, and PromQL query types; propagates query_type and datasets through alert request/config/response structures; adds trait access and deserialization tests.
Request conversion and ThresholdAlert validation
src/alerts/alert_structs.rs, src/alerts/alert_types.rs
Uses explicit datasets for PromQL, preserves query type through conversions, and rejects PromQL threshold alerts in OSS validation.
Alert loading and authorization
src/alerts/mod.rs
Adds config-based authorization, query-type-aware dataset checks, migration defaults, config parsing helpers, OSS filtering, and schedulability checks.
HTTP alert handler authorization
src/handlers/http/alerts.rs
Updates alert endpoints to authorize complete configurations and preserves query_type during alert modification.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AlertRequest
  participant AlertConfig
  participant AlertAuthorization
  participant DatasetAccess

  Client->>AlertRequest: submit queryType and datasets
  AlertRequest->>AlertConfig: resolve or validate datasets
  Client->>AlertAuthorization: access alert
  AlertAuthorization->>AlertConfig: inspect query_type
  AlertAuthorization->>DatasetAccess: authorize PromQL dataset
  DatasetAccess-->>AlertAuthorization: allow or deny
Loading

Poem

I’m a rabbit with queries, hopping in code,
Builder and PromQL share the road.
Datasets are checked, old aliases still sing,
Alerts carry their type through everything.
A carrot-sized config now knows what to do!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.37% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding alert query mode metadata.
Description check ✅ Passed The description covers the goal and key behavior changes, with only non-critical template items like issue ID and checklist omitted.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/alerts/alert_types.rs`:
- Around line 94-97: The PromQL guard in validate() is too late because
Alerts::load still enqueues unsupported ThresholdAlert entries before
validation. Update the load/scheduling path so unsupported
AlertQueryType::Promql alerts are filtered out or marked disabled before
creating an AlertTask::Create, using the existing validate() /
AlertError::NotPresentInOSS logic as the source of truth. Make sure both
occurrences in alert_types.rs are covered so OSS never schedules PromQL alerts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bd53268e-dd27-4454-a46a-b83b6e7fb28d

📥 Commits

Reviewing files that changed from the base of the PR and between c54b762 and 3993a1d.

📒 Files selected for processing (8)
  • src/alerts/alert_enums.rs
  • src/alerts/alert_structs.rs
  • src/alerts/alert_traits.rs
  • src/alerts/alert_types.rs
  • src/alerts/mod.rs
  • src/handlers/http/alerts.rs
  • src/lib.rs
  • src/metastore/metastore_traits.rs

Comment thread src/alerts/alert_types.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/alerts/mod.rs`:
- Around line 153-162: The OSS alert loading path is aborting on unsupported
alert types because `load()` propagates errors from `alert_from_config_oss`, so
a single anomaly or forecast config stops later alerts from being loaded. Update
the alert-loading logic in `load()` to mirror the unschedulable-alert handling
below by skipping `AlertError::NotPresentInOSS` cases instead of returning
early, while keeping supported `Threshold` alerts loaded normally through
`alert_from_config_oss`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7ace9906-fea3-4fff-9edf-01fd115291fa

📥 Commits

Reviewing files that changed from the base of the PR and between 805e9bc and 4cc0f7a.

📒 Files selected for processing (1)
  • src/alerts/mod.rs

Comment thread src/alerts/mod.rs Outdated
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.

1 participant