From 4b54077b2031f1ea770ae5a087d6e022793e418e Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Mon, 29 Apr 2019 15:45:50 +0100 Subject: [PATCH 1/5] Rules to add `missed-SLA` label to bugs past Priority threshold --- .gitlab-ci.yml | 5 ++++ policies/label-missed-sla.yml | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 policies/label-missed-sla.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3dd367c5..a7be2d60 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -129,6 +129,11 @@ schedule:daily:discover: variables: GITLAB_TRIAGE_FILE: policies/discover.yml +schedule:daily:label-missed-sla: + <<: *run-daily + variables: + GITLAB_TRIAGE_FILE: policies/label-missed-sla.yml + .run-weekly: &run-weekly <<: *run only: diff --git a/policies/label-missed-sla.yml b/policies/label-missed-sla.yml new file mode 100644 index 00000000..82339388 --- /dev/null +++ b/policies/label-missed-sla.yml @@ -0,0 +1,54 @@ +resource_rules: + issues: + rules: + - name: Add missed sla label to bugs over SLA threshold + conditions: + state: opened + labels: + - bug + forbidden_labels: + - missed-SLA + ruby: | + priority_regex = /P[1234]/ + + priority_sla_map = { + "P1": 45, + "P2": 120, + "P3": 170, + "P4": 300 + } + + if resource[:labels].grep(priority_regex).present? && labels_chronologically.present? + priority_label = labels_chronologically.reverse_each.find do |label| + label.name.match?(priority_regex) + end + + return false unless priority_label + + sla = priority_sla_map[priority_label.name.to_sym] + + priority_label.added_at < sla.days.ago + end + actions: + labels: + - missed-SLA + comment: | + #{ + priority_regex = /P[1234]/ + + priority_sla_map = { + "P1": 45, + "P2": 120, + "P3": 170, + "P4": 300 + } + + priority_label = labels_chronologically.reverse_each.find do |label| + label.name.match?(priority_regex) + end + + sla = priority_sla_map[priority_label.name.to_sym]; nil + } + + Adding the ~"missed-SLA" label because the ~#{priority_label.name} label was added over #{sla} days ago. + -- GitLab From fb702182b6aab893a0bc4f0f3b3dbf6a6fcf81bd Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Jun 2019 11:31:59 +0000 Subject: [PATCH 2/5] Throttle the API calls as we can be hitting limit --- policies/label-missed-sla.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/policies/label-missed-sla.yml b/policies/label-missed-sla.yml index 82339388..fea0cb15 100644 --- a/policies/label-missed-sla.yml +++ b/policies/label-missed-sla.yml @@ -23,6 +23,8 @@ resource_rules: label.name.match?(priority_regex) end + sleep(0.05) + return false unless priority_label sla = priority_sla_map[priority_label.name.to_sym] @@ -47,6 +49,8 @@ resource_rules: label.name.match?(priority_regex) end + sleep(0.05) + sla = priority_sla_map[priority_label.name.to_sym]; nil } -- GitLab From 86004f9c2df14a698514852562b3dbc888149edb Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Mon, 10 Jun 2019 13:54:33 +0100 Subject: [PATCH 3/5] Move to SLO over SLA --- .gitlab-ci.yml | 4 ++-- ...bel-missed-sla.yml => label-missed-slo.yml} | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) rename policies/{label-missed-sla.yml => label-missed-slo.yml} (69%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a7be2d60..10c03148 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -129,10 +129,10 @@ schedule:daily:discover: variables: GITLAB_TRIAGE_FILE: policies/discover.yml -schedule:daily:label-missed-sla: +schedule:daily:label-missed-slo: <<: *run-daily variables: - GITLAB_TRIAGE_FILE: policies/label-missed-sla.yml + GITLAB_TRIAGE_FILE: policies/label-missed-slo.yml .run-weekly: &run-weekly <<: *run diff --git a/policies/label-missed-sla.yml b/policies/label-missed-slo.yml similarity index 69% rename from policies/label-missed-sla.yml rename to policies/label-missed-slo.yml index fea0cb15..7e190d72 100644 --- a/policies/label-missed-sla.yml +++ b/policies/label-missed-slo.yml @@ -1,17 +1,17 @@ resource_rules: issues: rules: - - name: Add missed sla label to bugs over SLA threshold + - name: Add missed slo label to bugs over SLO threshold conditions: state: opened labels: - bug forbidden_labels: - - missed-SLA + - missed-SLO ruby: | priority_regex = /P[1234]/ - priority_sla_map = { + priority_slo_map = { "P1": 45, "P2": 120, "P3": 170, @@ -27,18 +27,18 @@ resource_rules: return false unless priority_label - sla = priority_sla_map[priority_label.name.to_sym] + slo = priority_slo_map[priority_label.name.to_sym] - priority_label.added_at < sla.days.ago + priority_label.added_at < slo.days.ago end actions: labels: - - missed-SLA + - missed-SLO comment: | #{ priority_regex = /P[1234]/ - priority_sla_map = { + priority_slo_map = { "P1": 45, "P2": 120, "P3": 170, @@ -51,8 +51,8 @@ resource_rules: sleep(0.05) - sla = priority_sla_map[priority_label.name.to_sym]; nil + slo = priority_slo_map[priority_label.name.to_sym]; nil } - Adding the ~"missed-SLA" label because the ~#{priority_label.name} label was added over #{sla} days ago. + Adding the ~"missed-SLO" label because the ~#{priority_label.name} label was added over #{slo} days ago. -- GitLab From 0beb2f95b2a6c889dad8f16dc0471949b20a5386 Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Tue, 11 Jun 2019 11:17:42 +0100 Subject: [PATCH 4/5] Revise SLO lengths, remove P4 --- policies/label-missed-slo.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/policies/label-missed-slo.yml b/policies/label-missed-slo.yml index 7e190d72..bfe02e0b 100644 --- a/policies/label-missed-slo.yml +++ b/policies/label-missed-slo.yml @@ -9,13 +9,12 @@ resource_rules: forbidden_labels: - missed-SLO ruby: | - priority_regex = /P[1234]/ + priority_regex = /P[123]/ priority_slo_map = { - "P1": 45, - "P2": 120, - "P3": 170, - "P4": 300 + "P1": 30, + "P2": 60, + "P3": 90 } if resource[:labels].grep(priority_regex).present? && labels_chronologically.present? @@ -36,13 +35,12 @@ resource_rules: - missed-SLO comment: | #{ - priority_regex = /P[1234]/ + priority_regex = /P[123]/ priority_slo_map = { - "P1": 45, - "P2": 120, - "P3": 170, - "P4": 300 + "P1": 30, + "P2": 60, + "P3": 90 } priority_label = labels_chronologically.reverse_each.find do |label| -- GitLab From e7257740795c9201def98459d01ff978ed1a1eac Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Mon, 17 Jun 2019 12:10:02 +0100 Subject: [PATCH 5/5] Remove comment about `missed-SLO` label apply --- policies/label-missed-slo.yml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/policies/label-missed-slo.yml b/policies/label-missed-slo.yml index bfe02e0b..948fb7f4 100644 --- a/policies/label-missed-slo.yml +++ b/policies/label-missed-slo.yml @@ -33,24 +33,3 @@ resource_rules: actions: labels: - missed-SLO - comment: | - #{ - priority_regex = /P[123]/ - - priority_slo_map = { - "P1": 30, - "P2": 60, - "P3": 90 - } - - priority_label = labels_chronologically.reverse_each.find do |label| - label.name.match?(priority_regex) - end - - sleep(0.05) - - slo = priority_slo_map[priority_label.name.to_sym]; nil - } - - Adding the ~"missed-SLO" label because the ~#{priority_label.name} label was added over #{slo} days ago. - -- GitLab