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] [receiver/bigip] Use confighttp.NewDefaultClientConfig instead of manually creating struct #35586

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 4 additions & 4 deletions receiver/bigipreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func NewFactory() receiver.Factory {

// createDefaultConfig creates a config for Big-IP with as many default values as possible
func createDefaultConfig() component.Config {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = defaultEndpoint
clientConfig.Timeout = 10 * time.Second
return &Config{
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: 10 * time.Second,
},
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultEndpoint,
Timeout: 10 * time.Second,
},
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
}
Expand Down
16 changes: 14 additions & 2 deletions receiver/bigipreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package bigipreceiver // import "github.com/open-telemetry/opentelemetry-collect

import (
"context"
"net/http"
"testing"
"time"

"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/consumer/consumertest"
"go.opentelemetry.io/collector/receiver/receivertest"
"go.opentelemetry.io/collector/receiver/scraperhelper"
Expand All @@ -19,6 +21,11 @@ import (
)

func TestNewFactory(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

testCases := []struct {
desc string
testFunc func(*testing.T)
Expand All @@ -40,8 +47,13 @@ func TestNewFactory(t *testing.T) {
CollectionInterval: 10 * time.Second,
},
ClientConfig: confighttp.ClientConfig{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create this config using the confighttp.NewDefaultClientConfig() method, then override values?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as: #35578 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated tests

Endpoint: defaultEndpoint,
Timeout: 10 * time.Second,
Endpoint: defaultEndpoint,
Timeout: 10 * time.Second,
MaxIdleConns: &defaultMaxIdleConns,
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &defaultIdleConnTimeout,
Headers: map[string]configopaque.String{},
},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
Expand Down
Loading