Skip to content

Add Missed SLA label via Cron job

Sean Arnold requested to merge 241663-incident-sla-cron-job into master

What does this MR do?

This adds a cron job and related services to add a missed::SLA label to the incidents which have missed their given SLA times.

To do this we've added a few services:

  • IncidentManagement::CreateIncidentSlaExceededLabelService - creates the missed::SLA label in the project
  • IncidentManagement::ApplyIncidentSlaExceededLabelService - applies the label to the incidents

This is done via a Cron worker:

  • IncidentManagement::IncidentSlaExceededCheckWorker

To aid this we've added a new database scope to IndcidentSla

  • IncidentSla.exceeded - This finds incident SLAs where the due_at time has expired, and the corresponding Issue is open.

Query for IncidentSla.exceeded scope:

SELECT "incident_slas".* FROM "incident_slas" INNER JOIN "issues" ON "issues"."id" = "incident_slas"."issue_id" WHERE ("issues"."state_id" IN (1)) AND (due_at < '2020-10-08 05:06:27.511481')
Explain: https://explain.depesz.com/s/SNPr
EXPLAIN for: SELECT "incident_slas".* FROM "incident_slas" INNER JOIN "issues" ON "issues"."id" = "incident_slas"."issue_id" WHERE ("issues"."state_id" IN (1)) AND (due_at < '2020-10-08 05:06:27.511481')
                                                                  QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
 Hash Join  (cost=23.53..58.28 rows=272 width=16)
   Hash Cond: (incident_slas.issue_id = issues.id)
   ->  Seq Scan on incident_slas  (cost=0.00..33.12 rows=617 width=16)
         Filter: (due_at < '2020-10-08 05:06:27.511481+00'::timestamp with time zone)
   ->  Hash  (cost=20.91..20.91 rows=210 width=4)
         ->  Index Only Scan using idx_issues_on_project_id_and_updated_at_and_id_and_state_id on issues  (cost=0.27..20.91 rows=210 width=4)
               Index Cond: (state_id = 1)
(7 rows)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • 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

Related to #241663 (closed)

Edited by Sean Arnold

Merge request reports