Skip to content

Allow incident severity updates to trigger issue webhooks

Sarah Yasonik requested to merge sy-add-incident-webhooks-for-severity into master

What does this MR do?

Related issue: #333774 (closed)

This MR allows changes to an incident's severity to trigger the issue webhooks.

As a side-effect, I also removed the severity system note on incident creation, as the user isn't actually in control of the severity that the incident is initialized with. Now we only create a severity-related system note when the severity is changed by a user.

Testing

  1. Setup a webhook receiver https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#example-webhook-receiver
  2. Setup a webhook which pushes Issues events at Settings > Webhooks
  3. Create a new incident (New Issue w/ type=Incident || Monitor > Incidents)
    • See the request come into the receiver: severity should be an attribute in the body
    • A system note should not be created for the severity
  4. Update the severity of the incident
    • See the request come into the receiver: severity should be present under the "changes" as well as in the body
    • A system note should be created for the severity change
  5. Change another attribute on the incident (like milestone or labels)
    • See the request come into the receiver: severity should not be present under "changes"

Other issuables/interactions:

  • For non-incident issues, severity should be present in the webhook payload with a constant value of "unknown"
  • For MRs, severity should not be present in the webhook payload
  • For incidents created from alerts, the severity should be set to match the alert's severity at creation-time
