monzo / response

Monzo's real-time incident response and reporting tool ⚡️
MIT License
1.53k stars 165 forks source link

Initial events API implementation #178

Closed mattrco closed 4 years ago

mattrco commented 4 years ago

When incidents or actions are changed (created, updated) we generate an event log using post_save signals. We intend to consume these events for reporting purposes.

The payload uses a TextField instead of JSON to maintain compatibility across database engines (and make testing easier).

An API smoke test is included.

The post_save signals can be overridden by end users with the *_EVENT_HANDLER_CLASS django settings - once we've tested these a bit more thoroughly they can be added to the readme.

Example incident change:

{
  "id": 74,
  "timestamp": "2019-11-05T18:33:34.236167",
  "event_type": "incident_event",
  "payload": {
    "id": 70,
    "lead": {
      "email": null,
      "app_id": "slack",
      "full_name": "mattrco",
      "external_id": "AAAAAAA",
      "display_name": "mattrco"
    },
    "impact": null,
    "report": "We’re out of milk",
    "summary": null,
    "end_time": null,
    "reporter": {
      "email": null,
      "app_id": "slack",
      "full_name": "mattrco",
      "external_id": "AAAAAA",
      "display_name": "mattrco"
    },
    "severity": "1",
    "is_closed": false,
    "start_time": "2019-11-05T18:33:33.142013",
    "report_only": false,
    "report_time": "2019-11-05T18:33:33.142013",
    "action_items": [],
    "comms_channel": null
  }
}

Example action change:

{
  "id": 75,
  "timestamp": "2019-11-05T18:34:16.715683",
  "event_type": "action_event",
  "payload": {
    "id": 72,
    "done": false,
    "user": {
      "email": null,
      "app_id": "slack",
      "full_name": "mattrco",
      "external_id": "AAAAAA",
      "display_name": "mattrco"
    },
    "details": "Head to the shops pronto",
    "incident_id": 70
  }
}