Skip to content

Commit 65c4a22

Browse files
carsonipChrsMark
andauthored
[exporter/elasticsearch] Fix incorrect retry backoff duration calculation (open-telemetry#41188)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR fixes a bug where backoff function is stateful and shared between bulk indexers, resulting in data race and incorrect retry backoff duration calculation. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#41187 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Christos Markou <[email protected]>
1 parent 265799d commit 65c4a22

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: elasticsearchexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix incorrect retry backoff duration calculation
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [41187]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: Fixes a bug where backoff function is stateful and shared between bulk indexers, resulting in data race and incorrect retry backoff duration calculation.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/elasticsearchexporter/esclient.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11+
"math/rand/v2"
1112
"net/http"
1213
"time"
1314

14-
"github.com/cenkalti/backoff/v4"
1515
elasticsearchv8 "github.com/elastic/go-elasticsearch/v8"
1616
"github.com/elastic/go-elasticsearch/v8/esapi"
1717
"github.com/klauspost/compress/gzip"
@@ -168,21 +168,10 @@ func createElasticsearchBackoffFunc(config *RetrySettings) func(int) time.Durati
168168
return nil
169169
}
170170

171-
expBackoff := backoff.NewExponentialBackOff()
172-
if config.InitialInterval > 0 {
173-
expBackoff.InitialInterval = config.InitialInterval
174-
}
175-
if config.MaxInterval > 0 {
176-
expBackoff.MaxInterval = config.MaxInterval
177-
}
178-
expBackoff.Reset()
179-
180171
return func(attempts int) time.Duration {
181-
if attempts == 1 {
182-
expBackoff.Reset()
183-
}
184-
185-
return expBackoff.NextBackOff()
172+
next := min(config.MaxInterval, config.InitialInterval*(1<<(attempts-1)))
173+
nextWithJitter := next/2 + time.Duration(rand.Float64()*float64(next/2))
174+
return nextWithJitter
186175
}
187176
}
188177

exporter/elasticsearchexporter/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasti
33
go 1.23.0
44

55
require (
6-
github.com/cenkalti/backoff/v4 v4.3.0
76
github.com/cespare/xxhash v1.1.0
87
github.com/elastic/go-docappender/v2 v2.10.0
98
github.com/elastic/go-elasticsearch/v8 v8.18.1

exporter/elasticsearchexporter/go.sum

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)