-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(exporters)!: use transport interface in node.js exporters #4743
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
Merged
pichlermarc
merged 18 commits into
open-telemetry:main
from
dynatrace-oss-contrib:feat/node-exporter-transport
Jul 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fb97582
feat(exporters)!: use transport interface in node.js exporters
pichlermarc cf6f479
feat(exporters): hide compression property
pichlermarc 4d785ce
feat(otlp-exporter-base)!: remove header property
pichlermarc e8635df
feat(otlp-exporter-base): add retrying transport
pichlermarc b039d49
fix: lint
pichlermarc c284ec4
chore: add changelog entry
pichlermarc 084a893
Merge branch 'main' into feat/node-exporter-transport
pichlermarc 6127207
Merge branch 'main' into feat/node-exporter-transport
pichlermarc 56a93de
Merge branch 'main' into feat/node-exporter-transport
pichlermarc b19734e
fix: use queueMicrotask over nextTick
pichlermarc 4df0efa
chore: move changelog entry to unreleased
pichlermarc 744c5f6
Merge branch 'main' into feat/node-exporter-transport
pichlermarc bb5ec8c
chore: note that user-agent cannot be overwritten by users anymore
pichlermarc 767eedc
fix: export missing ExportResponseRetryable
pichlermarc f1577c0
fix: retry jitter
pichlermarc a7f73a9
Merge branch 'main' into feat/node-exporter-transport
pichlermarc a071618
Merge branch 'main' into feat/node-exporter-transport
pichlermarc 0ad653e
Merge branch 'main' into feat/node-exporter-transport
pichlermarc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(otlp-exporter-base): add retrying transport
- Loading branch information
commit e8635df5f9bb791516f57ca55c7b02ffdc48dd6c
There are no files selected for viewing
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
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
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
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
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
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
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
66 changes: 66 additions & 0 deletions
66
experimental/packages/otlp-exporter-base/src/retryable-transport.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { IExporterTransport } from './exporter-transport'; | ||
| import { ExportResponse } from './export-response'; | ||
|
|
||
| const MAX_ATTEMPTS = 5; | ||
| const INITIAL_BACKOFF = 1000; | ||
| const MAX_BACKOFF = 5000; | ||
| const BACKOFF_MULTIPLIER = 1.5; | ||
|
|
||
| class RetryingTransport implements IExporterTransport { | ||
| constructor(private _transport: IExporterTransport) {} | ||
|
|
||
| private retry(data: Uint8Array, inMillis: number): Promise<ExportResponse> { | ||
| return new Promise((resolve, reject) => { | ||
| setTimeout(() => { | ||
| this._transport.send(data).then(resolve, reject); | ||
| }, inMillis); | ||
| }); | ||
| } | ||
|
|
||
| async send(data: Uint8Array): Promise<ExportResponse> { | ||
| let result = await this._transport.send(data); | ||
| let attempts = MAX_ATTEMPTS; | ||
| let nextBackoff = INITIAL_BACKOFF; | ||
|
|
||
| // TODO: I'm not 100% sure this is correct, please review in-depth. | ||
| while (result.status === 'retryable' && attempts > 0) { | ||
| attempts--; | ||
| const upperBound = Math.min(nextBackoff, MAX_BACKOFF); | ||
| const backoff = Math.random() * upperBound; | ||
| nextBackoff = nextBackoff * BACKOFF_MULTIPLIER; | ||
| result = await this.retry(data, result.retryInMillis ?? backoff); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| shutdown() { | ||
| return this._transport.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates an Exporter Transport that retries on 'retryable' response. | ||
| */ | ||
| export function createRetryingTransport(options: { | ||
| // Underlying transport to wrap. | ||
| transport: IExporterTransport; | ||
| }): IExporterTransport { | ||
| return new RetryingTransport(options.transport); | ||
| } | ||
Oops, something went wrong.
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.
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.
IIUC this is an iterative way of implementing exponential backoff (with 1,5 as exponent). What I do not fully get is this multiplication with
Math.rand()🤔With this randomness in place the waiting time between retries may not increase. We may even get small values consuming the reties very fast.
lowerBound?Math.min(nextBackoff, MAX_BACKOFF)? The progression is [1000, 1500, 2250, 3375, 5000, 5000 ...]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.
Ah yes you're right, that does not make any sense. 🤦 I think I was trying to implement a jitter but then failed to follow through on it and ended up with this thing. I think I fixed it in in f1577c0.
It takes the min of
nextBackoffandMAX_BACKOFFand then adds some jitter [-0.2ms, +0.2ms] to it. Would appreciate you having another look 👀