Skip to content

Commit bfdb6d9

Browse files
committed
OSD-29424 - Update PD incident title after investigation
1 parent 179db6a commit bfdb6d9

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

cadctl/cmd/investigate/investigate.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222
"path/filepath"
23+
"strings"
2324

2425
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
2526
investigations "github.com/openshift/configuration-anomaly-detection/pkg/investigations"
@@ -47,6 +48,8 @@ var (
4748
payloadPath = "./payload.json"
4849
)
4950

51+
const pagerdutyTitlePrefix = "[CAD Investigated]"
52+
5053
func init() {
5154
InvestigateCmd.Flags().StringVarP(&payloadPath, "payload-path", "p", payloadPath, "the path to the payload")
5255
InvestigateCmd.Flags().StringVarP(&logging.LogLevelString, "log-level", "l", "", "the log level [debug,info,warn,error,fatal], default = info")
@@ -151,8 +154,11 @@ func run(cmd *cobra.Command, _ []string) error {
151154
logging.Infof("Starting investigation for %s", alertInvestigation.Name())
152155
result, err := alertInvestigation.Run(investigationResources)
153156
updateMetrics(alertInvestigation.Name(), &result)
157+
if err != nil {
158+
return err
159+
}
154160

155-
return err
161+
return updateIncidentTitle(pdClient)
156162
}
157163

158164
func handleCADFailure(err error, resources *investigation.Resources, pdClient *pagerduty.SdkClient) {
@@ -231,3 +237,16 @@ func updateMetrics(investigationName string, result *investigation.Investigation
231237
metrics.Inc(metrics.LimitedSupportSet, append([]string{investigationName}, result.LimitedSupportSet.Labels...)...)
232238
}
233239
}
240+
241+
func updateIncidentTitle(pdClient *pagerduty.SdkClient) error {
242+
currentTitle := pdClient.GetTitle()
243+
if strings.Contains(currentTitle, pagerdutyTitlePrefix) {
244+
return nil
245+
}
246+
newTitle := fmt.Sprintf("[CAD Investigated] %s", currentTitle)
247+
err := pdClient.UpdateIncidentTitle(newTitle)
248+
if err != nil {
249+
return fmt.Errorf("failed to update PagerDuty incident title: %w", err)
250+
}
251+
return nil
252+
}

pkg/pagerduty/mock/pagerdutymock.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/pagerduty/pagerduty.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type Client interface {
5151
GetServiceID() string
5252
EscalateIncidentWithNote(notes string) error
5353
EscalateIncident() error
54+
UpdateIncidentTitle(title string) error
5455
}
5556

5657
// SdkClient will hold all the required fields for any SdkClient Operation
@@ -228,22 +229,22 @@ func (c *SdkClient) SetIncidentData(incidentData *IncidentData) {
228229
c.incidentData = incidentData
229230
}
230231

231-
// GetServiceID returns the event type of the webhook
232+
// GetServiceID returns the ID of the pagerduty service containing the client's incident
232233
func (c *SdkClient) GetServiceID() string {
233234
return c.incidentData.ServiceID
234235
}
235236

236-
// GetServiceName returns the event type of the webhook
237+
// GetServiceName returns the pagerduty service containing the client's incident
237238
func (c *SdkClient) GetServiceName() string {
238239
return c.incidentData.ServiceSummary
239240
}
240241

241-
// GetTitle returns the event type of the webhook
242+
// GetTitle returns the title of the client's incident
242243
func (c *SdkClient) GetTitle() string {
243244
return c.incidentData.IncidentTitle
244245
}
245246

246-
// GetIncidentID returns the event type of the webhook
247+
// GetIncidentID returns the ID of the client's incident
247248
func (c *SdkClient) GetIncidentID() string {
248249
return c.incidentData.IncidentID
249250
}
@@ -541,3 +542,18 @@ func (c *SdkClient) EscalateIncident() error {
541542
}
542543
return nil
543544
}
545+
546+
func (c *SdkClient) UpdateIncidentTitle(title string) error {
547+
o := []sdk.ManageIncidentsOptions{
548+
{
549+
ID: c.GetIncidentID(),
550+
Title: title,
551+
},
552+
}
553+
554+
err := c.updateIncident(o)
555+
if err != nil {
556+
return fmt.Errorf("failed to update incident: %w", err)
557+
}
558+
return nil
559+
}

0 commit comments

Comments
 (0)