Skip to content
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

chore: remote write exporter retry on 429 #31924

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
48782d7
chore: remote write exporter retry on 429
jmichalek132 Mar 24, 2024
7759eee
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 1, 2024
bada035
chore: added config option for enabling retries on 429
jmichalek132 Apr 1, 2024
b02ee17
chore: added changelog entry
jmichalek132 Apr 1, 2024
cb490c5
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 1, 2024
da276b4
chore: updated prometheus remote write exporter readme
jmichalek132 Apr 1, 2024
640e166
chore: forgot to ran make fmt
jmichalek132 Apr 1, 2024
c9f678e
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 2, 2024
419cbc8
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 9, 2024
ea17e0b
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 10, 2024
15175f9
chore: make linter happy
jmichalek132 Apr 10, 2024
f961840
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 10, 2024
a1fddc7
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 11, 2024
2abc7f8
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 11, 2024
622b669
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 17, 2024
172796c
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 28, 2024
b3ddc1c
chore: switch from a config option to a feature flag
jmichalek132 Apr 28, 2024
5e08621
chore: sort imports
jmichalek132 Apr 28, 2024
e703603
chore: don't mention remove config option in readme
jmichalek132 Apr 28, 2024
68a7e41
chore: ran make gotidy
jmichalek132 Apr 28, 2024
34a24ca
chore: addressed feedback from review
jmichalek132 Apr 30, 2024
81c2fcc
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 Apr 30, 2024
f006fb8
chore: fixed tests
jmichalek132 Apr 30, 2024
bbfa39b
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 May 1, 2024
92d2e54
Update exporter/prometheusremotewriteexporter/factory.go
jmichalek132 May 8, 2024
71a5e9a
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 May 8, 2024
d3b838d
chore: ran make gotidy
jmichalek132 May 8, 2024
257af9c
chore: forgot to rename all occurences
jmichalek132 May 8, 2024
5bcdf5a
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 May 8, 2024
0c84688
Update exporter/prometheusremotewriteexporter/factory.go
mx-psi May 9, 2024
924a592
Update exporter/prometheusremotewriteexporter/factory.go
jmichalek132 May 10, 2024
da63469
Update .chloggen/prometheus-remote-write-exporter-retry-429.yaml
jmichalek132 May 10, 2024
c60985f
Update .chloggen/prometheus-remote-write-exporter-retry-429.yaml
jmichalek132 May 10, 2024
0e75ded
Merge branch 'main' into jm-chore-remote-write-exporter-retry-429
jmichalek132 May 10, 2024
745ce72
chore: mention feature gate in the readme
jmichalek132 May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/prometheus-remote-write-exporter-retry-429.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: prometheusremotewriteexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add `exporter.prometheusremotewritexporter.RetryOn429` feature gate to retry on http status code 429 response.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [ 31032 ]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: The feature gate is initially disabled by default.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
7 changes: 7 additions & 0 deletions exporter/prometheusremotewriteexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ Several helper files are leveraged to provide additional capabilities automatica
- [TLS and mTLS settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/README.md)
- [Retry and timeout settings](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/README.md), note that the exporter doesn't support `sending_queue` but provides `remote_write_queue`.

### Feature gates
dashpole marked this conversation as resolved.
Show resolved Hide resolved
This exporter has feature gate: `exporter.prometheusremotewritexporter.RetryOn429`.
When this feature gate is enable the prometheus remote write exporter will retry on 429 http status code with the provided retry configuration.
It currently doesn't support respecting the http header `Retry-After` if provided since the retry library used doesn't support this feature.

To enable it run collector with enabled feature gate `exporter.prometheusremotewritexporter.RetryOn429`. This can be done by executing it with one additional parameter - `--feature-gates=telemetry.useOtelForInternalMetrics`.

## Metric names and labels normalization

