Skip to content

Github Provider: Support API Rate Limiting #5

Closed

Description

@hashibot

This issue was originally opened by @johnrengelman as hashicorp/terraform#6016. It was migrated here as part of the provider split. The original body of the issue is below.


The Github API has a rate limit than can be easily overcome when managing an organization.
This ticket is simply a spot to start a conversation about how to properly handle the rate limit.

Details: https://developer.github.com/v3/#rate-limiting

Activity

  1. added
    Type: Feature
    on Jun 13, 2017
  2. DWSR commented on Jul 6, 2017

    @DWSR
    Contributor

    Checking the X-RateLimit-Remaining and X-RateLimit-Reset headers seems like it should be straightforward enough. This would result in activity spikes as the provider would run full speed until the limit is reached, however.

  3. joestump commented on Jul 26, 2017

    @joestump

    I'd assume behavior would look similar to how TF behaves when it's doing a large AWS modification?

  4. majormoses commented on Jul 26, 2017

    @majormoses
    Contributor

    I thought about this more and the rate limits are still quite different in the sense that they are done hourly on github. So I am not sure how much value there is in this to slow down for an hour...Most rate limits are over a shorter period of time.

  5. joestump commented on Jul 27, 2017

    @joestump

    Our rate limit is like 5000 calls. I doubt this will be an issue for anyone anytime soon. Our GitHub TF runs are very low volume.

  6. majormoses commented on Jul 27, 2017

    @majormoses
    Contributor

    I hit this probably a half dozen times trying to get through one of the organizations I am a maintainer for: https://github.com/sensu-plugins which I was just finishing the import last night but took at least several passes to get all the way through importing some ones that were previously missed in initial attempts.

  7. majormoses commented on Jul 27, 2017

    @majormoses
    Contributor

    That's one of the problems with hourly rate limits, there is no opportunity to back off and slow down rate. It's just wait for an hour and then retry.

  8. joestump commented on Jul 27, 2017

    @joestump

    @majormoses agreed on the hourly bucket size. That's really only 1.5'ish calls per second when the bucket is that big. Though I do think, on an ongoing basis, 5000 calls an hour is probably fine. Not everyone is quite as popular as Sensu! 😄

  9. DWSR commented on Jul 27, 2017

    @DWSR
    Contributor

    I suspect just having some kind of simple logic to detect that we are out of calls, pause, and display feedback is perfectly sufficient. It would feel bad to have TF fail because of this and then succeed when you re-run it a bit later.

  10. majormoses commented on Jul 27, 2017

    @majormoses
    Contributor

    SGTM, not sure about pausing for ~60 minutes but def would be nice to have some feedback and then return with a try again later. I would feel much better about it if it was say even a half hour (IMHO should be something like 5m) bucket. Waiting for 60 minutes is a lot of wasted resources to keep all that it needs in RAM. What I ended up doing in my case which yes I know is probably much larger than the vast majority of projects on github was just setting a timer and walking away. As this was something I was doing at home for some open source projects it was not as big a deal for me to wait a few times and go do something else but I could see that being maddening at work.

  11. DWSR commented on Jul 27, 2017

    @DWSR
    Contributor

    I'm making that suggestion more to go from a state where TF just breaks when running into the limit to a place where it doesn't break. An MVP, if you will.

    A secondary evolution could be to precount the number of transactions against the API and subdivide that into buckets

  12. majormoses commented on Oct 1, 2017

    @majormoses
    Contributor

    I now have too many github objects managed by terraform that I can no longer get through a terraform plan. 😢 / 😂

    Any chance of getting someone to implement rate limiting per https://github.com/google/go-github#rate-limiting. If no one thinks they can get to it sometime soon I can try learning enough go to hack something together (probably will need some help). If I can't get it working soon I see a couple of options going forward:

    1. break up into multiple states so that we could limit every time a plan is run it is on a subset of the repositories
    2. look into if there is anything that can be optimized to reduce the number of requests made as this truly is insane that with ~200 repos and a few dozen labels you can chew through 5000 requests in a few minutes.
    3. Look for another tool to manage github via code. This would make me very sad.
  13. DWSR commented on Oct 1, 2017

    @DWSR
    Contributor

    Have you tried disabling TF's state refresh on plan run via -refresh=false?

    Also, have you tried limiting your plan runs to only certain repos via -target=?

  14. mbbroberg commented on Oct 1, 2017

    @mbbroberg

    👋 been working with @majormoses on this one.

    Have you tried disabling TF's state refresh on plan run via -refresh=false?

    I haven't, I'll give it a go.

    Also, have you tried limiting your plan runs to only certain repos via -target=?

    Could use that sometimes, but not often. The overall goal is to manage the 200+ repos so sometimes we have to hit them all.

    Thanks all 🙏

  15. majormoses commented on Oct 1, 2017

    @majormoses
    Contributor

    I mean those are temporary solutions, like matt said running it on a subset of repos with -target kinda defeats the purpose. Using -refresh=false permanently sounds dangerous to use (would be fine for an initial import) and defeats the benefit of terraform in the first place which is configuration drift.

  16. 15 remaining items

  17. majormoses commented on Oct 2, 2017

    @majormoses
    Contributor

    Sorry not default I misspoke. I mean having to define the same vaiables.tf. It's just a lot of extra duplication of stuff.

    Regarding out of band yes I do that at my job but I have a slew of Jenkins machines that run that on our behalf and have created very complex flows. This is an open source project and the closest we have is travis. I am not sure how much effort it would be to make something like this with travis but that is a hell of a lot more time/effort than I have time for right now. I do much of this contribution on nights and weekends. Also we would still need some maintainers to have admin to accept new repos into the org as I don't see terraform supporting a feature like transfer repo to/from user/org.

    If someone deletes a repository, simply refreshing the state and recreating it as a single repo

    I think I was not clear I was refering to my contemplation to actually stick each repos terraform into the repo itself but was offering a counter offer why a mono repo with more restrictive permissions/access is better than a bunch of repos that are more loose with access. The same thought process was applied to the chicken and egg. As this means that you create the github repo and then import to its own terraform state seems odd.

    I don't see many downsides to breaking out each repository into its own module (reliance on another utility is one, certainly), but see tremendous upside when allowing fully automated changes.

    Like I said it comes down to the time, effort, and lack of budget to split all that out and duplicate a lot of work.

  18. DWSR commented on Oct 2, 2017

    @DWSR
    Contributor

    Defining the same variables over and over again is something Terragrunt is very strong at. You can even template out your CLI flags so that you don't need to remember them..

    Importing a repository with Terragrunt vs. Terraform is almost identical. Transferring in a repository as an admin should be a very easy process. I suspect you could even register a webhook from Travis so that all newly imported repositories are automatically imported to Terraform/Terragrunt.

    Sticking each repository's definition into itself (a la Dockerfile or Jenkinsfile) is an interesting idea...not sure how to work it all out, but that's an idea worth exploring. :)

  19. majormoses commented on Oct 20, 2017

    @majormoses
    Contributor

    I took a closer look at terragrunt and while it does solve redefining variables it does not solve the base problem which is that we want to ensure that all config drift is caught in a single command without hitting api limits even if it sits there for a really long time.

  20. self-assigned this
    on Jun 5, 2018
  21. abridgett commented on Jul 24, 2018

    @abridgett

    FYI there was hashicorp/terraform#11670 which if it's suitable might be a quick win here. It seems to have been lost in the split of the providers. It's rather frustrating having to wait for the next set of tokens to become available that's for sure :)

  22. majormoses commented on Jul 24, 2018

    @majormoses
    Contributor

    Looking at the upstream library docs https://github.com/google/go-github/blob/v15.0.0/github/doc.go#L124-L149 it looks like it supports conditional requests (not directly).

  23. majormoses commented on Aug 7, 2018

    @majormoses
    Contributor

    @hwhopemaIBM since you are on github enterprise you could try discussing with your github admin to change your rate limits: https://help.github.com/enterprise/2.13/admin/guides/installation/configuring-rate-limits that being said the issue is still a big one for both enterprise and hosted solutions and I think there are several things we can do (not all scoped to this issue):

    • build in rate limit awareness (gracefully exit plan when rate limit is tripped)
    • use conditional requests where possible (reduces the number of requests sent)
    • make provider able to auth as a github oauth2 app so it's limits are larger for larger orgs
  24. ss-remygreinhofer commented on Aug 14, 2018

    @ss-remygreinhofer

    To add some feedback to the conversation, I am trying to manage a large GitHub organization with this provider and I am constantly blocked by the rate limit: 403 You have triggered an abuse detection mechanism. Please wait a few minutes before you try again..

  25. docwhat commented on Aug 14, 2018

    @docwhat
    Contributor

    If we switched to making the changes via GraphQL (the v4 API) then it would prevent the case where only a partial change happens (in theory).

  26. docwhat commented on Aug 14, 2018

    @docwhat
    Contributor

    @ss-remygreinhofer

    And don't forget:

    • Switch to the v4 GraphQL api since it (in theory) can get better info for less cost.
  27. nicksantamaria commented on Feb 27, 2019

    @nicksantamaria

    To add some feedback to the conversation, I am trying to manage a large GitHub organization with this provider and I am constantly blocked by the rate limit: 403 You have triggered an abuse detection mechanism. Please wait a few minutes before you try again..

    @ss-remygreinhofer This issue appears to be separate to the rate limit. Try adding -parallelism=1 to your plan/apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type: Feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions