orange-cloudfoundry / pivotaltrackermirror

Mirror a pivotal tracker project to an another tracker
Apache License 2.0
1 stars 2 forks source link

Protect against PT API rate limits #27

Open gberche-orange opened 8 years ago

gberche-orange commented 8 years ago

Seems sometimes hitting the pivotal tracker api rate limit fails the whole job:

2016-09-24T07:52:59.16+0200 [APP/0]      OUT Caused by: java.lang.RuntimeException: Failed to GET projects/1456570/memberships
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at onespot.pivotal.rest.JsonRestClient.get(JsonRestClient.java:93) ~[pivotaltracker-java-client-0
.0.21.jar!/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at onespot.pivotal.api.dao.ProjectMembershipsDAO.getAll(ProjectMembershipsDAO.java:46) ~[pivotalt
racker-java-client-0.0.21.jar!/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at onespot.pivotal.api.dao.ProjectMembershipsDAO.getMembershipFromPersonId(ProjectMembershipsDAO.
java:32) ~[pivotaltracker-java-client-0.0.21.jar!/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at onespot.pivotal.api.dao.CommentsDAO.person(CommentsDAO.java:45) ~[pivotaltracker-java-client-0
.0.21.jar!/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at onespot.pivotal.api.dao.CommentsDAO.get(CommentsDAO.java:27) ~[pivotaltracker-java-client-0.0.
21.jar!/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at com.orange.clara.pivotaltrackermirror.service.MirrorService.mirror(MirrorService.java:76) ~[cl
asses/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at com.orange.clara.pivotaltrackermirror.job.MirrorJob.execute(MirrorJob.java:57) ~[classes/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    ... 2 common frames omitted
2016-09-24T07:52:59.16+0200 [APP/0]      OUT Caused by: java.lang.RuntimeException: Request failed, status: 429, text:  body: {
2016-09-24T07:52:59.16+0200 [APP/0]      OUT   "kind": "error",
2016-09-24T07:52:59.16+0200 [APP/0]      OUT   "code": "rate_limit_exceeded",
2016-09-24T07:52:59.16+0200 [APP/0]      OUT   "error": "You have exceeded the allowed request rate",
2016-09-24T07:52:59.16+0200 [APP/0]      OUT   "http_status": "429"
2016-09-24T07:52:59.16+0200 [APP/0]      OUT }
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at onespot.pivotal.rest.JsonRestClient.extractBody(JsonRestClient.java:126) ~[pivotaltracker-java
-client-0.0.21.jar!/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at onespot.pivotal.rest.JsonRestClient.get(JsonRestClient.java:90) ~[pivotaltracker-java-client-0
.0.21.jar!/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    ... 8 common frames omitted
2016-09-24T07:52:59.16+0200 [APP/0]      OUT 2016-09-24 05:52:59.166 ERROR 18 --- [ryBean_Worker-4] org.quartz.core.ErrorLogger              : Jo
b (mirrorJob.jobFor61 threw an exception.
2016-09-24T07:52:59.16+0200 [APP/0]      OUT org.quartz.SchedulerException: Job threw an unhandled exception.
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at org.quartz.core.JobRunShell.run(JobRunShell.java:213) ~[quartz-2.2.1.jar!/:na]
2016-09-24T07:52:59.16+0200 [APP/0]      OUT    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.1.jar!/:na]

Would be great to catch such exception and perform current and planned strategies as part of #20 .

A short term workaround is to distribute the PT tracker load across multiple api token keys as to reduce probability of hitting limit on a single account.

While github tokens are accepted by the webui, the PT tokens are currently shared among a given pivotaltrackermirror instance. This therefore currently requires deploying multiple pivotaltrackermirror instances to shard "mirrors" on the PT key.