Skip to content

Commit

Permalink
update new method to have context for tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
mplachter committed Aug 16, 2023
1 parent c70b71a commit 2adff47
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/mocks/mock_vcs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pkg/vcs/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func (c *Client) GetMergeRequestApprovals(ctx context.Context, id int, project s
}

// Go over all comments on a PR, trying to grab any old TFC run urls and deleting the bodies
func (c *Client) GetOldRunUrls(prID int, fullName string, rootCommentID int) (string, error) {
func (c *Client) GetOldRunUrls(ctx context.Context, prID int, fullName string, rootCommentID int) (string, error) {
_, span := otel.Tracer("TFC").Start(ctx, "GetOldRunURLs")
defer span.End()

log.Debug().Msg("pruneComments")
projectParts, err := splitFullName(fullName)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/vcs/gitlab/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (c *GitlabClient) SetCommitStatus(ctx context.Context, projectWithNS string
return &GitlabCommitStatus{commitStatus}, utils.CreatePermanentError(err)
}, createBackOffWithRetries())
}

func (c *GitlabClient) GetCommitStatuses(ctx context.Context, projectID, commitSHA string) []*gogitlab.CommitStatus {
_, span := otel.Tracer("TFC").Start(ctx, "GetCommitStatuses")
defer span.End()
Expand All @@ -122,7 +123,10 @@ func (c *GitlabClient) GetCommitStatuses(ctx context.Context, projectID, commitS
}

// Crawl the comments on this MR for tfbuddy comments, grab any TFC urls out of them, and delete them.
func (c *GitlabClient) GetOldRunUrls(mrIID int, project string, rootNoteID int) (string, error) {
func (c *GitlabClient) GetOldRunUrls(ctx context.Context, mrIID int, project string, rootNoteID int) (string, error) {
_, span := otel.Tracer("TFC").Start(ctx, "GetOldRunURLs")
defer span.End()

log.Debug().Str("projectID", project).Int("mrIID", mrIID).Msg("pruning notes")
notes, _, err := c.client.Notes.ListMergeRequestNotes(project, mrIID, &gogitlab.ListMergeRequestNotesOptions{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vcs/gitlab/mr_comment_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (p *RunStatusUpdater) postRunStatusComment(ctx context.Context, run *tfe.Ru
var err error

if run.Status == tfe.RunErrored || run.Status == tfe.RunCanceled || run.Status == tfe.RunDiscarded || run.Status == tfe.RunPlannedAndFinished {
oldUrls, err = p.client.GetOldRunUrls(rmd.GetMRInternalID(), rmd.GetMRProjectNameWithNamespace(), int(rmd.GetRootNoteID()))
oldUrls, err = p.client.GetOldRunUrls(ctx, rmd.GetMRInternalID(), rmd.GetMRProjectNameWithNamespace(), int(rmd.GetRootNoteID()))
if err != nil {
log.Error().Err(err).Msg("could not retrieve old run urls")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/vcs/gitlab/mr_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (p *RunStatusUpdater) updateCommitStatusForRun(ctx context.Context, run *tf

case tfe.RunApplied:
if len(run.TargetAddrs) > 0 {
p.updateStatus(gogitlab.Pending, "apply", rmd)
p.updateStatus(ctx, gogitlab.Pending, "apply", rmd)
return
}
// The applying phase of a run has completed.
Expand Down

0 comments on commit 2adff47

Please sign in to comment.