Skip to content

Commit ee4934d

Browse files
rogercollsbylica-splunk
authored andcommitted
[chore] [receiver/elasticsearch] Use NewDefaultClientConfig instead of manual initialization (open-telemetry#35509)
**Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> Similar to open-telemetry#35452 but for the `elasticsearch` receiver. **Link to tracking Issue:** <Issue number if applicable> open-telemetry#35457 **Testing:** <Describe what testing was performed and which tests were added.> **Documentation:** <Describe the documentation added.>
1 parent 52dd42a commit ee4934d

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

receiver/elasticsearchreceiver/config_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package elasticsearchreceiver
55

66
import (
7+
"net/http"
78
"path/filepath"
89
"testing"
910
"time"
@@ -14,6 +15,7 @@ import (
1415
"github.com/stretchr/testify/require"
1516
"go.opentelemetry.io/collector/component"
1617
"go.opentelemetry.io/collector/config/confighttp"
18+
"go.opentelemetry.io/collector/config/configopaque"
1719
"go.opentelemetry.io/collector/confmap/confmaptest"
1820
"go.opentelemetry.io/collector/receiver/scraperhelper"
1921

@@ -138,6 +140,11 @@ func TestValidateEndpoint(t *testing.T) {
138140
}
139141

140142
func TestLoadConfig(t *testing.T) {
143+
defaultMaxIdleConns := http.DefaultTransport.(*http.Transport).MaxIdleConns
144+
defaultMaxIdleConnsPerHost := http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost
145+
defaultMaxConnsPerHost := http.DefaultTransport.(*http.Transport).MaxConnsPerHost
146+
defaultIdleConnTimeout := http.DefaultTransport.(*http.Transport).IdleConnTimeout
147+
141148
t.Parallel()
142149

143150
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
@@ -167,8 +174,13 @@ func TestLoadConfig(t *testing.T) {
167174
Username: "otel",
168175
Password: "password",
169176
ClientConfig: confighttp.ClientConfig{
170-
Timeout: 10000000000,
171-
Endpoint: "http://example.com:9200",
177+
Timeout: 10000000000,
178+
Endpoint: "http://example.com:9200",
179+
Headers: map[string]configopaque.String{},
180+
MaxIdleConns: &defaultMaxIdleConns,
181+
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
182+
MaxConnsPerHost: &defaultMaxConnsPerHost,
183+
IdleConnTimeout: &defaultIdleConnTimeout,
172184
},
173185
},
174186
},

receiver/elasticsearchreceiver/factory.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ func createDefaultConfig() component.Config {
3535
cfg := scraperhelper.NewDefaultControllerConfig()
3636
cfg.CollectionInterval = defaultCollectionInterval
3737

38+
clientConfig := confighttp.NewDefaultClientConfig()
39+
clientConfig.Endpoint = defaultEndpoint
40+
clientConfig.Timeout = defaultHTTPClientTimeout
41+
3842
return &Config{
39-
ControllerConfig: cfg,
40-
ClientConfig: confighttp.ClientConfig{
41-
Endpoint: defaultEndpoint,
42-
Timeout: defaultHTTPClientTimeout,
43-
},
43+
ControllerConfig: cfg,
44+
ClientConfig: clientConfig,
4445
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
4546
Nodes: []string{"_all"},
4647
Indices: []string{"_all"},

0 commit comments

Comments
 (0)