fix(hc): Change send_incident_alert_notification to take raw JSON#54592
Conversation
Resolve a TODO comment to remove the use of `Mapping[str, Any]` as a parameter. The `Any` would be a problem because it can't be cleanly represented in a JSON schema and won't stop callers from passing non-serializable values. Because the incident attachment is treated as an arbitrary JSON blob, have the RPC method take an arbitrary string containing JSON, which is loaded on the other side. The string is presumed to contain valid JSON syntax, and will cause a server-side exception otherwise.
|
Passing arbitrary JSON blobs around is never my first choice, but I think it's acceptable in this case because the pre-RPC code is already treating it as such -- creating it in The alternative would be to create an To give you a sense of scale, here's an example of the JSON object from a unit test: {
"metric_alert": {
"id": "1",
"identifier": "1",
"organization_id": "4552430653538320",
"projects": ["bar"],
"alert_rule": {
"id": "2",
"name": "Real Swift",
"organization_id": "4552430653538320",
"status": 0,
"query_type": 0,
"dataset": "events",
"query": "level:error",
"aggregate": "count()",
"threshold_type": 0,
"resolve_threshold": null,
"time_window": 10.0,
"environment": null,
"resolution": 1.0,
"threshold_period": 1,
"triggers": [],
"projects": ["bar"],
"include_all_projects": false,
"owner": null,
"original_alert_rule_id": null,
"comparison_delta": null,
"date_modified": "2023-08-10T20:52:08.485958Z",
"date_created": "2023-08-10T20:52:08.485958Z",
"created_by": null
},
"activities": null,
"seen_by": null,
"has_seen": null,
"status": 2,
"status_method": 3,
"type": 2,
"title": "Nearby Bluegill",
"date_started": "2023-08-10T20:52:08.485958Z",
"date_detected": "2023-08-10T20:52:08.485958Z",
"date_created": "2023-08-10T20:52:08.485958Z",
"date_closed": null
},
"description_text": "1000 events in the last 10 minutes",
"description_title": "Resolved: Real Swift",
"web_url": "http://testserver/organizations/baz/alerts/rules/details/2/?alert=1"
}That's a lot of fields to represent in |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #54592 +/- ##
=======================================
Coverage 79.78% 79.78%
=======================================
Files 5000 5000
Lines 212244 212244
Branches 36162 36162
=======================================
+ Hits 169330 169335 +5
+ Misses 37706 37702 -4
+ Partials 5208 5207 -1
|
|
I agree. When in doubt, I think the principle of |
Resolve a TODO comment to remove the use of
Mapping[str, Any]as a parameter. TheAnywould be a problem because it can't be cleanly represented in a JSON schema and won't stop callers from passing non-serializable values.Because the incident attachment is treated as an arbitrary JSON blob, have the RPC method take an arbitrary string containing JSON, which is loaded on the other side. The string is presumed to contain valid JSON syntax, and will cause a server-side exception otherwise.