-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(aci): Add missing anomaly detection conditions #103004
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a86f435
feat(aci): Add missing anomaly detection conditions
scttcper d1ff1b6
update payload casing, remove unused values
scttcper fc3473d
cleanup
scttcper 25cf1dc
remove seasonality
scttcper 4295ec0
remove unused config fields
scttcper c4f6690
last usage
scttcper 81647e2
cleanup sensitivity
scttcper b8c726f
Merge branch 'master' into scttcper/dynamic-alert-thresholds
scttcper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { | |
| DetectorPriorityLevel, | ||
| } from 'sentry/types/workflowEngine/dataConditions'; | ||
| import type { | ||
| AnomalyDetectionComparison, | ||
| Detector, | ||
| MetricCondition, | ||
| MetricConditionGroup, | ||
|
|
@@ -183,6 +184,22 @@ interface NewDataSource { | |
| timeWindow: number; | ||
| } | ||
|
|
||
| function createAnomalyDetectionCondition( | ||
| data: Pick<MetricDetectorFormData, 'sensitivity' | 'thresholdType'> | ||
| ): NewConditionGroup['conditions'] { | ||
| return [ | ||
| { | ||
| type: DataConditionType.ANOMALY_DETECTION, | ||
| comparison: { | ||
| sensitivity: data.sensitivity, | ||
| seasonality: 'auto' as const, | ||
| thresholdType: data.thresholdType, | ||
| }, | ||
| conditionResult: DetectorPriorityLevel.HIGH, | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Creates escalation conditions based on priority level and available thresholds | ||
| */ | ||
|
|
@@ -303,30 +320,30 @@ function createDataSource(data: MetricDetectorFormData): NewDataSource { | |
| export function metricDetectorFormDataToEndpointPayload( | ||
| data: MetricDetectorFormData | ||
| ): MetricDetectorUpdatePayload { | ||
| const conditions = createConditions(data); | ||
| const conditions = | ||
| data.detectionType === 'dynamic' | ||
| ? createAnomalyDetectionCondition(data) | ||
| : createConditions(data); | ||
|
|
||
| const dataSource = createDataSource(data); | ||
|
|
||
| // Create config based on detection type | ||
| let config: MetricDetectorConfig; | ||
| switch (data.detectionType) { | ||
| case 'percent': | ||
| config = { | ||
| thresholdPeriod: 1, | ||
| detectionType: 'percent', | ||
| comparisonDelta: data.conditionComparisonAgo || 3600, | ||
| }; | ||
| break; | ||
| case 'dynamic': | ||
| config = { | ||
| thresholdPeriod: 1, | ||
| detectionType: 'dynamic', | ||
| sensitivity: data.sensitivity, | ||
| }; | ||
| break; | ||
| case 'static': | ||
| default: | ||
| config = { | ||
| thresholdPeriod: 1, | ||
| detectionType: 'static', | ||
| }; | ||
| break; | ||
|
|
@@ -423,6 +440,24 @@ function processDetectorConditions( | |
| }; | ||
| } | ||
|
|
||
| function getAnomalyCondition(detector: MetricDetector): AnomalyDetectionComparison { | ||
| const anomalyCondition = detector.conditionGroup?.conditions?.find( | ||
| condition => condition.type === DataConditionType.ANOMALY_DETECTION | ||
| ); | ||
|
|
||
| const comparison = anomalyCondition?.comparison; | ||
| if (typeof comparison === 'object') { | ||
| return comparison; | ||
| } | ||
|
|
||
| // Fallback to default values | ||
| return { | ||
| sensitivity: AlertRuleSensitivity.MEDIUM, | ||
| seasonality: 'auto', | ||
| thresholdType: AlertRuleThresholdType.ABOVE_AND_BELOW, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Converts a Detector to MetricDetectorFormData for editing | ||
| */ | ||
|
|
@@ -444,6 +479,7 @@ export function metricSavedDetectorToFormData( | |
| : DetectorDataset.SPANS; | ||
|
|
||
| const datasetConfig = getDatasetConfig(dataset); | ||
| const anomalyCondition = getAnomalyCondition(detector); | ||
|
|
||
| return { | ||
| // Core detector fields | ||
|
|
@@ -471,15 +507,8 @@ export function metricSavedDetectorToFormData( | |
| ? detector.config.comparisonDelta | ||
| : DEFAULT_THRESHOLD_METRIC_FORM_DATA.conditionComparisonAgo, | ||
|
|
||
| // Dynamic fields - extract from config for dynamic detectors | ||
| sensitivity: | ||
| detector.config.detectionType === 'dynamic' && defined(detector.config.sensitivity) | ||
| ? detector.config.sensitivity | ||
| : DEFAULT_THRESHOLD_METRIC_FORM_DATA.sensitivity, | ||
| thresholdType: | ||
| detector.config.detectionType === 'dynamic' && | ||
| defined(detector.config.thresholdType) | ||
| ? detector.config.thresholdType | ||
| : DEFAULT_THRESHOLD_METRIC_FORM_DATA.thresholdType, | ||
| // Dynamic fields - extract from anomaly detection condition for dynamic detectors | ||
| sensitivity: anomalyCondition.sensitivity, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also be removed here
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one is sensitivity |
||
| thresholdType: anomalyCondition.thresholdType, | ||
| }; | ||
| } | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.