You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by he...@apache.org on 2023/05/26 00:19:14 UTC

[incubator-devlake] branch release-v0.17 updated: fix: PagerDuty incident conversion query by service ID (#5281) (#5287)

This is an automated email from the ASF dual-hosted git repository.

hez 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 c8de9da5c fix: PagerDuty incident conversion query by service ID (#5281) (#5287)
c8de9da5c is described below

commit c8de9da5ccbb19da406a24ee8efc3f1faf310730
Author: Keon Amini <ke...@merico.dev>
AuthorDate: Thu May 25 19:19:04 2023 -0500

    fix: PagerDuty incident conversion query by service ID (#5281) (#5287)
    
    ---------
    
    Co-authored-by: Louis.z <lo...@gmail.com>
---
 backend/plugins/pagerduty/api/remote.go            | 106 +--------
 backend/plugins/pagerduty/models/raw/incidents.go  |   2 +-
 backend/plugins/pagerduty/models/raw/services.go   | 248 ++++++---------------
 .../plugins/pagerduty/tasks/incidents_converter.go |   2 +-
 .../plugins/pagerduty/tasks/incidents_extractor.go |   2 +-
 5 files changed, 75 insertions(+), 285 deletions(-)

diff --git a/backend/plugins/pagerduty/api/remote.go b/backend/plugins/pagerduty/api/remote.go
index 6cb4ab064..ea2ceefad 100644
--- a/backend/plugins/pagerduty/api/remote.go
+++ b/backend/plugins/pagerduty/api/remote.go
@@ -26,10 +26,10 @@ import (
 	"github.com/apache/incubator-devlake/core/plugin"
 	"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
 	"github.com/apache/incubator-devlake/plugins/pagerduty/models"
+	"github.com/apache/incubator-devlake/plugins/pagerduty/models/raw"
 	"net/http"
 	"net/url"
 	"strconv"
-	"time"
 )
 
 type RemoteScopesChild struct {
@@ -56,110 +56,16 @@ type PageData struct {
 	PerPage int `json:"per_page"`
 }
 
-type TeamResponse struct {
-	Offset int  `json:"offset"`
-	Limit  int  `json:"limit"`
-	More   bool `json:"more"`
-	Total  int  `json:"total"`
-	Teams  []struct {
-		Id   string `json:"id"`
-		Name string `json:"name"`
-	} `json:"teams"`
-}
-
-type WorkspaceItem struct {
-	//Type string `json:"type"`
-	//Uuid string `json:"uuid"`
-	Slug string `json:"slug"`
-	Name string `json:"name"`
-}
-
-type ReposResponse struct {
-	Pagelen int              `json:"pagelen"`
-	Page    int              `json:"page"`
-	Size    int              `json:"size"`
-	Values  []models.Service `json:"values"`
-}
-
 type ServiceResponse struct {
-	Offset   int  `json:"offset"`
-	Limit    int  `json:"limit"`
-	More     bool `json:"more"`
-	Total    int  `json:"total"`
-	Services []struct {
-		Id                      string    `json:"id"`
-		Summary                 string    `json:"summary"`
-		Type                    string    `json:"type"`
-		Self                    string    `json:"self"`
-		HtmlUrl                 string    `json:"html_url"`
-		Name                    string    `json:"name"`
-		AutoResolveTimeout      int       `json:"auto_resolve_timeout"`
-		AcknowledgementTimeout  int       `json:"acknowledgement_timeout"`
-		CreatedAt               time.Time `json:"created_at"`
-		Status                  string    `json:"status"`
-		AlertCreation           string    `json:"alert_creation"`
-		AlertGroupingParameters struct {
-			Type string `json:"type"`
-		} `json:"alert_grouping_parameters"`
-		Integrations []struct {
-			Id      string `json:"id"`
-			Type    string `json:"type"`
-			Summary string `json:"summary"`
-			Self    string `json:"self"`
-			HtmlUrl string `json:"html_url"`
-		} `json:"integrations"`
-		EscalationPolicy struct {
-			Id      string `json:"id"`
-			Type    string `json:"type"`
-			Summary string `json:"summary"`
-			Self    string `json:"self"`
-			HtmlUrl string `json:"html_url"`
-		} `json:"escalation_policy"`
-		Teams []struct {
-			Id      string `json:"id"`
-			Type    string `json:"type"`
-			Summary string `json:"summary"`
-			Self    string `json:"self"`
-			HtmlUrl string `json:"html_url"`
-		} `json:"teams"`
-		IncidentUrgencyRule struct {
-			Type               string `json:"type"`
-			DuringSupportHours struct {
-				Type    string `json:"type"`
-				Urgency string `json:"urgency"`
-			} `json:"during_support_hours"`
-			OutsideSupportHours struct {
-				Type    string `json:"type"`
-				Urgency string `json:"urgency"`
-			} `json:"outside_support_hours"`
-		} `json:"incident_urgency_rule"`
-		SupportHours struct {
-			Type       string `json:"type"`
-			TimeZone   string `json:"time_zone"`
-			StartTime  string `json:"start_time"`
-			EndTime    string `json:"end_time"`
-			DaysOfWeek []int  `json:"days_of_week"`
-		} `json:"support_hours"`
-		ScheduledActions []struct {
-			Type string `json:"type"`
-			At   struct {
-				Type string `json:"type"`
-				Name string `json:"name"`
-			} `json:"at"`
-			ToUrgency string `json:"to_urgency"`
-		} `json:"scheduled_actions"`
-		AutoPauseNotificationsParameters struct {
-			Enabled bool `json:"enabled"`
-			Timeout int  `json:"timeout"`
-		} `json:"auto_pause_notifications_parameters"`
-	}
+	Offset   int           `json:"offset"`
+	Limit    int           `json:"limit"`
+	More     bool          `json:"more"`
+	Total    int           `json:"total"`
+	Services []raw.Service `json:"services"`
 }
 
 const RemoteScopesPerPage int = 100
 const TypeScope string = "scope"
-const TypeGroup string = "group"
-
-//const TypeGroup string = "group"
 
 // RemoteScopes list all available scopes (services) for this connection
 // @Summary list all available scopes (services) for this connection
diff --git a/backend/plugins/pagerduty/models/raw/incidents.go b/backend/plugins/pagerduty/models/raw/incidents.go
index 464ab1072..06299858c 100644
--- a/backend/plugins/pagerduty/models/raw/incidents.go
+++ b/backend/plugins/pagerduty/models/raw/incidents.go
@@ -19,7 +19,7 @@ package raw
 
 import "time"
 
-type Incidents struct {
+type Incident struct {
 	// Acknowledgements corresponds to the JSON schema field "acknowledgements".
 	Acknowledgements []IncidentsAcknowledgementsElem `json:"acknowledgements,omitempty"`
 
diff --git a/backend/plugins/pagerduty/models/raw/services.go b/backend/plugins/pagerduty/models/raw/services.go
index c68b42f2a..d268e6dd3 100644
--- a/backend/plugins/pagerduty/models/raw/services.go
+++ b/backend/plugins/pagerduty/models/raw/services.go
@@ -19,186 +19,70 @@ package raw
 
 import "time"
 
-type Services struct {
-	// AcknowledgementTimeout corresponds to the JSON schema field
-	// "acknowledgement_timeout".
-	AcknowledgementTimeout *int `json:"acknowledgement_timeout,omitempty"`
-
-	// AlertCreation corresponds to the JSON schema field "alert_creation".
-	AlertCreation *string `json:"alert_creation,omitempty"`
-
-	// AlertGrouping corresponds to the JSON schema field "alert_grouping".
-	AlertGrouping *string `json:"alert_grouping,omitempty"`
-
-	// AlertGroupingTimeout corresponds to the JSON schema field
-	// "alert_grouping_timeout".
-	AlertGroupingTimeout *int `json:"alert_grouping_timeout,omitempty"`
-
-	// AutoResolveTimeout corresponds to the JSON schema field "auto_resolve_timeout".
-	AutoResolveTimeout *int `json:"auto_resolve_timeout,omitempty"`
-
-	// CreatedAt corresponds to the JSON schema field "created_at".
-	CreatedAt *time.Time `json:"created_at,omitempty"`
-
-	// Description corresponds to the JSON schema field "description".
-	Description *string `json:"description,omitempty"`
-
-	// EscalationPolicy corresponds to the JSON schema field "escalation_policy".
-	EscalationPolicy *ServicesEscalationPolicy `json:"escalation_policy,omitempty"`
-
-	// HtmlUrl corresponds to the JSON schema field "html_url".
-	HtmlUrl *string `json:"html_url,omitempty"`
-
-	// Id corresponds to the JSON schema field "id".
-	Id *string `json:"id,omitempty"`
-
-	// IncidentUrgencyRule corresponds to the JSON schema field
-	// "incident_urgency_rule".
-	IncidentUrgencyRule *ServicesIncidentUrgencyRule `json:"incident_urgency_rule,omitempty"`
-
-	// Integrations corresponds to the JSON schema field "integrations".
-	Integrations []ServicesIntegrationsElem `json:"integrations,omitempty"`
-
-	// LastIncidentTimestamp corresponds to the JSON schema field
-	// "last_incident_timestamp".
-	LastIncidentTimestamp *time.Time `json:"last_incident_timestamp,omitempty"`
-
-	// Name corresponds to the JSON schema field "name".
-	Name *string `json:"name,omitempty"`
-
-	// ScheduledActions corresponds to the JSON schema field "scheduled_actions".
-	ScheduledActions []ServicesScheduledActionsElem `json:"scheduled_actions,omitempty"`
-
-	// Self corresponds to the JSON schema field "self".
-	Self *string `json:"self,omitempty"`
-
-	// Status corresponds to the JSON schema field "status".
-	Status *string `json:"status,omitempty"`
-
-	// Summary corresponds to the JSON schema field "summary".
-	Summary *string `json:"summary,omitempty"`
-
-	// SupportHours corresponds to the JSON schema field "support_hours".
-	SupportHours *ServicesSupportHours `json:"support_hours,omitempty"`
-
-	// Teams corresponds to the JSON schema field "teams".
-	Teams []ServicesTeamsElem `json:"teams,omitempty"`
-
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
-}
-
-type ServicesEscalationPolicy struct {
-	// HtmlUrl corresponds to the JSON schema field "html_url".
-	HtmlUrl *string `json:"html_url,omitempty"`
-
-	// Id corresponds to the JSON schema field "id".
-	Id *string `json:"id,omitempty"`
-
-	// Self corresponds to the JSON schema field "self".
-	Self *string `json:"self,omitempty"`
-
-	// Summary corresponds to the JSON schema field "summary".
-	Summary *string `json:"summary,omitempty"`
-
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
-}
-
-type ServicesIncidentUrgencyRule struct {
-	// DuringSupportHours corresponds to the JSON schema field "during_support_hours".
-	DuringSupportHours *ServicesIncidentUrgencyRuleDuringSupportHours `json:"during_support_hours,omitempty"`
-
-	// OutsideSupportHours corresponds to the JSON schema field
-	// "outside_support_hours".
-	OutsideSupportHours *ServicesIncidentUrgencyRuleOutsideSupportHours `json:"outside_support_hours,omitempty"`
-
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
-}
-
-type ServicesIncidentUrgencyRuleDuringSupportHours struct {
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
-
-	// Urgency corresponds to the JSON schema field "urgency".
-	Urgency *string `json:"urgency,omitempty"`
-}
-
-type ServicesIncidentUrgencyRuleOutsideSupportHours struct {
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
-
-	// Urgency corresponds to the JSON schema field "urgency".
-	Urgency *string `json:"urgency,omitempty"`
-}
-
-type ServicesIntegrationsElem struct {
-	// HtmlUrl corresponds to the JSON schema field "html_url".
-	HtmlUrl *string `json:"html_url,omitempty"`
-
-	// Id corresponds to the JSON schema field "id".
-	Id *string `json:"id,omitempty"`
-
-	// Self corresponds to the JSON schema field "self".
-	Self *string `json:"self,omitempty"`
-
-	// Summary corresponds to the JSON schema field "summary".
-	Summary *string `json:"summary,omitempty"`
-
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
-}
-
-type ServicesScheduledActionsElem struct {
-	// At corresponds to the JSON schema field "at".
-	At *ServicesScheduledActionsElemAt `json:"at,omitempty"`
-
-	// ToUrgency corresponds to the JSON schema field "to_urgency".
-	ToUrgency *string `json:"to_urgency,omitempty"`
-
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
-}
-
-type ServicesScheduledActionsElemAt struct {
-	// Name corresponds to the JSON schema field "name".
-	Name *string `json:"name,omitempty"`
-
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
-}
-
-type ServicesSupportHours struct {
-	// DaysOfWeek corresponds to the JSON schema field "days_of_week".
-	DaysOfWeek []int `json:"days_of_week,omitempty"`
-
-	// EndTime corresponds to the JSON schema field "end_time".
-	EndTime *string `json:"end_time,omitempty"`
-
-	// StartTime corresponds to the JSON schema field "start_time".
-	StartTime *string `json:"start_time,omitempty"`
-
-	// TimeZone corresponds to the JSON schema field "time_zone".
-	TimeZone *string `json:"time_zone,omitempty"`
-
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
-}
-
-type ServicesTeamsElem struct {
-	// HtmlUrl corresponds to the JSON schema field "html_url".
-	HtmlUrl *string `json:"html_url,omitempty"`
-
-	// Id corresponds to the JSON schema field "id".
-	Id *string `json:"id,omitempty"`
-
-	// Self corresponds to the JSON schema field "self".
-	Self *string `json:"self,omitempty"`
-
-	// Summary corresponds to the JSON schema field "summary".
-	Summary *string `json:"summary,omitempty"`
-
-	// Type corresponds to the JSON schema field "type".
-	Type *string `json:"type,omitempty"`
+type Service struct {
+	Id                      string    `json:"id"`
+	Summary                 string    `json:"summary"`
+	Type                    string    `json:"type"`
+	Self                    string    `json:"self"`
+	HtmlUrl                 string    `json:"html_url"`
+	Name                    string    `json:"name"`
+	AutoResolveTimeout      int       `json:"auto_resolve_timeout"`
+	AcknowledgementTimeout  int       `json:"acknowledgement_timeout"`
+	CreatedAt               time.Time `json:"created_at"`
+	Status                  string    `json:"status"`
+	AlertCreation           string    `json:"alert_creation"`
+	AlertGroupingParameters struct {
+		Type string `json:"type"`
+	} `json:"alert_grouping_parameters"`
+	Integrations []struct {
+		Id      string `json:"id"`
+		Type    string `json:"type"`
+		Summary string `json:"summary"`
+		Self    string `json:"self"`
+		HtmlUrl string `json:"html_url"`
+	} `json:"integrations"`
+	EscalationPolicy struct {
+		Id      string `json:"id"`
+		Type    string `json:"type"`
+		Summary string `json:"summary"`
+		Self    string `json:"self"`
+		HtmlUrl string `json:"html_url"`
+	} `json:"escalation_policy"`
+	Teams []struct {
+		Id      string `json:"id"`
+		Type    string `json:"type"`
+		Summary string `json:"summary"`
+		Self    string `json:"self"`
+		HtmlUrl string `json:"html_url"`
+	} `json:"teams"`
+	IncidentUrgencyRule struct {
+		Type               string `json:"type"`
+		DuringSupportHours struct {
+			Type    string `json:"type"`
+			Urgency string `json:"urgency"`
+		} `json:"during_support_hours"`
+		OutsideSupportHours struct {
+			Type    string `json:"type"`
+			Urgency string `json:"urgency"`
+		} `json:"outside_support_hours"`
+	} `json:"incident_urgency_rule"`
+	SupportHours struct {
+		Type       string `json:"type"`
+		TimeZone   string `json:"time_zone"`
+		StartTime  string `json:"start_time"`
+		EndTime    string `json:"end_time"`
+		DaysOfWeek []int  `json:"days_of_week"`
+	} `json:"support_hours"`
+	ScheduledActions []struct {
+		Type string `json:"type"`
+		At   struct {
+			Type string `json:"type"`
+			Name string `json:"name"`
+		} `json:"at"`
+		ToUrgency string `json:"to_urgency"`
+	} `json:"scheduled_actions"`
+	AutoPauseNotificationsParameters struct {
+		Enabled bool `json:"enabled"`
+		Timeout int  `json:"timeout"`
+	} `json:"auto_pause_notifications_parameters"`
 }
diff --git a/backend/plugins/pagerduty/tasks/incidents_converter.go b/backend/plugins/pagerduty/tasks/incidents_converter.go
index 2c7f8895a..0713af07b 100644
--- a/backend/plugins/pagerduty/tasks/incidents_converter.go
+++ b/backend/plugins/pagerduty/tasks/incidents_converter.go
@@ -58,7 +58,7 @@ func ConvertIncidents(taskCtx plugin.SubTaskContext) errors.Error {
 		dal.From("_tool_pagerduty_incidents AS pi"),
 		dal.Join(`LEFT JOIN _tool_pagerduty_assignments AS pa ON pa.incident_number = pi.number`),
 		dal.Join(`LEFT JOIN _tool_pagerduty_users AS pu ON pa.user_id = pu.id`),
-		dal.Where("pi.connection_id = ?", data.Options.ConnectionId),
+		dal.Where("pi.connection_id = ? AND pi.service_id = ?", data.Options.ConnectionId, data.Options.ServiceId),
 	)
 	if err != nil {
 		return err
diff --git a/backend/plugins/pagerduty/tasks/incidents_extractor.go b/backend/plugins/pagerduty/tasks/incidents_extractor.go
index d5ba7eb26..8b5e6ba7a 100644
--- a/backend/plugins/pagerduty/tasks/incidents_extractor.go
+++ b/backend/plugins/pagerduty/tasks/incidents_extractor.go
@@ -39,7 +39,7 @@ func ExtractIncidents(taskCtx plugin.SubTaskContext) errors.Error {
 			Table: RAW_INCIDENTS_TABLE,
 		},
 		Extract: func(row *api.RawData) ([]interface{}, errors.Error) {
-			incidentRaw := &raw.Incidents{}
+			incidentRaw := &raw.Incident{}
 			err := errors.Convert(json.Unmarshal(row.Data, incidentRaw))
 			if err != nil {
 				return nil, err