Skip to content

Commit

Permalink
[chore] [receiver/elasticsearch] Use NewDefaultClientConfig instead o…
Browse files Browse the repository at this point in the history
…f 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.>
  • Loading branch information
rogercoll authored and jmichalek132 committed Oct 10, 2024
1 parent def91cd commit 1fae88b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
16 changes: 14 additions & 2 deletions receiver/elasticsearchreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package elasticsearchreceiver

import (
"net/http"
"path/filepath"
"testing"
"time"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/receiver/scraperhelper"

Expand Down Expand Up @@ -138,6 +140,11 @@ func TestValidateEndpoint(t *testing.T) {
}

func TestLoadConfig(t *testing.T) {
defaultMaxIdleConns := http.DefaultTransport.(*http.Transport).MaxIdleConns
defaultMaxIdleConnsPerHost := http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost
defaultMaxConnsPerHost := http.DefaultTransport.(*http.Transport).MaxConnsPerHost
defaultIdleConnTimeout := http.DefaultTransport.(*http.Transport).IdleConnTimeout

t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
Expand Down Expand Up @@ -167,8 +174,13 @@ func TestLoadConfig(t *testing.T) {
Username: "otel",
Password: "password",
ClientConfig: confighttp.ClientConfig{
Timeout: 10000000000,
Endpoint: "http://example.com:9200",
Timeout: 10000000000,
Endpoint: "http://example.com:9200",
Headers: map[string]configopaque.String{},
MaxIdleConns: &defaultMaxIdleConns,
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &defaultIdleConnTimeout,
},
},
},
Expand Down
11 changes: 6 additions & 5 deletions receiver/elasticsearchreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ func createDefaultConfig() component.Config {
cfg := scraperhelper.NewDefaultControllerConfig()
cfg.CollectionInterval = defaultCollectionInterval

clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = defaultEndpoint
clientConfig.Timeout = defaultHTTPClientTimeout

return &Config{
ControllerConfig: cfg,
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultEndpoint,
Timeout: defaultHTTPClientTimeout,
},
ControllerConfig: cfg,
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Nodes: []string{"_all"},
Indices: []string{"_all"},
Expand Down

0 comments on commit 1fae88b

Please sign in to comment.