Skip to content

✨ feat(aci): Update EvidenceData to match Stateful Detector Evidence Data #93676

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 6 commits into from
Jun 17, 2025

Conversation

iamrajjoshi
Copy link
Member

Updates the EvidenceData dataclass to match what the StatefuleDetector adds to the IssueOccurrence for evidence data.

Also updates how the NOA handles and parses this data to fetch the appropriate information

@iamrajjoshi iamrajjoshi self-assigned this Jun 17, 2025
@iamrajjoshi iamrajjoshi requested review from a team as code owners June 17, 2025 01:40
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 17, 2025
Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

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

thanks for also updating the stateful handler! 🎉

@@ -32,7 +32,7 @@


@dataclass
class MetricIssueEvidenceData(EvidenceData):
class MetricIssueEvidenceData(EvidenceData[float]):
Copy link
Contributor

Choose a reason for hiding this comment

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

just want to confirm that it's a float for all metric issues?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, i have dug through a lot of code around this we use float and int interchangeably for typing in this area, but based on queries i have ran and some issues i have seen in the past, the correct type is float

Comment on lines 105 to 117
for condition in evidence_data.conditions:
# The condition.condition_result is of type DetectorPriorityLevel
if (
condition["condition_result"]
== PRIORITY_LEVEL_TO_DETECTOR_PRIORITY_LEVEL[PriorityLevel(priority_level)]
):
threshold_type = fetch_threshold_type(Condition(condition["type"]))
resolve_threshold = fetch_resolve_threshold(condition["comparison"], group_status)
alert_threshold = fetch_alert_threshold(condition["comparison"], group_status)
sensitivity = fetch_sensitivity(condition)
break
else:
raise ValueError("No threshold type found for metric issues")
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 i wonder if we could split this up a little differently, first finding the condition that we care about, then getting the information about it.

target_priority = PRIORITY_LEVEL_TO_DETECTOR_PRIORITY_LEVEL[PriorityLevel(priority_level)]

try:
    condition = next(
        cond for cond in evidence_data.conditions 
        if cond["condition_result"] == target_priority
    )
    threshold_type = fetch_threshold_type(Condition(condition["type"]))
    resolve_threshold = fetch_resolve_threshold(condition["comparison"], group_status)
    alert_threshold = fetch_alert_threshold(condition["comparison"], group_status)
    sensitivity = fetch_sensitivity(condition)
except StopIteration:
    # thrown by `next` if no value is found
    raise ValueError("No threshold type found for metric issues")

This works more or less the same way as you have it, but it will find the condition we care about, then we can find values. (more info about next here)

@@ -486,6 +487,7 @@ def _create_decorated_issue_occurrence(
**detector_occurrence.evidence_data,
"detector_id": self.detector.id,
"value": new_priority,
"data_source_id": data_packet.source_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 we should probably come up with a different name for this, data_packet_source_id? i fear data_source_id will be confused with DataSource.id -- if we include packet it will also be clear that this is coming from the evaluation of a single data packet.

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 point, i think data_packet_source_id is good

Copy link

codecov bot commented Jun 17, 2025

Codecov Report

Attention: Patch coverage is 83.87097% with 5 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/incidents/typings/metric_detector.py 79.16% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #93676      +/-   ##
==========================================
+ Coverage   88.02%   88.03%   +0.01%     
==========================================
  Files       10328    10327       -1     
  Lines      596000   595765     -235     
  Branches    23154    23108      -46     
==========================================
- Hits       524638   524505     -133     
+ Misses      70869    70767     -102     
  Partials      493      493              

Copy link
Member

@ceorourke ceorourke left a comment

Choose a reason for hiding this comment

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

looks good and I can see you took josh's feedback so I don't feel like I am clobbering his review by approving 😅

@iamrajjoshi iamrajjoshi enabled auto-merge (squash) June 17, 2025 17:33
@iamrajjoshi iamrajjoshi merged commit 0cd8f21 into master Jun 17, 2025
64 checks passed
@iamrajjoshi iamrajjoshi deleted the raj/update-stateful-detector-evidence-data branch June 17, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants