Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions internal/scms/gitlab/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gitlab

import (
"context"
"errors"
"fmt"
"strconv"
"time"
Expand Down Expand Up @@ -247,12 +248,15 @@ func (pr *PullRequest) FindOpen(ctx context.Context, pullRequest v1alpha1.PullRe

start := time.Now()
mrs, resp, err := pr.client.MergeRequests.ListMergeRequests(options)
if resp != nil {
metrics.RecordSCMCall(repo, metrics.SCMAPIPullRequest, metrics.SCMOperationList, resp.StatusCode, time.Since(start), nil)
}
if err != nil {
return false, "", time.Time{}, fmt.Errorf("failed to list pull requests: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the gitlab client return an error for non-200 responses? If so, we still want to make sure we push the metric for the failed request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see it does return an error for non-200 response code https://gitlab.com/gitlab-org/api/client-go/-/blob/main/merge_requests.go#L316

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I don't think we can move the metrics call down...

But we can still add the if resp == nil check, I think that's valid and fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @crenshaw-dev for the explanation, I have updated

}
if resp == nil {
logger.V(4).Info("gitlab response status", "status", "nil response")
return false, "", time.Time{}, errors.New("received nil response from GitLab API")
}

metrics.RecordSCMCall(repo, metrics.SCMAPIPullRequest, metrics.SCMOperationList, resp.StatusCode, time.Since(start), nil)

logGitLabRateLimitsIfAvailable(
logger,
Expand Down
Loading