UI interactions
About to create incident Created incident About to update severity Updated severity About to update milestone Updated milestone
Screen_Shot_2021-06-24_at_1.51.38_PM Screen_Shot_2021-06-24_at_1.51.57_PM Screen_Shot_2021-06-24_at_1.52.11_PM Screen_Shot_2021-06-24_at_1.52.24_PM Screen_Shot_2021-06-24_at_1.53.55_PM Screen_Shot_2021-06-24_at_1.54.03_PM
Webhook receiver output
% ruby print_http_body.rb 8300
[2021-06-24 13:50:23] INFO  WEBrick 1.6.1
[2021-06-24 13:50:23] INFO  ruby 2.7.2 (2020-10-01) [x86_64-darwin20]
[2021-06-24 13:50:23] INFO  WEBrick::HTTPServer#start: pid=22916 port=8300
{"object_kind":"issue","event_type":"issue","user":{"id":1,"name":"Administrator","username":"root","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","email":"admin@example.com"},"project":{"id":21,"name":"autodevops","description":"","web_url":"http://192.168.0.202:3000/root/autodevops","avatar_url":null,"git_ssh_url":"ssh://git@192.168.0.202:2222/root/autodevops.git","git_http_url":"http://192.168.0.202:3000/root/autodevops.git","namespace":"Administrator","visibility_level":20,"path_with_namespace":"root/autodevops","default_branch":"master","ci_config_path":null,"homepage":"http://192.168.0.202:3000/root/autodevops","url":"ssh://git@192.168.0.202:2222/root/autodevops.git","ssh_url":"ssh://git@192.168.0.202:2222/root/autodevops.git","http_url":"http://192.168.0.202:3000/root/autodevops.git"},"object_attributes":{"author_id":1,"closed_at":null,"confidential":false,"created_at":"2021-06-24 17:51:40 UTC","description":"","discussion_locked":null,"due_date":null,"id":657,"iid":179,"last_edited_at":null,"last_edited_by_id":null,"milestone_id":59,"moved_to_id":null,"duplicated_to_id":null,"project_id":21,"relative_position":null,"state_id":1,"time_estimate":0,"title":"This is a new incident for which I will update the severity after creation","updated_at":"2021-06-24 17:51:40 UTC","updated_by_id":null,"weight":null,"url":"http://192.168.0.202:3000/root/autodevops/-/issues/179","total_time_spent":0,"time_change":0,"human_total_time_spent":null,"human_time_change":null,"human_time_estimate":null,"assignee_ids":[],"assignee_id":null,"labels":[{"id":109,"title":"incident","color":"#CC0033","project_id":21,"created_at":"2020-07-08 19:11:20 UTC","updated_at":"2020-07-08 19:11:20 UTC","template":false,"description":"Denotes a disruption to IT services and the associated issues require immediate attention","type":"ProjectLabel","group_id":null,"remove_on_close":false}],"state":"opened","severity":"unknown","action":"open"},"labels":[{"id":109,"title":"incident","color":"#CC0033","project_id":21,"created_at":"2020-07-08 19:11:20 UTC","updated_at":"2020-07-08 19:11:20 UTC","template":false,"description":"Denotes a disruption to IT services and the associated issues require immediate attention","type":"ProjectLabel","group_id":null,"remove_on_close":false}],"changes":{"author_id":{"previous":null,"current":1},"created_at":{"previous":null,"current":"2021-06-24 17:51:40 UTC"},"description":{"previous":null,"current":""},"id":{"previous":null,"current":657},"iid":{"previous":null,"current":179},"milestone_id":{"previous":null,"current":59},"project_id":{"previous":null,"current":21},"title":{"previous":null,"current":"This is a new incident for which I will update the severity after creation"},"updated_at":{"previous":null,"current":"2021-06-24 17:51:40 UTC"}},"repository":{"name":"autodevops","url":"ssh://git@192.168.0.202:2222/root/autodevops.git","description":"","homepage":"http://192.168.0.202:3000/root/autodevops"}}
::1 - - [24/Jun/2021:13:51:46 EDT] "POST / HTTP/1.1" 200 0
- -> /
{"object_kind":"issue","event_type":"issue","user":{"id":1,"name":"Administrator","username":"root","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","email":"admin@example.com"},"project":{"id":21,"name":"autodevops","description":"","web_url":"http://192.168.0.202:3000/root/autodevops","avatar_url":null,"git_ssh_url":"ssh://git@192.168.0.202:2222/root/autodevops.git","git_http_url":"http://192.168.0.202:3000/root/autodevops.git","namespace":"Administrator","visibility_level":20,"path_with_namespace":"root/autodevops","default_branch":"master","ci_config_path":null,"homepage":"http://192.168.0.202:3000/root/autodevops","url":"ssh://git@192.168.0.202:2222/root/autodevops.git","ssh_url":"ssh://git@192.168.0.202:2222/root/autodevops.git","http_url":"http://192.168.0.202:3000/root/autodevops.git"},"object_attributes":{"author_id":1,"closed_at":null,"confidential":false,"created_at":"2021-06-24 17:51:40 UTC","description":"","discussion_locked":null,"due_date":null,"id":657,"iid":179,"last_edited_at":null,"last_edited_by_id":null,"milestone_id":59,"moved_to_id":null,"duplicated_to_id":null,"project_id":21,"relative_position":1879128549,"state_id":1,"time_estimate":0,"title":"This is a new incident for which I will update the severity after creation","updated_at":"2021-06-24 17:52:13 UTC","updated_by_id":1,"weight":null,"url":"http://192.168.0.202:3000/root/autodevops/-/issues/179","total_time_spent":0,"time_change":0,"human_total_time_spent":null,"human_time_change":null,"human_time_estimate":null,"assignee_ids":[],"assignee_id":null,"labels":[{"id":109,"title":"incident","color":"#CC0033","project_id":21,"created_at":"2020-07-08 19:11:20 UTC","updated_at":"2020-07-08 19:11:20 UTC","template":false,"description":"Denotes a disruption to IT services and the associated issues require immediate attention","type":"ProjectLabel","group_id":null,"remove_on_close":false}],"state":"opened","severity":"high","action":"update"},"labels":[{"id":109,"title":"incident","color":"#CC0033","project_id":21,"created_at":"2020-07-08 19:11:20 UTC","updated_at":"2020-07-08 19:11:20 UTC","template":false,"description":"Denotes a disruption to IT services and the associated issues require immediate attention","type":"ProjectLabel","group_id":null,"remove_on_close":false}],"changes":{"updated_at":{"previous":"2021-06-24 17:51:40 UTC","current":"2021-06-24 17:52:13 UTC"},"updated_by_id":{"previous":null,"current":1},"severity":{"previous":"unknown","current":"high"}},"repository":{"name":"autodevops","url":"ssh://git@192.168.0.202:2222/root/autodevops.git","description":"","homepage":"http://192.168.0.202:3000/root/autodevops"}}
::1 - - [24/Jun/2021:13:52:16 EDT] "POST / HTTP/1.1" 200 0
- -> /
{"object_kind":"issue","event_type":"issue","user":{"id":1,"name":"Administrator","username":"root","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","email":"admin@example.com"},"project":{"id":21,"name":"autodevops","description":"","web_url":"http://192.168.0.202:3000/root/autodevops","avatar_url":null,"git_ssh_url":"ssh://git@192.168.0.202:2222/root/autodevops.git","git_http_url":"http://192.168.0.202:3000/root/autodevops.git","namespace":"Administrator","visibility_level":20,"path_with_namespace":"root/autodevops","default_branch":"master","ci_config_path":null,"homepage":"http://192.168.0.202:3000/root/autodevops","url":"ssh://git@192.168.0.202:2222/root/autodevops.git","ssh_url":"ssh://git@192.168.0.202:2222/root/autodevops.git","http_url":"http://192.168.0.202:3000/root/autodevops.git"},"object_attributes":{"author_id":1,"closed_at":null,"confidential":false,"created_at":"2021-06-24 17:51:40 UTC","description":"","discussion_locked":null,"due_date":null,"id":657,"iid":179,"last_edited_at":null,"last_edited_by_id":null,"milestone_id":null,"moved_to_id":null,"duplicated_to_id":null,"project_id":21,"relative_position":1879128549,"state_id":1,"time_estimate":0,"title":"This is a new incident for which I will update the severity after creation","updated_at":"2021-06-24 17:53:57 UTC","updated_by_id":1,"weight":null,"url":"http://192.168.0.202:3000/root/autodevops/-/issues/179","total_time_spent":0,"time_change":0,"human_total_time_spent":null,"human_time_change":null,"human_time_estimate":null,"assignee_ids":[],"assignee_id":null,"labels":[{"id":109,"title":"incident","color":"#CC0033","project_id":21,"created_at":"2020-07-08 19:11:20 UTC","updated_at":"2020-07-08 19:11:20 UTC","template":false,"description":"Denotes a disruption to IT services and the associated issues require immediate attention","type":"ProjectLabel","group_id":null,"remove_on_close":false}],"state":"opened","severity":"high","action":"update"},"labels":[{"id":109,"title":"incident","color":"#CC0033","project_id":21,"created_at":"2020-07-08 19:11:20 UTC","updated_at":"2020-07-08 19:11:20 UTC","template":false,"description":"Denotes a disruption to IT services and the associated issues require immediate attention","type":"ProjectLabel","group_id":null,"remove_on_close":false}],"changes":{"milestone_id":{"previous":59,"current":null},"updated_at":{"previous":"2021-06-24 17:52:13 UTC","current":"2021-06-24 17:53:57 UTC"}},"repository":{"name":"autodevops","url":"ssh://git@192.168.0.202:2222/root/autodevops.git","description":"","homepage":"http://192.168.0.202:3000/root/autodevops"}}
::1 - - [24/Jun/2021:13:54:02 EDT] "POST / HTTP/1.1" 200 0
- -> /

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Michael Kozono

Merge request reports

Loading