Skip to content

Commit

Permalink
[chore] Update confignet structs (open-telemetry#31354)
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerHelmuth authored Feb 21, 2024
1 parent afbd318 commit 7c5999f
Show file tree
Hide file tree
Showing 95 changed files with 214 additions and 214 deletions.
2 changes: 1 addition & 1 deletion exporter/carbonexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// Config defines configuration for Carbon exporter.
type Config struct {
// Specifies the connection endpoint config. The default value is "localhost:2003".
confignet.TCPAddr `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
confignet.TCPAddrConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
// MaxIdleConns is used to set a limit to the maximum idle TCP connections the client can keep open. Default value is 100.
// If `sending_queue` is enabled, it is recommended to use same value as `sending_queue::num_consumers`.
MaxIdleConns int `mapstructure:"max_idle_conns"`
Expand Down
10 changes: 5 additions & 5 deletions exporter/carbonexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestLoadConfig(t *testing.T) {
{
id: component.NewIDWithName(metadata.Type, "allsettings"),
expected: &Config{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "localhost:8080",
},
MaxIdleConns: 15,
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestValidateConfig(t *testing.T) {
{
name: "invalid_tcp_addr",
config: &Config{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "http://localhost:2003",
},
},
Expand All @@ -103,7 +103,7 @@ func TestValidateConfig(t *testing.T) {
{
name: "invalid_timeout",
config: &Config{
TCPAddr: confignet.TCPAddr{Endpoint: defaultEndpoint},
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: defaultEndpoint},
TimeoutSettings: exporterhelper.TimeoutSettings{
Timeout: -5 * time.Second,
},
Expand All @@ -113,8 +113,8 @@ func TestValidateConfig(t *testing.T) {
{
name: "invalid_max_idle_conns",
config: &Config{
TCPAddr: confignet.TCPAddr{Endpoint: defaultEndpoint},
MaxIdleConns: -1,
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: defaultEndpoint},
MaxIdleConns: -1,
},
wantErr: true,
},
Expand Down
10 changes: 5 additions & 5 deletions exporter/carbonexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func newCarbonExporter(ctx context.Context, cfg *Config, set exporter.CreateSettings) (exporter.Metrics, error) {
sender := carbonSender{
writeTimeout: cfg.Timeout,
conns: newConnPool(cfg.TCPAddr, cfg.Timeout, cfg.MaxIdleConns),
conns: newConnPool(cfg.TCPAddrConfig, cfg.Timeout, cfg.MaxIdleConns),
}

exp, err := exporterhelper.NewMetricsExporter(
Expand Down Expand Up @@ -104,7 +104,7 @@ type connPool interface {
}

func newConnPool(
tcpConfig confignet.TCPAddr,
tcpConfig confignet.TCPAddrConfig,
timeout time.Duration,
maxIdleConns int,
) connPool {
Expand All @@ -124,7 +124,7 @@ func newConnPool(
// nopConnPool is a very simple implementation that does not cache any net.Conn.
type nopConnPool struct {
timeout time.Duration
tcpConfig confignet.TCPAddr
tcpConfig confignet.TCPAddrConfig
}

func (cp *nopConnPool) get() (net.Conn, error) {
Expand All @@ -149,7 +149,7 @@ type connPoolWithIdle struct {
maxIdleConns int
mtx sync.Mutex
conns []net.Conn
tcpConfig confignet.TCPAddr
tcpConfig confignet.TCPAddrConfig
}

func (cp *connPoolWithIdle) get() (net.Conn, error) {
Expand Down Expand Up @@ -195,7 +195,7 @@ func (cp *connPoolWithIdle) close() error {
return errs
}

func createTCPConn(tcpConfig confignet.TCPAddr, timeout time.Duration) (net.Conn, error) {
func createTCPConn(tcpConfig confignet.TCPAddrConfig, timeout time.Duration) (net.Conn, error) {
c, err := net.DialTimeout("tcp", tcpConfig.Endpoint, timeout)
if err != nil {
return nil, err
Expand Down
16 changes: 8 additions & 8 deletions exporter/carbonexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestConsumeMetricsNoServer(t *testing.T) {
exp, err := newCarbonExporter(
context.Background(),
&Config{
TCPAddr: confignet.TCPAddr{Endpoint: testutil.GetAvailableLocalAddress(t)},
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: testutil.GetAvailableLocalAddress(t)},
TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: 5 * time.Second},
},
exportertest.NewNopCreateSettings())
Expand All @@ -61,7 +61,7 @@ func TestConsumeMetricsWithResourceToTelemetry(t *testing.T) {
exp, err := newCarbonExporter(
context.Background(),
&Config{
TCPAddr: confignet.TCPAddr{Endpoint: addr},
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: addr},
TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: 5 * time.Second},
ResourceToTelemetryConfig: resourcetotelemetry.Settings{Enabled: true},
},
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestConsumeMetrics(t *testing.T) {
exp, err := newCarbonExporter(
context.Background(),
&Config{
TCPAddr: confignet.TCPAddr{Endpoint: addr},
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: addr},
MaxIdleConns: tt.numProducers,
TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: 5 * time.Second},
},
Expand Down Expand Up @@ -159,8 +159,8 @@ func TestConsumeMetrics(t *testing.T) {
}

func TestNewConnectionPool(t *testing.T) {
assert.IsType(t, &nopConnPool{}, newConnPool(confignet.TCPAddr{Endpoint: defaultEndpoint}, 10*time.Second, 0))
assert.IsType(t, &connPoolWithIdle{}, newConnPool(confignet.TCPAddr{Endpoint: defaultEndpoint}, 10*time.Second, 10))
assert.IsType(t, &nopConnPool{}, newConnPool(confignet.TCPAddrConfig{Endpoint: defaultEndpoint}, 10*time.Second, 0))
assert.IsType(t, &connPoolWithIdle{}, newConnPool(confignet.TCPAddrConfig{Endpoint: defaultEndpoint}, 10*time.Second, 10))
}

func TestNopConnPool(t *testing.T) {
Expand All @@ -172,7 +172,7 @@ func TestNopConnPool(t *testing.T) {

cp := &nopConnPool{
timeout: 1 * time.Second,
tcpConfig: confignet.TCPAddr{Endpoint: addr},
tcpConfig: confignet.TCPAddrConfig{Endpoint: addr},
}

conn, err := cp.get()
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestConnPoolWithIdle(t *testing.T) {

cp := &connPoolWithIdle{
timeout: 1 * time.Second,
tcpConfig: confignet.TCPAddr{Endpoint: addr},
tcpConfig: confignet.TCPAddrConfig{Endpoint: addr},
maxIdleConns: 4,
}

Expand Down Expand Up @@ -234,7 +234,7 @@ func TestConnPoolWithIdleMaxConnections(t *testing.T) {

cp := &connPoolWithIdle{
timeout: 1 * time.Second,
tcpConfig: confignet.TCPAddr{Endpoint: addr},
tcpConfig: confignet.TCPAddrConfig{Endpoint: addr},
maxIdleConns: maxIdleConns,
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/carbonexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewFactory() exporter.Factory {

func createDefaultConfig() component.Config {
return &Config{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: defaultEndpoint,
},
MaxIdleConns: 100,
Expand Down
14 changes: 7 additions & 7 deletions exporter/datadogexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type MetricsConfig struct {

// TCPAddr.Endpoint is the host of the Datadog intake server to send metrics to.
// If unset, the value is obtained from the Site.
confignet.TCPAddr `mapstructure:",squash"`
confignet.TCPAddrConfig `mapstructure:",squash"`

ExporterConfig MetricsExporterConfig `mapstructure:",squash"`

Expand Down Expand Up @@ -248,7 +248,7 @@ type MetricsExporterConfig struct {
type TracesConfig struct {
// TCPAddr.Endpoint is the host of the Datadog intake server to send traces to.
// If unset, the value is obtained from the Site.
confignet.TCPAddr `mapstructure:",squash"`
confignet.TCPAddrConfig `mapstructure:",squash"`

// ignored resources
// A blacklist of regular expressions can be provided to disable certain traces based on their resource name
Expand Down Expand Up @@ -310,7 +310,7 @@ type TracesConfig struct {
type LogsConfig struct {
// TCPAddr.Endpoint is the host of the Datadog intake server to send logs to.
// If unset, the value is obtained from the Site.
confignet.TCPAddr `mapstructure:",squash"`
confignet.TCPAddrConfig `mapstructure:",squash"`

// DumpPayloads report whether payloads should be dumped when logging level is debug.
DumpPayloads bool `mapstructure:"dump_payloads"`
Expand Down Expand Up @@ -573,17 +573,17 @@ func (c *Config) Unmarshal(configMap *confmap.Conf) error {

// If an endpoint is not explicitly set, override it based on the site.
if !configMap.IsSet("metrics::endpoint") {
c.Metrics.TCPAddr.Endpoint = fmt.Sprintf("https://api.%s", c.API.Site)
c.Metrics.TCPAddrConfig.Endpoint = fmt.Sprintf("https://api.%s", c.API.Site)
}
if !configMap.IsSet("traces::endpoint") {
c.Traces.TCPAddr.Endpoint = fmt.Sprintf("https://trace.agent.%s", c.API.Site)
c.Traces.TCPAddrConfig.Endpoint = fmt.Sprintf("https://trace.agent.%s", c.API.Site)
}
if !configMap.IsSet("logs::endpoint") {
c.Logs.TCPAddr.Endpoint = fmt.Sprintf("https://http-intake.logs.%s", c.API.Site)
c.Logs.TCPAddrConfig.Endpoint = fmt.Sprintf("https://http-intake.logs.%s", c.API.Site)
}

// Return an error if an endpoint is explicitly set to ""
if c.Metrics.TCPAddr.Endpoint == "" || c.Traces.TCPAddr.Endpoint == "" || c.Logs.TCPAddr.Endpoint == "" {
if c.Metrics.TCPAddrConfig.Endpoint == "" || c.Traces.TCPAddrConfig.Endpoint == "" || c.Logs.TCPAddrConfig.Endpoint == "" {
return errEmptyEndpoint
}

Expand Down
6 changes: 3 additions & 3 deletions exporter/datadogexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (f *factory) createDefaultConfig() component.Config {
},

Metrics: MetricsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://api.datadoghq.com",
},
DeltaTTL: 3600,
Expand All @@ -210,14 +210,14 @@ func (f *factory) createDefaultConfig() component.Config {
},

Traces: TracesConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://trace.agent.datadoghq.com",
},
IgnoreResources: []string{},
},

Logs: LogsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://http-intake.logs.datadoghq.com",
},
},
Expand Down
36 changes: 18 additions & 18 deletions exporter/datadogexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestCreateDefaultConfig(t *testing.T) {
},

Metrics: MetricsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://api.datadoghq.com",
},
DeltaTTL: 3600,
Expand All @@ -98,13 +98,13 @@ func TestCreateDefaultConfig(t *testing.T) {
},

Traces: TracesConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://trace.agent.datadoghq.com",
},
IgnoreResources: []string{},
},
Logs: LogsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://http-intake.logs.datadoghq.com",
},
},
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestLoadConfig(t *testing.T) {
},

Metrics: MetricsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://api.datadoghq.com",
},
DeltaTTL: 3600,
Expand All @@ -160,13 +160,13 @@ func TestLoadConfig(t *testing.T) {
},

Traces: TracesConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://trace.agent.datadoghq.com",
},
IgnoreResources: []string{},
},
Logs: LogsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://http-intake.logs.datadoghq.com",
},
},
Expand All @@ -192,7 +192,7 @@ func TestLoadConfig(t *testing.T) {
FailOnInvalidKey: true,
},
Metrics: MetricsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://api.datadoghq.eu",
},
DeltaTTL: 3600,
Expand All @@ -209,7 +209,7 @@ func TestLoadConfig(t *testing.T) {
},
},
Traces: TracesConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://trace.agent.datadoghq.eu",
},
SpanNameRemappings: map[string]string{
Expand All @@ -221,7 +221,7 @@ func TestLoadConfig(t *testing.T) {
TraceBuffer: 10,
},
Logs: LogsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://http-intake.logs.datadoghq.eu",
},
},
Expand All @@ -247,7 +247,7 @@ func TestLoadConfig(t *testing.T) {
FailOnInvalidKey: false,
},
Metrics: MetricsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://api.datadoghq.test",
},
DeltaTTL: 3600,
Expand All @@ -264,7 +264,7 @@ func TestLoadConfig(t *testing.T) {
},
},
Traces: TracesConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://trace.agent.datadoghq.test",
},
SpanNameRemappings: map[string]string{
Expand All @@ -274,7 +274,7 @@ func TestLoadConfig(t *testing.T) {
IgnoreResources: []string{},
},
Logs: LogsConfig{
TCPAddr: confignet.TCPAddr{
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: "https://http-intake.logs.datadoghq.test",
},
},
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestCreateAPIMetricsExporter(t *testing.T) {
require.NoError(t, component.UnmarshalConfig(sub, cfg))

c := cfg.(*Config)
c.Metrics.TCPAddr.Endpoint = server.URL
c.Metrics.TCPAddrConfig.Endpoint = server.URL
c.HostMetadata.Enabled = false

ctx := context.Background()
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestCreateAPIExporterFailOnInvalidKey_Zorkian(t *testing.T) {

// Use the mock server for API key validation
c := cfg.(*Config)
c.Metrics.TCPAddr.Endpoint = server.URL
c.Metrics.TCPAddrConfig.Endpoint = server.URL
c.HostMetadata.Enabled = false

t.Run("true", func(t *testing.T) {
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestCreateAPIExporterFailOnInvalidKey(t *testing.T) {

// Use the mock server for API key validation
c := cfg.(*Config)
c.Metrics.TCPAddr.Endpoint = server.URL
c.Metrics.TCPAddrConfig.Endpoint = server.URL
c.HostMetadata.Enabled = false

t.Run("true", func(t *testing.T) {
Expand Down Expand Up @@ -599,7 +599,7 @@ func TestCreateAPILogsExporter(t *testing.T) {
require.NoError(t, component.UnmarshalConfig(sub, cfg))

c := cfg.(*Config)
c.Metrics.TCPAddr.Endpoint = server.URL
c.Metrics.TCPAddrConfig.Endpoint = server.URL
c.HostMetadata.Enabled = false

ctx := context.Background()
Expand All @@ -625,8 +625,8 @@ func TestOnlyMetadata(t *testing.T) {
QueueSettings: exporterhelper.NewDefaultQueueSettings(),

API: APIConfig{Key: "notnull"},
Metrics: MetricsConfig{TCPAddr: confignet.TCPAddr{Endpoint: server.URL}},
Traces: TracesConfig{TCPAddr: confignet.TCPAddr{Endpoint: server.URL}},
Metrics: MetricsConfig{TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL}},
Traces: TracesConfig{TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL}},
OnlyMetadata: true,

HostMetadata: HostMetadataConfig{
Expand Down
Loading

0 comments on commit 7c5999f

Please sign in to comment.