OpenTelemetry metric names and attributes are normalized to be compliant with Prometheus naming rules. [Details on this normalization process are described in the Prometheus translator module](../../pkg/translator/prometheus/).
Expand Down
9 changes: 9 additions & 0 deletions exporter/prometheusremotewriteexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type prwExporter struct {
clientSettings *confighttp.ClientConfig
settings component.TelemetrySettings
retrySettings configretry.BackOffConfig
retryOnHTTP429 bool
wal *prweWAL
exporterSettings prometheusremotewrite.Settings
telemetry prwTelemetry
Expand Down Expand Up @@ -124,6 +125,7 @@ func newPRWExporter(cfg *Config, set exporter.CreateSettings) (*prwExporter, err
clientSettings: &cfg.ClientConfig,
settings: set.TelemetrySettings,
retrySettings: cfg.BackOffConfig,
retryOnHTTP429: retryOn429FeatureGate.IsEnabled(),
exporterSettings: prometheusremotewrite.Settings{
Namespace: cfg.Namespace,
ExternalLabels: sanitizedLabels,
Expand Down Expand Up @@ -329,6 +331,13 @@ func (prwe *prwExporter) execute(ctx context.Context, writeReq *prompb.WriteRequ
if resp.StatusCode >= 500 && resp.StatusCode < 600 {
return rerr
}

// 429 errors are recoverable and the exporter should retry if RetryOnHTTP429 enabled
// Reference: https://github.com/prometheus/prometheus/pull/12677
if prwe.retryOnHTTP429 && resp.StatusCode == 429 {
return rerr
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved
}

return backoff.Permanent(consumererror.NewPermanent(rerr))
}

Expand Down
29 changes: 27 additions & 2 deletions exporter/prometheusremotewriteexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ func TestRetries(t *testing.T) {
serverErrorCount int // number of times server should return error
expectedAttempts int
httpStatus int
RetryOnHTTP429 bool
assertError assert.ErrorAssertionFunc
assertErrorType assert.ErrorAssertionFunc
ctx context.Context
Expand All @@ -1060,15 +1061,37 @@ func TestRetries(t *testing.T) {
3,
4,
http.StatusInternalServerError,
false,
assert.NoError,
assert.NoError,
context.Background(),
},
{
"test 429 should retry",
3,
4,
http.StatusTooManyRequests,
true,
assert.NoError,
assert.NoError,
context.Background(),
},
{
"test 429 should not retry",
4,
1,
http.StatusTooManyRequests,
false,
assert.Error,
assertPermanentConsumerError,
context.Background(),
},
{
"test 4xx should not retry",
4,
1,
http.StatusBadRequest,
false,
assert.Error,
assertPermanentConsumerError,
context.Background(),
Expand All @@ -1078,6 +1101,7 @@ func TestRetries(t *testing.T) {
4,
0,
http.StatusInternalServerError,
false,
assert.Error,
assertPermanentConsumerError,
canceledContext(),
Expand All @@ -1103,8 +1127,9 @@ func TestRetries(t *testing.T) {

// Create the prwExporter
exporter := &prwExporter{
endpointURL: endpointURL,
client: http.DefaultClient,
endpointURL: endpointURL,
client: http.DefaultClient,
retryOnHTTP429: tt.RetryOnHTTP429,
retrySettings: configretry.BackOffConfig{
Enabled: true,
},
Expand Down
8 changes: 8 additions & 0 deletions exporter/prometheusremotewriteexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ import (
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/featuregate"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry"
)

var retryOn429FeatureGate = featuregate.GlobalRegistry().MustRegister(
"exporter.prometheusremotewritexporter.RetryOn429",
featuregate.StageAlpha,
featuregate.WithRegisterFromVersion("v0.101.0"),
featuregate.WithRegisterDescription("When enabled, the Prometheus remote write exporter will retry 429 http status code. Requires exporter.prometheusremotewritexporter.metrics.RetryOn429 to be enabled."),
)

// NewFactory creates a new Prometheus Remote Write exporter.
func NewFactory() exporter.Factory {
return exporter.NewFactory(
Expand Down
2 changes: 1 addition & 1 deletion exporter/prometheusremotewriteexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
go.opentelemetry.io/collector/confmap v0.100.0
go.opentelemetry.io/collector/consumer v0.100.0
go.opentelemetry.io/collector/exporter v0.100.0
go.opentelemetry.io/collector/featuregate v1.7.0
go.opentelemetry.io/collector/pdata v1.7.0
go.opentelemetry.io/otel v1.26.0
go.opentelemetry.io/otel/metric v1.26.0
Expand Down Expand Up @@ -67,7 +68,6 @@ require (
go.opentelemetry.io/collector/config/internal v0.100.0 // indirect
go.opentelemetry.io/collector/extension v0.100.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.100.0 // indirect
go.opentelemetry.io/collector/featuregate v1.7.0 // indirect
go.opentelemetry.io/collector/receiver v0.100.0 // indirect
go.opentelemetry.io/collector/semconv v0.100.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
Expand Down