-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(aci milestone 3): anomaly detection condition handler #88647
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
base: master
Are you sure you want to change the base?
Conversation
src/sentry/workflow_engine/handlers/condition/anomaly_detection_handler.py
Outdated
Show resolved
Hide resolved
src/sentry/workflow_engine/handlers/condition/anomaly_detection_handler.py
Outdated
Show resolved
Hide resolved
src/sentry/workflow_engine/handlers/condition/anomaly_detection_handler.py
Outdated
Show resolved
Hide resolved
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this file to the incidents
directory.
@@ -5,6 +5,7 @@ | |||
from typing import Any | |||
|
|||
from sentry import features | |||
from sentry.incidents.handlers.condition import * # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imported so that the condition handler gets added to the registry. Maybe there's a better solution?
src/sentry/incidents/handlers/condition/anomaly_detection_handler.py
Outdated
Show resolved
Hide resolved
|
||
|
||
# placeholder until we create this in the workflow engine model | ||
class DetectorError(Exception): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling this out as a TODO (need to add it to the workflow engine + build exception handling for it within process_detectors
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could live in either sentry/workflow_engine/processors/detector.py
or a new utils file in the same dir?
SEER_ANOMALY_DETECTION_ENDPOINT_URL, | ||
json.dumps(detect_anomalies_request).encode("utf-8"), | ||
) | ||
except (TimeoutError, MaxRetryError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything below this line is error handling (copied from the legacy method)
src/sentry/incidents/handlers/condition/anomaly_detection_handler.py
Outdated
Show resolved
Hide resolved
src/sentry/incidents/handlers/condition/anomaly_detection_handler.py
Outdated
Show resolved
Hide resolved
# covers both None and [] | ||
if not anomaly_data: | ||
# something went wrong during evaluation | ||
raise DetectorError("Error during Seer data evaluation process.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this return False instead of raising an exception, if you're going to build exception handling for it? what's the outcome of the exception handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want this to raise an error instead of returning False, because returning False indicates that we should set the detector priority level to OK.
I think we actually want to change this condition handler to emit multiple detector priority levels according to the anomaly detection result 🤔
threshold_type = comparison["threshold_type"] | ||
confidence = comparison["confidence"] | ||
|
||
subscription: QuerySubscription = QuerySubscription.objects.get(id=update.source_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have handling around this in case it doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's let it fail loudly—I don't think this should happen.
|
||
|
||
# placeholder until we create this in the workflow engine model | ||
class DetectorError(Exception): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could live in either sentry/workflow_engine/processors/detector.py
or a new utils file in the same dir?
sensitivity = comparison["sensitivity"] | ||
seasonality = comparison["seasonality"] | ||
threshold_type = comparison["threshold_type"] | ||
confidence = comparison["confidence"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What else is in comparison
? I'm wondering if we could just pass that var to get_anomaly_data_from_seer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's a good idea—I'd be open to it.
}, | ||
) | ||
return None | ||
return ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add tests for this method? Probably can mostly copy/paste from the existing ones, just don't wanna lose the coverage when we delete the old stuff.
"seasonality": AnomalyDetectionSeasonality.AUTO, | ||
"threshold_type": AnomalyDetectionThresholdType.ABOVE_AND_BELOW, | ||
}, | ||
condition_result=DetectorPriorityLevel.HIGH, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saponifi3d calling out that we want this data condition to emit whatever the result of evaluate_value()
is, not a static condition result.
) -> list[TimeSeriesPoint] | None: | ||
snuba_query: SnubaQuery = subscription.snuba_query | ||
aggregation_value = subscription_update["values"].get("value") | ||
source_id = subscription.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we're passing in the query subscription, we don't need to pass source_id and source_type.
Create a condition handler for Anomaly Detection detector triggers. This data condition takes in a data packet and passes if the Seer evaluation corresponds to its condition result.