-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat(ACI): Detector details PUT endpoint #84098
Conversation
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## master #84098 +/- ##
==========================================
+ Coverage 87.97% 87.99% +0.01%
==========================================
Files 9631 9632 +1
Lines 543870 545756 +1886
Branches 21089 21089
==========================================
+ Hits 478492 480241 +1749
- Misses 65075 65212 +137
Partials 303 303 |
394cdec
to
4330776
Compare
3137949
to
ec4b7fe
Compare
22b212a
to
c9992a3
Compare
c9992a3
to
2ab2d9c
Compare
449820d
to
12075bf
Compare
src/sentry/workflow_engine/endpoints/project_detector_details.py
Outdated
Show resolved
Hide resolved
src/sentry/workflow_engine/endpoints/validators/metric_alert_detector.py
Show resolved
Hide resolved
def update_data_source(self, instance, data_source): | ||
try: | ||
source_instance = DataSource.objects.get(detector=instance) | ||
except DataSource.DoesNotExist: |
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.
does the data source need to be created if you add it to an existing detector?
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.
I am not sure if that scenario would be possible in the UI, I believe you're always creating both a data source and a detector at the same time
def update(self, instance, validated_data): | ||
instance.name = validated_data.get("name", instance.name) | ||
instance.type = validated_data.get("detector_type", instance.group_type).slug | ||
condition_group = validated_data.pop("condition_group") |
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.
nit: is there a reason this is pop
instead of get
?
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.
🤔 I wanna say I had a reason at one point but I don't think it applies anymore
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.
oh wait the reason is because when I call instance.save()
the instance here is a Detector
and if I have the dict of condition group data that's bad cause it's not data that gets saved to that model
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 be the Detector.workflow_condition_group
or is this just because of the API -> models mapping?
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 gets passed here are the data conditions, the condition group doesn't change
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.
taking a step back, is it an anti-pattern to be creating new models in the validator?
just by the naming i would expect a validator to only ensure data exists as expected, not create new models. i'm not super familiar with this layer, so it's def more of a smell than anything for me.
404: RESPONSE_NOT_FOUND, | ||
}, | ||
) | ||
def put(self, request: Request, project: Project, detector: Detector) -> Response: |
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.
i really like how clean these api handlers are so clean and well documented 💯
tests/sentry/workflow_engine/endpoints/test_project_detector_details.py
Outdated
Show resolved
Hide resolved
@@ -1,12 +1,17 @@ | |||
from datetime import timedelta |
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.
once this pr is merged, mind if i move this validator to the incidents
directory to colocate it with the detector it's validating?
src/sentry/workflow_engine/endpoints/validators/metric_alert_detector.py
Outdated
Show resolved
Hide resolved
src/sentry/workflow_engine/endpoints/validators/metric_alert_detector.py
Outdated
Show resolved
Hide resolved
query_type=data_source.get("query_type", snuba_query.type), | ||
dataset=data_source.get("dataset", snuba_query.dataset), | ||
query=data_source.get("query", snuba_query.query), | ||
aggregate=data_source.get("aggregate", snuba_query.aggregate), | ||
time_window=timedelta(minutes=data_source.get("time_window", snuba_query.time_window)), | ||
resolution=timedelta(seconds=data_source.get("resolution", snuba_query.resolution)), | ||
environment=data_source.get("environment", snuba_query.environment), | ||
event_types=data_source.get("event_types", [event_types]), |
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.
🤔 the data_source won't have these attributes, it's just the lookup like you have on line 87.
is this like new_snuba_query
rather than data_source
?
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.
I think I based this off of https://github.com/getsentry/sentry/blob/master/tests/sentry/workflow_engine/endpoints/test_project_detector_index.py#L62-L70 and https://www.notion.so/sentry/UI-APIs-1888b10e4b5d80dfa47fcbffa2a7c9af?pvs=4#1928b10e4b5d801da849e25bc24915f3 - we'd need all of this information if the snuba query is changing. Do you feel strongly about renaming it? I'll have to check with Nate to make sure he's aware that it'll be changing.
src/sentry/workflow_engine/endpoints/validators/metric_alert_detector.py
Outdated
Show resolved
Hide resolved
def update(self, instance, validated_data): | ||
instance.name = validated_data.get("name", instance.name) | ||
instance.type = validated_data.get("detector_type", instance.group_type).slug | ||
condition_group = validated_data.pop("condition_group") |
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 be the Detector.workflow_condition_group
or is this just because of the API -> models mapping?
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.
lgtm - we can update the nits in upcoming work.
class DataConditionType(TypedDict): | ||
id: int | None | ||
comparison: int | ||
type: Condition | ||
condition_result: DetectorPriorityLevel | ||
condition_group_id: int |
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 be in workflow_engine/types.py
? (we can update later)
condition_group_id: int | ||
|
||
|
||
class DataSourceType(TypedDict): |
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.
Since this seems to be specific to snuba query's as the data source:
class DataSourceType(TypedDict): | |
class SnubaQueryDataSourceType(TypedDict): |
Create a PUT endpoint for detector details.
Addresses https://getsentry.atlassian.net/browse/ACI-114