feat: add rate of change as alert trigger condition#1943
Draft
feat: add rate of change as alert trigger condition#1943
Conversation
Add a new "Rate of Change" condition type for alerts alongside the existing threshold rules. This compares the current evaluation window's value to the immediately preceding window and fires when the absolute or percentage change exceeds the configured threshold -- similar to Datadog's Change Alert, Grafana's diff/percent_diff reducers, and Splunk's Sudden Change detector. - New enums: AlertConditionType (threshold | rate_of_change), AlertChangeType (absolute | percentage) - Zod validation requiring changeType when conditionType is rate_of_change - Evaluation engine: extended date range for 2-window lookback, computeRateOfChange function, baseline bucket tracking in processAlert - Frontend: condition type / change type selectors in saved search and dashboard tile alert forms, improved alert card summary on /alerts page - Notification templates updated for rate-of-change context - Unit tests (schema validation, computeRateOfChange, external API) - Integration tests (API CRUD, ClickHouse evaluation with 4 scenarios) - E2E Playwright tests for saved search and dashboard tile flows Made-with: Cursor
🦋 Changeset detectedLatest commit: 89d0617 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Made-with: Cursor
Contributor
E2E Test Results✅ All tests passed • 93 passed • 3 skipped • 949s
Tests ran across 4 shards in parallel. |
| AlertSource, | ||
| AlertThresholdType, | ||
| } from '@/models/alert'; | ||
| import { SavedSearch } from '@/models/savedSearch'; |
| AlertThresholdType, | ||
| } from '@/models/alert'; | ||
| import { SavedSearch } from '@/models/savedSearch'; | ||
| import { Source } from '@/models/source'; |
Comment on lines
+23
to
+28
| import Alert, { | ||
| AlertChangeType, | ||
| AlertConditionType, | ||
| AlertSource, | ||
| AlertThresholdType, | ||
| } from '@/models/alert'; |
- Remove unused imports (SavedSearch, Source, AlertConditionType) - Fix backward-compat test: Mongoose default makes conditionType 'threshold' on new alerts, not undefined - Add conditionType to external API snapshot test expectation - Fix E2E locator: use 'Rate of Change' text to avoid strict mode violation from ambiguous 'change' match Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/alertspage summary now shows the condition type (Threshold vs Rate of Change) and whether percentage change is in use.Changes
Data model (
common-utils,api/models,api/utils/zod):AlertConditionType(threshold | rate_of_change),AlertChangeType(absolute | percentage)changeTypewhenconditionTypeisrate_of_changeIAlertinterface updated with optional fields for backward compatibilityEvaluation engine (
api/tasks/checkAlerts/index.ts):computeRateOfChange()function (absolute and percentage modes)processAlertloop tracks previous bucket values per group, skips baseline bucket, computes changeFrontend (
app/):/alertspage shows condition type label and % suffixAlertPreviewChartaccepts new props for rate-of-change contextAPI (
api/routers,api/utils/externalApi,api/controllers,api/tasks/checkAlerts/template):/alertsresponse includesconditionTypeandchangeTypeTest plan
alertTypes.test.ts),computeRateOfChange(12 tests), external API translation (2 tests)alerts.test.ts, 2 in external API), ClickHouse evaluation (4 new tests insingleInvocationAlert.test.tscovering absolute fires, percentage fires, below-threshold suppression, empty-baseline)Made with Cursor