Skip to content
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

Initial events API implementation #178

Merged
merged 7 commits into from
Nov 8, 2019
Merged

Initial events API implementation #178

merged 7 commits into from
Nov 8, 2019

Conversation

mattrco
Copy link
Contributor

@mattrco mattrco commented Nov 5, 2019

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
  }
}

@mattrco mattrco added the wip Work in Progress label Nov 5, 2019
@mattrco mattrco force-pushed the mattrco/events-api branch 3 times, most recently from d793a4a to 0cce2ab Compare November 7, 2019 13:53
@mattrco mattrco force-pushed the mattrco/events-api branch 2 times, most recently from 9587f1e to 60450b4 Compare November 7, 2019 16:47
@mattrco mattrco force-pushed the mattrco/events-api branch from 23c15a8 to d5083d4 Compare November 8, 2019 10:40
@mattrco mattrco removed the wip Work in Progress label Nov 8, 2019
@mattrco mattrco requested a review from ChrisAnn November 8, 2019 10:44
event_type = models.CharField(max_length=50)
payload = models.TextField()

def save(self, *args, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could add a getter here that parses the payload and returns a native dict, but since events are write-only this isn't currently needed.

Copy link
Contributor

@ChrisAnn ChrisAnn left a comment

Choose a reason for hiding this comment

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

🚀

@mattrco mattrco merged commit 38ad3ec into master Nov 8, 2019
@mattrco mattrco deleted the mattrco/events-api branch November 8, 2019 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants