-
Notifications
You must be signed in to change notification settings - Fork 35
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
feat: Add exponential and server-mediated backoff on retries #56
Conversation
Codecov Report
@@ Coverage Diff @@
## master #56 +/- ##
==========================================
+ Coverage 92.95% 96.92% +3.97%
==========================================
Files 6 6
Lines 298 325 +27
Branches 54 59 +5
==========================================
+ Hits 277 315 +38
+ Misses 21 10 -11
Continue to review full report at Codecov.
|
ts/src/config.ts
Outdated
// by the server response, then profiler will wait this long before asking | ||
// server to create a profile again. After a successful profile creation, | ||
// the backoff will be reset to initialExpBackoffMillis. | ||
initialExpBackoffMillis?: number; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/config.ts
Outdated
@@ -108,5 +125,8 @@ export const defaultConfig = { | |||
timeIntervalMicros: 1000, | |||
heapIntervalBytes: 512 * 1024, | |||
heapMaxStackDepth: 64, | |||
backoffMillis: 5 * 60 * 1000 | |||
initialExpBackoffMillis: 1000, | |||
maxExpBackoffMillis: 60 * 60 * 1000, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/config.ts
Outdated
initialExpBackoffMillis: 1000, | ||
maxExpBackoffMillis: 60 * 60 * 1000, | ||
expBackoffMultiplier: 1.3, | ||
backoffLimitMillis: 7 * 24 * 60 * 60 * 1000, // 7 days |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
super(message.toString()); | ||
this.statusCode = response.statusCode; | ||
if (isServerBackoffResponse(response)) { | ||
this.backoffMillis = parseDuration(response.body.details.retryDelay); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
} | ||
getBackoff(): number { | ||
const curBackoff = this.nextBackoff; | ||
this.nextBackoff = this.backoffMultiplier * this.nextBackoff; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
@@ -201,29 +254,37 @@ export class Profiler extends common.ServiceObject { | |||
const delayMillis = await this.collectProfile(); | |||
|
|||
// Schedule the next profile. | |||
setTimeout(this.runLoop.bind(this), delayMillis).unref(); | |||
if (typeof delayMillis === 'number') { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
@@ -126,6 +137,48 @@ async function profileBytes(p: perftools.profiles.IProfile): Promise<string> { | |||
} | |||
|
|||
/** | |||
* Error which also indicates how long backoff should be in response to the |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
backoffMillis?: number; | ||
statusCode: number; | ||
constructor(response: http.ServerResponse) { | ||
let message: number|string = response.statusCode; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
*/ | ||
async collectProfile(): Promise<number> { | ||
async collectProfile(retryer?: Retryer): Promise<number|Retryer> { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
let prof: RequestProfile; | ||
try { | ||
prof = await this.createProfile(); | ||
} catch (err) { | ||
this.logger.error( | ||
`Error requesting profile type to be collected: ${err}.`); | ||
return this.config.backoffMillis; | ||
if (err.backoffMillis !== undefined) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
throw new Error(`Profile not valid: ${body}.`); | ||
} | ||
return body; | ||
return await new Promise<RequestProfile>((resolve, reject) => { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
*/ | ||
class BackoffResponseError extends Error { | ||
// tslint:disable-next-line: variable-name | ||
__proto__: Error; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/src/profiler.ts
Outdated
export class Retryer { | ||
private nextMaxBackoffMillis: number; | ||
constructor( | ||
private initialBackoffMillis: number, private maxBackoffMillis: number, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/test/test-init-config.ts
Outdated
initialBackoffMillis: 1000, | ||
maxBackoffMillis: 60 * 60 * 1000, | ||
backoffMultiplier: 1.3, | ||
backoffLimitMillis: 7 * 24 * 60 * 60 * 1000 |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/test/test-profiler.ts
Outdated
const profiler = new Profiler(testConfig); | ||
profiler.timeProfiler = instance(mockTimeProfiler); | ||
const delayMillis = await profiler.collectProfile(); | ||
assert.equal(7 * 24 * 60 * 60 * 1000, delayMillis); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
1f722d3
to
68b0b08
Compare
@nolanmar511, I am not sure why the bot is unhappy. Did you use a different computer, or edit your git config perhaps? |
I'm pretty sure the bot is unhappy after I merged. |
Can you revert #60 separately from this PR?
…On Mon, Nov 20, 2017 at 10:38 AM, Margaret Nolan ***@***.***> wrote:
With the changes from #60
<#60>
merged in, tests here started to fail and I couldn't figure out why. I
filed #68
<#68>
with more details on this.
This PR reverts #60
<#60>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#56 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABctwOvXFXuWDuAyboB9yIZk577s44b_ks5s4ccwgaJpZM4Qf3sX>
.
--
Alex
|
Also, with a PR in flight, never merge, rebase instead.
On Mon, Nov 20, 2017 at 12:25 PM, Alexey Alexandrov <aalexand@google.com>
wrote:
… Can you revert #60 separately from this PR?
On Mon, Nov 20, 2017 at 10:38 AM, Margaret Nolan ***@***.***
> wrote:
> With the changes from #60
> <#60>
> merged in, tests here started to fail and I couldn't figure out why. I
> filed #68
> <#68>
> with more details on this.
> This PR reverts #60
> <#60>.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#56 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABctwOvXFXuWDuAyboB9yIZk577s44b_ks5s4ccwgaJpZM4Qf3sX>
> .
>
--
Alex
--
Alex
|
b432afd
to
ddbafc4
Compare
PTAL |
69ebe62
to
5ea0f63
Compare
5ea0f63
to
5c79415
Compare
Closed, because I could not get the CLA approval again. |
Fixes #43 and #44