You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ka...@apache.org on 2023/05/18 22:08:33 UTC
[incubator-devlake] branch release-v0.17 updated: [fix-5233]: Pagerduty MTTR computation fix (#5229)
This is an automated email from the ASF dual-hosted git repository.
ka94 pushed a commit to branch release-v0.17
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v0.17 by this push:
new d997a6ea9 [fix-5233]: Pagerduty MTTR computation fix (#5229)
d997a6ea9 is described below
commit d997a6ea97754fef3851d5b9c1477f0436be5db5
Author: Keon Amini <ke...@merico.dev>
AuthorDate: Thu May 18 17:06:43 2023 -0500
[fix-5233]: Pagerduty MTTR computation fix (#5229)
* fix: Pagerduty now writes to the boards tables to correctly compute MTTR for DORA
* fix: remove cicd scope
---
backend/plugins/pagerduty/impl/impl.go | 1 +
.../plugins/pagerduty/tasks/incidents_converter.go | 6 ++
.../plugins/pagerduty/tasks/service_converter.go | 81 ++++++++++++++++++++++
3 files changed, 88 insertions(+)
diff --git a/backend/plugins/pagerduty/impl/impl.go b/backend/plugins/pagerduty/impl/impl.go
index d669e7e82..6362ba4c0 100644
--- a/backend/plugins/pagerduty/impl/impl.go
+++ b/backend/plugins/pagerduty/impl/impl.go
@@ -54,6 +54,7 @@ func (p PagerDuty) SubTaskMetas() []plugin.SubTaskMeta {
tasks.CollectIncidentsMeta,
tasks.ExtractIncidentsMeta,
tasks.ConvertIncidentsMeta,
+ tasks.ConvertServicesMeta,
}
}
diff --git a/backend/plugins/pagerduty/tasks/incidents_converter.go b/backend/plugins/pagerduty/tasks/incidents_converter.go
index 4f1d4bc9a..2c7f8895a 100644
--- a/backend/plugins/pagerduty/tasks/incidents_converter.go
+++ b/backend/plugins/pagerduty/tasks/incidents_converter.go
@@ -66,6 +66,7 @@ func ConvertIncidents(taskCtx plugin.SubTaskContext) errors.Error {
defer cursor.Close()
seenIncidents := map[int]*IncidentWithUser{}
idGen := didgen.NewDomainIdGenerator(&models.Incident{})
+ serviceIdGen := didgen.NewDomainIdGenerator(&models.Service{})
converter, err := api.NewDataConverter(api.DataConverterArgs{
RawDataSubTaskArgs: api.RawDataSubTaskArgs{
Ctx: taskCtx,
@@ -107,7 +108,12 @@ func ConvertIncidents(taskCtx plugin.SubTaskContext) errors.Error {
AssigneeName: user.Name,
}
seenIncidents[incident.Number] = combined
+ boardIssue := &ticket.BoardIssue{
+ BoardId: serviceIdGen.Generate(data.Options.ConnectionId, data.Options.ServiceId),
+ IssueId: domainIssue.Id,
+ }
return []interface{}{
+ boardIssue,
domainIssue,
}, nil
},
diff --git a/backend/plugins/pagerduty/tasks/service_converter.go b/backend/plugins/pagerduty/tasks/service_converter.go
new file mode 100644
index 000000000..4a6fca4c5
--- /dev/null
+++ b/backend/plugins/pagerduty/tasks/service_converter.go
@@ -0,0 +1,81 @@
+/*
+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 (
+ "github.com/apache/incubator-devlake/core/dal"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/models/domainlayer"
+ "github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
+ "github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
+ "github.com/apache/incubator-devlake/core/plugin"
+ helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/apache/incubator-devlake/plugins/pagerduty/models"
+ "reflect"
+)
+
+func ConvertServices(taskCtx plugin.SubTaskContext) errors.Error {
+ db := taskCtx.GetDal()
+ data := taskCtx.GetData().(*PagerDutyTaskData)
+ rawDataSubTaskArgs := &helper.RawDataSubTaskArgs{
+ Ctx: taskCtx,
+ Options: data.Options,
+ Table: "pagerduty_services",
+ }
+ clauses := []dal.Clause{
+ dal.Select("services.*"),
+ dal.From("_tool_pagerduty_services services"),
+ dal.Where("id = ? and connection_id = ?", data.Options.ServiceId, data.Options.ConnectionId),
+ }
+ cursor, err := db.Cursor(clauses...)
+ if err != nil {
+ return err
+ }
+ defer cursor.Close()
+
+ converter, err := helper.NewDataConverter(helper.DataConverterArgs{
+ RawDataSubTaskArgs: *rawDataSubTaskArgs,
+ InputRowType: reflect.TypeOf(models.Service{}),
+ Input: cursor,
+ Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
+ service := inputRow.(*models.Service)
+ domainBoard := &ticket.Board{
+ DomainEntity: domainlayer.DomainEntity{
+ Id: didgen.NewDomainIdGenerator(service).Generate(service.ConnectionId, service.Id),
+ },
+ Name: service.Name,
+ Url: service.Url,
+ }
+ return []interface{}{
+ domainBoard,
+ }, nil
+ },
+ })
+ if err != nil {
+ return err
+ }
+ return converter.Execute()
+}
+
+var ConvertServicesMeta = plugin.SubTaskMeta{
+ Name: "convertServices",
+ EntryPoint: ConvertServices,
+ EnabledByDefault: true,
+ Description: "Convert PagerDuty services",
+ DomainTypes: []string{plugin.DOMAIN_TYPE_TICKET},
+}