Skip to content

Commit

Permalink
[chore] [receiver/apachespark] Use NewDefaultClientConfig instead of …
Browse files Browse the repository at this point in the history
…manually creating struct (#35578)

**Description:**
This PR makes usage of `NewDefaultClientConfig` instead of manually
creating the confighttp.ClientConfig struct.

**Link to tracking Issue:** #35457
  • Loading branch information
mackjmr authored Oct 28, 2024
1 parent 3b31e40 commit 859ea73
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions receiver/apachesparkreceiver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
)

func TestNewApacheSparkClient(t *testing.T) {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = defaultEndpoint
testCases := []struct {
desc string
cfg *Config
Expand All @@ -39,9 +41,7 @@ func TestNewApacheSparkClient(t *testing.T) {
{
desc: "Valid Configuration",
cfg: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultEndpoint,
},
ClientConfig: clientConfig,
},
host: componenttest.NewNopHost(),
settings: componenttest.NewNopTelemetrySettings(),
Expand Down
6 changes: 3 additions & 3 deletions receiver/apachesparkreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

func TestValidate(t *testing.T) {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "invalid://endpoint 12efg"
testCases := []struct {
desc string
cfg *Config
Expand All @@ -27,9 +29,7 @@ func TestValidate(t *testing.T) {
{
desc: "invalid endpoint",
cfg: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: "invalid://endpoint 12efg",
},
ClientConfig: clientConfig,
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
},
expectedErr: errInvalidEndpoint,
Expand Down
9 changes: 4 additions & 5 deletions receiver/apachesparkreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ func NewFactory() receiver.Factory {
func createDefaultConfig() component.Config {
cfg := scraperhelper.NewDefaultControllerConfig()
cfg.CollectionInterval = defaultCollectionInterval

clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = defaultEndpoint
return &Config{
ControllerConfig: cfg,
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultEndpoint,
},
ControllerConfig: cfg,
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
}
Expand Down
7 changes: 4 additions & 3 deletions receiver/apachesparkreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
)

func TestNewFactory(t *testing.T) {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = defaultEndpoint

testCases := []struct {
desc string
testFunc func(*testing.T)
Expand All @@ -40,9 +43,7 @@ func TestNewFactory(t *testing.T) {
CollectionInterval: defaultCollectionInterval,
InitialDelay: time.Second,
},
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultEndpoint,
},
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}

Expand Down
14 changes: 6 additions & 8 deletions receiver/apachesparkreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
)

func TestScraper(t *testing.T) {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = defaultEndpoint
testcases := []struct {
desc string
setupMockClient func(t *testing.T) client
Expand Down Expand Up @@ -68,10 +70,8 @@ func TestScraper(t *testing.T) {
config: &Config{ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: defaultCollectionInterval,
},
ApplicationNames: []string{"local-123", "local-987"},
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultEndpoint,
},
ApplicationNames: []string{"local-123", "local-987"},
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
},
expectedErr: errNoMatchingAllowedApps,
Expand Down Expand Up @@ -215,10 +215,8 @@ func TestScraper(t *testing.T) {
config: &Config{ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: defaultCollectionInterval,
},
ApplicationNames: []string{"streaming-example"},
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultEndpoint,
},
ApplicationNames: []string{"streaming-example"},
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
},
expectedErr: nil,
Expand Down

0 comments on commit 859ea73

Please sign in to comment.