-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[exporter/datadogexporter] Retry per network call #6412
Merged
codeboten
merged 7 commits into
open-telemetry:main
from
DataDog:mx-psi/retries-per-network-call
Dec 2, 2021
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4bf2e46
[exporter/datadogexporter] Refactor metadata retrier to take RetrySet…
mx-psi 2366398
[exporter/datadogexporter] Do retries per network call on the metrics…
mx-psi c8b1554
Merge branch 'main' into mx-psi/retries-per-network-call
mx-psi 0b5a5da
Address review comment
mx-psi 1a8d05d
Merge remote-tracking branch 'upstream/main' into mx-psi/retries-per-…
mx-psi 7f7b2e2
Merge branch 'main' into mx-psi/retries-per-network-call
mx-psi 3e21ff7
Fix lint
mx-psi 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
There are no files selected for viewing
This file contains 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 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 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 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 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 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,97 @@ | ||
// 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 | ||
// | ||
// http://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. | ||
|
||
package utils | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/cenkalti/backoff/v4" | ||
"go.opentelemetry.io/collector/consumer/consumererror" | ||
"go.opentelemetry.io/collector/exporter/exporterhelper" | ||
"go.uber.org/zap" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/scrub" | ||
) | ||
|
||
type Retrier struct { | ||
cfg exporterhelper.RetrySettings | ||
logger *zap.Logger | ||
scrubber scrub.Scrubber | ||
} | ||
|
||
func NewRetrier(logger *zap.Logger, settings exporterhelper.RetrySettings, scrubber scrub.Scrubber) *Retrier { | ||
return &Retrier{ | ||
cfg: settings, | ||
logger: logger, | ||
scrubber: scrubber, | ||
} | ||
} | ||
|
||
// DoWithRetries does a function with retries. This is a condensed version of the code on | ||
// the exporterhelper, which we reuse here since we want custom retry logic. | ||
func (r *Retrier) DoWithRetries(ctx context.Context, fn func(context.Context) error) error { | ||
if !r.cfg.Enabled { | ||
return fn(ctx) | ||
} | ||
|
||
// Do not use NewExponentialBackOff since it calls Reset and the code here must | ||
// call Reset after changing the InitialInterval (this saves an unnecessary call to Now). | ||
expBackoff := backoff.ExponentialBackOff{ | ||
InitialInterval: r.cfg.InitialInterval, | ||
RandomizationFactor: backoff.DefaultRandomizationFactor, | ||
Multiplier: backoff.DefaultMultiplier, | ||
MaxInterval: r.cfg.MaxInterval, | ||
MaxElapsedTime: r.cfg.MaxElapsedTime, | ||
Stop: backoff.Stop, | ||
Clock: backoff.SystemClock, | ||
} | ||
expBackoff.Reset() | ||
retryNum := int64(0) | ||
for { | ||
err := fn(ctx) | ||
if err == nil { | ||
return nil | ||
} | ||
|
||
err = r.scrubber.Scrub(err) | ||
|
||
if consumererror.IsPermanent(err) { | ||
return err | ||
} | ||
|
||
backoffDelay := expBackoff.NextBackOff() | ||
if backoffDelay == backoff.Stop { | ||
err = fmt.Errorf("max elapsed time expired %w", err) | ||
return err | ||
} | ||
|
||
backoffDelayStr := backoffDelay.String() | ||
r.logger.Info( | ||
"Request failed. Will retry the request after interval.", | ||
zap.Error(err), | ||
zap.String("interval", backoffDelayStr), | ||
) | ||
retryNum++ | ||
|
||
// back-off, but get interrupted when shutting down or request is cancelled or timed out. | ||
select { | ||
case <-ctx.Done(): | ||
return fmt.Errorf("request is cancelled or timed out %w", err) | ||
case <-time.After(backoffDelay): | ||
} | ||
} | ||
} |
This file contains 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
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.
This looks like a breaking change. Could you add this to the changelog? Make sure also to add this to the readme. Is there a way to determine whether the retry settings were customized by users, and warn them?
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.
Retry settings will still be used here
opentelemetry-collector-contrib/exporter/datadogexporter/internal/utils/retrier.go
Lines 53 to 61 in 3e21ff7
ConsumeMetrics
function (so, we disable theexporterhelper
retry mechanism). I believe this change should be transparent to users and it will probably align closer with what one would expect from the retry settings.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.
Got it! Makes sense then.