octokit / go-sdk

A generated Go SDK from GitHub's OpenAPI specification. Built on Kiota.
MIT License
56 stars 7 forks source link

Primary and secondary rate-limit handling #52

Closed kfcampbell closed 3 months ago

kfcampbell commented 4 months ago

Note that parts of testing code were taken from our colleagues at Kiota (as noted here) and parts of implementation code were taken from the google/go-github library (as noted here). I'm grateful to those teams for doing excellent work before us!

This PR adds a rate limit handler to the go-sdk for primary and secondary rate limits. When it detects such a rate limit, it sleeps until the limit has expired, then retries the request. This has been validated using a local GitHub test environment in addition to unit test coverage. In the future, it would be cool to build better retry logic that builds in exponential backoff, jitter, throttling, etc.

It also greatly simplifies the abstractions for API client instantiation. The values I focused on were:

The current pattern looks like this:

client, err := pkg.NewApiClient(
    pkg.WithUserAgent("my-user-agent"),
    pkg.WithRequestTimeout(5*time.Second),
    pkg.WithBaseUrl("https://api.github.com"),
    pkg.WithAuthorizationToken(os.Getenv("GITHUB_TOKEN")),
)

// equally valid:
//client, err := pkg.NewApiClient()
if err != nil {
    log.Fatalf("error creating client: %v", err)
}
github-actions[bot] commented 4 months ago

šŸ‘‹ Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! šŸš€

what-the-diff[bot] commented 4 months ago

PR Summary