Skip to content

Conversation

@malwilley
Copy link
Member

When viewing the issue details for a metric detector open period, we want to display the query which failed. This adds the serialized data source on the issue occurrence's evidence_data for this purpose. I've done this in a generalized way that should work across all detector types.

@malwilley malwilley requested review from a team as code owners November 18, 2025 19:59
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 18, 2025
@malwilley malwilley force-pushed the malwilley/feat/add-serialized-data-source-to-issue-occurrence-evidence-data branch from e11375b to dfebb5f Compare November 18, 2025 20:02
)
.select_related("workflow_condition_group")
.prefetch_related("workflow_condition_group__conditions")
.prefetch_related("workflow_condition_group__conditions", "data_sources")
Copy link
Member Author

@malwilley malwilley Nov 18, 2025

Choose a reason for hiding this comment

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

Is it okay to prefetch the data sources here as well? Or would it be better to wait and query for this when the occurrence is being generated?

Copy link
Contributor

Choose a reason for hiding this comment

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

it's probably better to do the select when we're generating the issue occurrence.

we only create an occurrence / status change on like 0.5% of the evaluations so it's a bit more efficient to make a second select statement.

we also can't guarantee that other product areas will use this method. for example, uptime fetches their detectors separately, then directly calls process_detectors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense! Pushed that change, we now query for the data source when building the evidence data.

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

❌ Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ntry/workflow_engine/handlers/detector/stateful.py 76.92% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #103549      +/-   ##
===========================================
+ Coverage   80.09%    80.58%   +0.48%     
===========================================
  Files        9256      9259       +3     
  Lines      395241    395378     +137     
  Branches    25207     25207              
===========================================
+ Hits       316581    318609    +2028     
+ Misses      78231     76340    -1891     
  Partials      429       429              

detector_id: int
data_packet_source_id: int
conditions: list[dict[str, Any]]
data_source_definition: dict[str, Any] | None
Copy link
Member Author

Choose a reason for hiding this comment

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

Also wanted to call out that I'm adding a property to this dataclass and I know python will raise an exception when instantiating if it doesn't exist. Is it safe to do this? Want to make sure this won't start failing for old event data when this is merged

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 it should be okay, but might want to set a default value to None to be safe.

afaik, we only apply this dataclass to the write on an issue occurrence, and when we're fetching for the API we just pass it through the serializer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay added a default value, but I agree I think it would probably be okay without one

detector_id: int
data_packet_source_id: int
conditions: list[dict[str, Any]]
data_source_definition: dict[str, Any] | None
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 it should be okay, but might want to set a default value to None to be safe.

afaik, we only apply this dataclass to the write on an issue occurrence, and when we're fetching for the API we just pass it through the serializer.

try:
data_source = DataSource.objects.filter(
detectors=self.detector, source_id=data_packet.source_id
).first()
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 allow this to have multiple data sources rather than limit to the first one. could we just serialize the list of data sources even though it'll generally only be 1? it might also help with debugging to see if there are multiple sources connected or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay makes sense - I thought that because this sent a source_id that meant that only one datasource should match, but if that's not the case the list makes sense. Updated

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.

woohoo! thanks for all those changes.

@malwilley malwilley enabled auto-merge (squash) November 21, 2025 18:26
@malwilley malwilley merged commit 5d54957 into master Nov 21, 2025
66 checks passed
@malwilley malwilley deleted the malwilley/feat/add-serialized-data-source-to-issue-occurrence-evidence-data branch November 21, 2025 18:27
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