From a7cc983b8893b173e8b82859e3646fdfae779620 Mon Sep 17 00:00:00 2001 From: Rory Malcolm Date: Fri, 13 Sep 2024 15:56:13 +0100 Subject: [PATCH] Fix on-call user detection --- integrations/access/incidentio/app.go | 6 ++++-- integrations/access/incidentio/client.go | 10 +++++----- integrations/access/incidentio/types.go | 4 ++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/integrations/access/incidentio/app.go b/integrations/access/incidentio/app.go index fe6d50aa18914..9e5727ceefbb1 100644 --- a/integrations/access/incidentio/app.go +++ b/integrations/access/incidentio/app.go @@ -132,6 +132,8 @@ func (a *App) run(ctx context.Context) error { }, a.onWatcherEvent, ) + log.Info("Starting watcher job") + if err != nil { return trace.Wrap(err) } @@ -450,7 +452,7 @@ func (a *App) tryApproveRequest(ctx context.Context, req types.AccessRequest) er if err != nil { return trace.Wrap(err) } - for _, shift := range respondersResult.CurrentShifts { + for _, shift := range respondersResult.Schedule.CurrentShifts { if shift.User != nil { onCallUsers = append(onCallUsers, shift.User.Email) } @@ -517,7 +519,7 @@ func (a *App) resolveAlert(ctx context.Context, reqID string, resolution Resolut return trace.Wrap(err) } if !ok { - logger.Get(ctx).Debug("Failed to resolve the alert: plugin data is missing") + logger.Get(ctx).Debugf("Failed to resolve the alert: plugin data is missing") return nil } diff --git a/integrations/access/incidentio/client.go b/integrations/access/incidentio/client.go index 195ab863df877..15d90b4f4f187 100644 --- a/integrations/access/incidentio/client.go +++ b/integrations/access/incidentio/client.go @@ -181,19 +181,19 @@ func (inc AlertClient) ResolveAlert(ctx context.Context, alertID string, resolut } // GetOnCall returns the list of responders on-call for a schedule. -func (inc APIClient) GetOnCall(ctx context.Context, scheduleID string) (ScheduleResult, error) { - var result ScheduleResult +func (inc APIClient) GetOnCall(ctx context.Context, scheduleID string) (GetScheduleResponse, error) { + var result GetScheduleResponse resp, err := inc.client.NewRequest(). SetContext(ctx). SetPathParams(map[string]string{"scheduleID": scheduleID}). SetResult(&result). - Get("v2/schedules/{scheduleID}") + Get("/v2/schedules/{scheduleID}") if err != nil { - return ScheduleResult{}, trace.Wrap(err) + return GetScheduleResponse{}, trace.Wrap(err) } defer resp.RawResponse.Body.Close() if resp.IsError() { - return ScheduleResult{}, errWrapper(resp.StatusCode(), string(resp.Body())) + return GetScheduleResponse{}, errWrapper(resp.StatusCode(), string(resp.Body())) } return result, nil } diff --git a/integrations/access/incidentio/types.go b/integrations/access/incidentio/types.go index 9e1e917f4a4c3..c4c84fcb2974c 100644 --- a/integrations/access/incidentio/types.go +++ b/integrations/access/incidentio/types.go @@ -34,6 +34,10 @@ type AlertBody struct { Metadata map[string]string `json:"metadata,omitempty"` } +type GetScheduleResponse struct { + Schedule ScheduleResult `json:"schedule"` +} + type ScheduleResult struct { Annotations map[string]string `json:"annotations"` Config ScheduleConfig `json:"config"`