Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "Assignee has already been taken" #19954

Closed
wants to merge 3 commits into from

Conversation

ajaygm
Copy link
Contributor

@ajaygm ajaygm commented Nov 15, 2020

Handle the following response...
https://docs.github.com/en/free-pro-team@latest/rest/reference/issues#add-assignees-to-an-issue
HTTP Status Code: 422

{
	"message":"Validation Failed",
	"errors":["Could not add assignees: Validation failed: Assignee has already been taken"],
	"documentation_url":"https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue"
}

Fixes #16145

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 15, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @ajaygm. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 15, 2020
@k8s-ci-robot k8s-ci-robot added area/prow Issues or PRs related to prow sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Nov 15, 2020
@matthyx
Copy link
Contributor

matthyx commented Nov 15, 2020

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 15, 2020
@matthyx
Copy link
Contributor

matthyx commented Nov 15, 2020

elegant solution, thanks!
/lgtm
/assign @alvaroaleman

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 15, 2020
// Make a request with retries. If ret is not nil, unmarshal the response body
// into it. Returns an error if the exit code is not one of the provided codes.
// Returns githubError if HTTP Status Code is not 2xx.
func (c *client) requestWithGitHubError(r *request, ret interface{}) (int, githubError, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@matthyx @alvaroaleman I was thinking of putting this functionality in the original "request" method and change the signature of the calling functions. With that I'll be able to get rid of this method as it is mostly doing whatever was done in the "request" method.
I wanted to create an independent PR to do these changes as they are not related to this bug fix.
Please let me know your thoughts

Copy link
Member

Choose a reason for hiding this comment

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

I don't think its a good idea to add this method or to have methods that have multiple error type returns that are mutually exclusive in general. The correct way for something like this would be to return the githubError as the last return and then use errors.As in the caller

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found out after a bit more digging in types.go that there was no need to extend githubError or to make any changes in the request function. There's already a datatype AlternativeClientError which has the fields corresponding to the response we get from Github. That data type is returned by request function, so just need to use errors.As as suggested above.

That raises an independent question - is there a need to have the data type githubError at all?

// Make a request with retries. If ret is not nil, unmarshal the response body
// into it. Returns an error if the exit code is not one of the provided codes.
// Returns githubError if HTTP Status Code is not 2xx.
func (c *client) requestWithGitHubError(r *request, ret interface{}) (int, githubError, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think its a good idea to add this method or to have methods that have multiple error type returns that are mutually exclusive in general. The correct way for something like this would be to return the githubError as the last return and then use errors.As in the caller

}, &i)
if err != nil {
return err
}
if httpStatusCode == http.StatusUnprocessableEntity {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be just ignoring that error, we should instead find out how it was possible that we tried to assign the same user twice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you @alvaroaleman
In fact I had asked for directions on places where I should try to look for the root cause of this issue - comment 1, comment 2, comment 3.
Please note that I'm not familiar with the codebase / workflow to make a judgement on places that could be triggering this type of behavior.

I was thinking that there are two approaches when looking at this type of issues...

  1. This is a cloud based solution hence there are chances of calls being sent to your webhook multiple times. Your code should be resilient to such events and work correctly.
  2. You should find out the root cause of why there were 2 calls in the first place.

As I didn't have much knowledge on how to deal with point 2 above, I took this approach to solve point 1 above. I have also left a debug message when we ignore the error incase we wish to still keep looking for the root cause. Is debug level message acceptable?

Please let me know your thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking that there are two approaches when looking at this type of issues...

  1. This is a cloud based solution hence there are chances of calls being sent to your webhook multiple times. Your code should be resilient to such events and work correctly.
  2. You should find out the root cause of why there were 2 calls in the first place.

Regarding 1), that is not expected to happen and if it would happen would cause a lot of other issues as well, like tests always get started twice.

Regarding 2), the place to look would be in the lgtm plugin somewhere:

func handleGenericCommentEvent(pc plugins.Agent, e github.GenericCommentEvent) error {
cp, err := pc.CommentPruner()
if err != nil {
return err
}
return handleGenericComment(pc.GitHubClient, pc.PluginConfig, pc.OwnersClient, pc.Logger, cp, e)
}
func handlePullRequestEvent(pc plugins.Agent, pre github.PullRequestEvent) error {
return handlePullRequest(
pc.Logger,
pc.GitHubClient,
pc.PluginConfig,
&pre,
)
}
func handlePullRequestReviewEvent(pc plugins.Agent, e github.ReviewEvent) error {
// If ReviewActsAsLgtm is disabled, ignore review event.
opts := pc.PluginConfig.LgtmFor(e.Repo.Owner.Login, e.Repo.Name)
if !opts.ReviewActsAsLgtm {
return nil
}
cp, err := pc.CommentPruner()
if err != nil {
return err
}
return handlePullRequestReview(pc.GitHubClient, pc.PluginConfig, pc.OwnersClient, pc.Logger, cp, e)
}

I am not sure if the underlying issue qualifies as good first issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alvaroaleman Are we sure about point 1 above not being possible? To rule that out, I've posted a question in the issue.

Copy link
Member

Choose a reason for hiding this comment

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

I meant it as in Github does give this guarantee and Prow would largely stop working properly if that wasn't the case. That being said its possible to configure the same webhook multiple times (for example on the github organization and repository) in which case the event will be sent once per webhook configuration.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 16, 2020
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 7, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ajaygm, petr-muller
To complete the pull request process, please assign alvaroaleman after the PR has been reviewed.
You can assign the PR to them by writing /assign @alvaroaleman in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@spiffxp
Copy link
Member

spiffxp commented Jan 19, 2021

/test pull-test-infra-integration
#20498 (comment)

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 19, 2021
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 19, 2021
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hook: blunderbuss: do not attempt to assign someone who's already assigned
7 participants