Commit fd262a4f authored by Sean Arnold's avatar Sean Arnold

Add SLA check cron job

- Update cron queue
- Add service for adding label
- add service for applying label
parent 99e12104
......@@ -574,6 +574,9 @@ Gitlab.ee do
Settings.cron_jobs['historical_data_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['historical_data_worker']['cron'] ||= '0 12 * * *'
Settings.cron_jobs['historical_data_worker']['job_class'] = 'HistoricalDataWorker'
Settings.cron_jobs['incident_sla_exceeded_check_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['incident_sla_exceeded_check_worker']['cron'] ||= '*/2 * * * *'
Settings.cron_jobs['incident_sla_exceeded_check_worker']['job_class'] = 'IncidentManagement::IncidentSlaExceededCheckWorker'
Settings.cron_jobs['import_software_licenses_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['import_software_licenses_worker']['cron'] ||= '0 3 * * 0'
Settings.cron_jobs['import_software_licenses_worker']['job_class'] = 'ImportSoftwareLicensesWorker'
......
# frozen_string_literal: true
module IncidentManagement
class ApplyIncidentSlaExceededLabelService < BaseService
def initialize(incident)
super(incident.project)
@incident = incident
@label = incident_exceeded_label
end
def execute
return if incident.label_ids.include?(label.id)
incident.labels << label
end
private
attr_reader :incident, :label
def incident_exceeded_label
::IncidentManagement::CreateIncidentSlaExceededLabelService
.new(project, current_user)
.execute
.payload[:label]
end
end
end
# frozen_string_literal: true
module IncidentManagement
class CreateIncidentSlaExceededLabelService < BaseService
LABEL_PROPERTIES = {
title: 'SLA exceeded',
color: '#7E6AB0',
description: <<~DESCRIPTION.chomp
This incident was not closed before the SLA (Service Level Agreement) time exceeded
DESCRIPTION
}.freeze
def execute
label = Labels::FindOrCreateService
.new(current_user, project, **LABEL_PROPERTIES)
.execute(skip_authorization: true)
ServiceResponse.success(payload: { label: label })
end
end
end
......@@ -195,6 +195,14 @@
:weight: 1
:idempotent:
:tags: []
- :name: cronjob:incident_management_incident_sla_exceeded_check
:feature_category: :incident_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
:tags: []
- :name: cronjob:ingress_modsecurity_counter_metrics
:feature_category: :web_firewall
:has_external_dependencies: true
......
# frozen_string_literal: true
module IncidentManagement
class IncidentSlaExceededCheckWorker
include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
feature_category :incident_management
def perform
IncidentSla.exceeded.find_in_batches do |incident_slas|
incident_slas.each do |incident_sla|
ApplyIncidentSlaExceededLabelService.new(incident_sla.issue).execute
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment