This repository was archived by the owner on Aug 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
fix: put [5s, 1d] range guard on the delay before re-fetching central config #185
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trentm
commented
Oct 24, 2022
astorm
approved these changes
Oct 25, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Does the thing and preserves most of the old behavior for the edge case arguments (0
, other false-y values result in 300
-- true
now comes through at 5
instead of 1
, which is inline with the change). Strings still result in NaN
(per the previous algorithm), which is a little weird but it's not a public API so that doesn't seem like an edge case worth fixing.
+--------------------------------+
| Sec. Input | Calculated Delay |
+--------------------------------+
| -4 | 5 |
| -3 | 5 |
| -2 | 5 |
| -1 | 5 |
| 0 | 300 |
| 1 | 5 |
| 2 | 5 |
| 3 | 5 |
| 4 | 5 |
| 5 | 5 |
| 6 | 6 |
| 7 | 7 |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| 86398 | 86398 |
| 86399 | 86399 |
| 86400 | 86400 |
| 86401 | 86400 |
| 86402 | 86400 |
| 86403 | 86400 |
| 86404 | 86400 |
| null | 300 |
| undefined | 300 |
| FALSE | 300 |
| TRUE | 5 |
| “a string” | NaN |
+--------------------------------+
Agreed. Thanks. I've improved it to return the default value for any non-positive number. From a test run:
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refs: elastic/apm-agent-nodejs#2941
The spec change requires a minimum 5s delay for refetching central config. The Node.js APM agent didn't have the "spin loop fetching central config from
Cache-Control: max-age=0
" issue. However, theoretically a large max-age value could overflow the maxsetTimeout
delay (https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value) which could result in a similar spin loop. I picked a maximum value of 1 day -- a large enough value that I cannot imagine it getting in a way of a legitimate max-age value from the APM server.It might be worth adding a max guard to the spec.