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

🐛 clusterctl: retry github i/o operations #6430

Merged
merged 1 commit into from
Apr 28, 2022

Conversation

jackfrancis
Copy link
Contributor

What this PR does / why we need it:

In response to a test flake, this PR introduces retry tolerance to GitHub API-dependent operations in clusterctl.

The passing (unchanged) UT should prove functional equivalence between this change and existing (no retry) behavior.

Reference test flake:

https://prow.k8s.io/view/gs/kubernetes-jenkins/logs/periodic-cluster-api-provider-azure-e2e-workload-upgrade-1-19-1-20-main/1516508031641194496

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 20, 2022
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 20, 2022
@jackfrancis
Copy link
Contributor Author

cc @CecileRobertMichon

Comment on lines 44 to 45
retryableOperationInterval = 3 * time.Second
retryableOperationTimeout = 5 * time.Minute
Copy link
Member

Choose a reason for hiding this comment

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

Given that GitHub is rate limited I suggest having a longer interval and shorter Timeout
Otherwise lgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

interval increased to every 10 seconds, timeout to 1 minute

@fabriziopandini
Copy link
Member

/test pull-cluster-api-e2e-full-main

@jackfrancis
Copy link
Contributor Author

/retest

Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

If I understood this correctly, the intension of this PR (and the linked test flake) is to make github repository client resilient to network errors. In that case the approach in this PR may not work because wait.PollImmediate will return immediately (and will not retry) if the condition function returns an error. For example, this would mean if the client.Repositories.GetReleaseByTag call fails because of the network error and returns an error the client will return the error immediately and fail.

Since we are looking to basically retry when we hit network errors we might want to do something like this:

var err error
_ := wait.PollImmediate(retryableOperationInterval, retryableOperationTimeout, func() (bool, error) {
		var getReleasesErr error
		release, _, getReleasesErr = client.Repositories.GetReleaseByTag(context.TODO(), g.owner, g.repository, tag)
		if getReleasesErr != nil {
			err = getReleasesErr // Do this so we can capture the last error and return that to the layer above. We probably dont care about returning the poll timeout error.
                         // TODO: Here we should be check to see if err is ratelimting err and return immediately. No point in retrying if we are hitting a rate limitting error.
                        return false, nil
		}

		if release == nil {
			return false, nil
		}
		return true, nil
	})
if err != nil {
	return nil, err
}

@jackfrancis
Copy link
Contributor Author

@ykakarap that's not my understanding of how PollImmediate works:

https://github.com/kubernetes/apimachinery/blob/v0.23.5/pkg/util/wait/wait.go#L501

The advantage of using PollImmediate over PullUntil is that the first operation is attempted straight away, while Poll waits for one interval (configurable) first of all before running.

@ykakarap
Copy link
Contributor

@ykakarap that's not my understanding of how PollImmediate works:

https://github.com/kubernetes/apimachinery/blob/v0.23.5/pkg/util/wait/wait.go#L501

The advantage of using PollImmediate over PullUntil is that the first operation is attempted straight away, while Poll waits for one interval (configurable) first of all before running.

That is correct. PollImmediate will run the condition function immediately. I was talking about how we want to handle if the call to function client.Repositories.GetReleaseByTag returns an error because of a network flake. I assumed that was the intention of this PR. I might have misunderstood.

My understanding: The intention of this PR to to retry the github calls if it fails because of network flakes.

@jackfrancis
Copy link
Contributor Author

@ykakarap you're correct, thank you!

https://go.dev/play/p/Z8ynq-10nhS

Hang on for a correct implementation

@fabriziopandini sorry, I'll submit a follow-up to #6431 with the correct implementation

@jackfrancis
Copy link
Contributor Author

@ykakarap updated, PTAL

Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

Overall LGTM for the approach pending the comment fix and the lint fixes.

cmd/clusterctl/client/repository/repository_github.go Outdated Show resolved Hide resolved
@jackfrancis jackfrancis force-pushed the github-retries branch 4 times, most recently from b2618d1 to 62bf324 Compare April 22, 2022 19:36
@jackfrancis
Copy link
Contributor Author

/test pull-cluster-api-e2e-full-main

@jackfrancis
Copy link
Contributor Author

/retest

Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 25, 2022
@jackfrancis
Copy link
Contributor Author

/test pull-cluster-api-e2e-full-main

Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

Looks good overall.

Given that it seems hard to add unit tests for this, did we do a bit of manual testing to verify we're hitting the cases correctly? (I'm aware we can't test all of them)

cmd/clusterctl/client/repository/repository_github.go Outdated Show resolved Hide resolved
@jackfrancis
Copy link
Contributor Author

@sbueringer these changes actually influence existing UT, so there is coverage there (this is why I manually override the timeout in UT so they don't take 1 min for each case :))

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 27, 2022
Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 27, 2022
@sbueringer
Copy link
Member

/lgtm

@fabriziopandini
Copy link
Member

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 28, 2022
@k8s-ci-robot k8s-ci-robot merged commit 582b0e1 into kubernetes-sigs:main Apr 28, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.2 milestone Apr 28, 2022
@jackfrancis
Copy link
Contributor Author

/cherry-pick release-1.1

@jackfrancis jackfrancis deleted the github-retries branch April 28, 2022 15:08
@k8s-infra-cherrypick-robot

@jackfrancis: #6430 failed to apply on top of branch "release-1.1":

Applying: clusterctl: retry github i/o operations
Using index info to reconstruct a base tree...
M	cmd/clusterctl/client/repository/repository_github.go
Falling back to patching base and 3-way merge...
Auto-merging cmd/clusterctl/client/repository/repository_github.go
CONFLICT (content): Merge conflict in cmd/clusterctl/client/repository/repository_github.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 clusterctl: retry github i/o operations
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-1.1

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
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants