This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 62ae94bd5 fix(opsgenie): convert closed incidents to DONE with a
resolution date (#9390)
62ae94bd5 is described below
commit 62ae94bd575f4b762d07ade1e60c5de7415b6272
Author: Shivam Sharma <[email protected]>
AuthorDate: Sat Nov 14 12:38:41 2026 +0530
fix(opsgenie): convert closed incidents to DONE with a resolution date
(#9390)
getStatus mapped closed incidents to OTHER, and getTimes only set
resolution_date and lead_time_minutes for resolved ones. A closed
incident is finished like a resolved one, but it ended up in issues
with status OTHER and no resolution date, so metrics that use the
resolution date, such as DORA's failed deployment recovery time,
left it out.
Treat closed like resolved in both functions, and add unit tests.
Fixes #9388
Generated-by: Claude Code (Claude Opus 5.5)
Signed-off-by: Shivam Sharma
<[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../plugins/opsgenie/tasks/incidents_converter.go | 7 +--
.../opsgenie/tasks/incidents_converter_test.go | 61 ++++++++++++++++++++++
2 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/backend/plugins/opsgenie/tasks/incidents_converter.go
b/backend/plugins/opsgenie/tasks/incidents_converter.go
index 50fe1f1ab..1244c14ad 100644
--- a/backend/plugins/opsgenie/tasks/incidents_converter.go
+++ b/backend/plugins/opsgenie/tasks/incidents_converter.go
@@ -147,13 +147,10 @@ func ConvertIncidents(taskCtx plugin.SubTaskContext)
errors.Error {
}
func getStatus(incident *models.Incident) string {
- if incident.Status == models.IncidentStatusClosed {
- return ticket.OTHER
- }
if incident.Status == models.IncidentStatusOpen {
return ticket.IN_PROGRESS
}
- if incident.Status == models.IncidentStatusResolved {
+ if incident.Status == models.IncidentStatusResolved || incident.Status
== models.IncidentStatusClosed {
return ticket.DONE
}
panic("unknown incident status encountered")
@@ -162,7 +159,7 @@ func getStatus(incident *models.Incident) string {
func getTimes(incident *models.Incident) (*uint, *time.Time) {
var leadTime *uint
var resolutionDate *time.Time
- if incident.Status == models.IncidentStatusResolved {
+ if incident.Status == models.IncidentStatusResolved || incident.Status
== models.IncidentStatusClosed {
resolutionDate = &incident.UpdatedDate
temp := uint(resolutionDate.Sub(incident.CreatedDate).Minutes())
leadTime = &temp
diff --git a/backend/plugins/opsgenie/tasks/incidents_converter_test.go
b/backend/plugins/opsgenie/tasks/incidents_converter_test.go
new file mode 100644
index 000000000..b630e1c3a
--- /dev/null
+++ b/backend/plugins/opsgenie/tasks/incidents_converter_test.go
@@ -0,0 +1,61 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+ "testing"
+ "time"
+
+ "github.com/apache/devlake/core/models/domainlayer/ticket"
+ "github.com/apache/devlake/plugins/opsgenie/models"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestGetStatus(t *testing.T) {
+ cases := map[models.IncidentStatus]string{
+ models.IncidentStatusOpen: ticket.IN_PROGRESS,
+ models.IncidentStatusResolved: ticket.DONE,
+ models.IncidentStatusClosed: ticket.DONE,
+ }
+ for status, expected := range cases {
+ t.Run(string(status), func(t *testing.T) {
+ assert.Equal(t, expected,
getStatus(&models.Incident{Status: status}))
+ })
+ }
+}
+
+func TestGetTimes(t *testing.T) {
+ created := time.Date(2023, 9, 5, 18, 20, 0, 0, time.UTC)
+ updated := created.Add(90 * time.Minute)
+
+ for _, status := range
[]models.IncidentStatus{models.IncidentStatusResolved,
models.IncidentStatusClosed} {
+ t.Run(string(status), func(t *testing.T) {
+ leadTime, resolutionDate :=
getTimes(&models.Incident{Status: status, CreatedDate: created, UpdatedDate:
updated})
+ if assert.NotNil(t, resolutionDate) && assert.NotNil(t,
leadTime) {
+ assert.Equal(t, updated, *resolutionDate)
+ assert.Equal(t, uint(90), *leadTime)
+ }
+ })
+ }
+
+ t.Run("open", func(t *testing.T) {
+ leadTime, resolutionDate := getTimes(&models.Incident{Status:
models.IncidentStatusOpen, CreatedDate: created, UpdatedDate: updated})
+ assert.Nil(t, leadTime)
+ assert.Nil(t, resolutionDate)
+ })
+}