Skip to content

feat(ACI): Handle anomaly detection data condition in validator #93886

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 5 commits into from
Jun 24, 2025

Conversation

ceorourke
Copy link
Member

Update the metric issue validator to handle anomaly detection data condition input - the main difference with these is that comparison is a dictionary rather than a number.

@ceorourke ceorourke requested review from a team as code owners June 18, 2025 23:09
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 18, 2025
Comment on lines +46 to +47
if isinstance(self.initial_data, list) and self.initial_data:
return self.initial_data[0].get("type")
Copy link
Member Author

Choose a reason for hiding this comment

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

self.initial_data is a list of conditions in some cases (e.g. the case where we're subclassing it for the MetricIssueComparisonConditionValidator)

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be a silly question, but how do we know to get the type using for index 0? I'm assuming we know there's only one condition in the list?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit of an assumption yeah - for anomaly detection we may have 2 data conditions but their type would both be 'anomaly detection'. I don't think we'd ever have a case where we have 1 anomaly detection data condition and 1 of another type, right?

Copy link

codecov bot commented Jun 19, 2025

Codecov Report

Attention: Patch coverage is 96.66667% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/incidents/metric_issue_detector.py 83.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #93886       +/-   ##
===========================================
+ Coverage   76.56%   88.03%   +11.46%     
===========================================
  Files       10338    10333        -5     
  Lines      597261   598430     +1169     
  Branches    23193    23193               
===========================================
+ Hits       457316   526844    +69528     
+ Misses     139484    71125    -68359     
  Partials      461      461               

Copy link
Contributor

@mifu67 mifu67 left a comment

Choose a reason for hiding this comment

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

Left a couple questions but this looks good to me—if the questions are unrelated to the PR, feel free to merge!

Comment on lines +46 to +47
if isinstance(self.initial_data, list) and self.initial_data:
return self.initial_data[0].get("type")
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be a silly question, but how do we know to get the type using for index 0? I'm assuming we know there's only one condition in the list?

AbstractDataConditionValidator[float, DetectorPriorityLevel]
):
supported_conditions = frozenset((Condition.GREATER, Condition.LESS))
class MetricIssueComparisonConditionValidator(BaseDataConditionValidator):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the switch to BaseDataConditionValidator here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did this because I need to use the base class's validate_comparison method (line 49) for dict input

"condition_result": 25,
"condition_group_id": self.data_condition_group.id,
**self.valid_data,
"conditionResult": 25,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this change from snake case to camel case?

Copy link
Member Author

Choose a reason for hiding this comment

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

good question, it's a mix of both throughout the payloads of many tests 🤔 updated to just be all camel

@ceorourke ceorourke merged commit 3129f1a into master Jun 24, 2025
64 checks passed
@ceorourke ceorourke deleted the ceorourke/anom-detect-validator-tests branch June 24, 2025 21:30
@github-actions github-actions bot locked and limited conversation to collaborators Jul 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants