Skip to content

Commit

Permalink
chore: don't reference testutil from non-test code
Browse files Browse the repository at this point in the history
Update various receiver factories to stop using
testutil.EndpointForPort, and directly specify
the default endpoint.
  • Loading branch information
axw committed Jan 8, 2025
1 parent 2aa1d00 commit 9a83df2
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 56 deletions.
6 changes: 2 additions & 4 deletions receiver/awsfirehosereceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.opentelemetry.io/collector/receiver"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsfirehosereceiver/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsfirehosereceiver/internal/unmarshaler"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsfirehosereceiver/internal/unmarshaler/cwlog"
Expand All @@ -22,8 +21,7 @@ import (
)

const (
defaultEndpoint = "0.0.0.0:4433"
defaultPort = 4433
defaultEndpoint = "localhost:4433"
)

var (
Expand Down Expand Up @@ -78,7 +76,7 @@ func defaultLogsUnmarshalers(logger *zap.Logger) map[string]unmarshaler.LogsUnma
func createDefaultConfig() component.Config {
return &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: testutil.EndpointForPort(defaultPort),
Endpoint: defaultEndpoint,
},
}
}
Expand Down
5 changes: 2 additions & 3 deletions receiver/awsxrayreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/proxy"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsxrayreceiver/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsxrayreceiver/internal/udppoller"
)

const defaultPort = 2000
const defaultEndpoint = "localhost:2000"

// NewFactory creates a factory for AWS receiver.
func NewFactory() receiver.Factory {
Expand All @@ -33,7 +32,7 @@ func createDefaultConfig() component.Config {
// https://github.com/aws/aws-xray-daemon/blob/master/pkg/cfg/cfg.go#L99
return &Config{
AddrConfig: confignet.AddrConfig{
Endpoint: testutil.EndpointForPort(defaultPort),
Endpoint: defaultEndpoint,
Transport: udppoller.Transport,
},
ProxyServer: proxy.DefaultConfig(),
Expand Down
5 changes: 2 additions & 3 deletions receiver/influxdbreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/influxdbreceiver/internal/metadata"
)

const defaultPort = 8086
const defaultEndpoint = "localhost:8086"

func NewFactory() receiver.Factory {
return receiver.NewFactory(
Expand All @@ -28,7 +27,7 @@ func NewFactory() receiver.Factory {
func createDefaultConfig() component.Config {
return &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: testutil.EndpointForPort(defaultPort),
Endpoint: defaultEndpoint,
},
}
}
Expand Down
19 changes: 9 additions & 10 deletions receiver/jaegerreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/metadata"
)

Expand All @@ -27,11 +26,11 @@ const (
protoThriftBinary = "thrift_binary"
protoThriftCompact = "thrift_compact"

// Default ports to bind to.
defaultGRPCPort = 14250
defaultHTTPPort = 14268
defaultThriftCompactPort = 6831
defaultThriftBinaryPort = 6832
// Default endpoints to bind to.
defaultGRPCEndpoint = "localhost:14250"
defaultHTTPEndpoint = "localhost:14268"
defaultThriftCompactEndpoint = "localhost:6831"
defaultThriftBinaryEndpoint = "localhost:6832"
)

var disableJaegerReceiverRemoteSampling = featuregate.GlobalRegistry().MustRegister(
Expand All @@ -54,19 +53,19 @@ func createDefaultConfig() component.Config {
Protocols: Protocols{
GRPC: &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: testutil.EndpointForPort(defaultGRPCPort),
Endpoint: defaultGRPCEndpoint,
Transport: confignet.TransportTypeTCP,
},
},
ThriftHTTP: &confighttp.ServerConfig{
Endpoint: testutil.EndpointForPort(defaultHTTPPort),
Endpoint: defaultHTTPEndpoint,
},
ThriftBinary: &ProtocolUDP{
Endpoint: testutil.EndpointForPort(defaultThriftBinaryPort),
Endpoint: defaultThriftBinaryEndpoint,
ServerConfigUDP: defaultServerConfigUDP(),
},
ThriftCompact: &ProtocolUDP{
Endpoint: testutil.EndpointForPort(defaultThriftCompactPort),
Endpoint: defaultThriftCompactEndpoint,
ServerConfigUDP: defaultServerConfigUDP(),
},
},
Expand Down
11 changes: 4 additions & 7 deletions receiver/lokireceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/lokireceiver/internal/metadata"
)

const (
defaultGRPCPort = 3600
defaultHTTPPort = 3500
defaultGRPCBindEndpoint = "0.0.0.0:3600"
defaultHTTPBindEndpoint = "0.0.0.0:3500"
defaultGRPCEndpoint = "localhost:3600"
defaultHTTPEndpoint = "localhost:3500"
)

// NewFactory return a new receiver.Factory for loki receiver.
Expand All @@ -39,12 +36,12 @@ func createDefaultConfig() component.Config {
Protocols: Protocols{
GRPC: &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: testutil.EndpointForPort(defaultGRPCPort),
Endpoint: defaultGRPCEndpoint,
Transport: confignet.TransportTypeTCP,
},
},
HTTP: &confighttp.ServerConfig{
Endpoint: testutil.EndpointForPort(defaultHTTPPort),
Endpoint: defaultHTTPEndpoint,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/lokireceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestCreateReceiver(t *testing.T) {
cfg := factory.CreateDefaultConfig()
cfg.(*Config).Protocols.GRPC = &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: defaultGRPCBindEndpoint,
Endpoint: defaultGRPCEndpoint,
Transport: confignet.TransportTypeTCP,
},
}
Expand Down
5 changes: 2 additions & 3 deletions receiver/opencensusreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/opencensusreceiver/internal/metadata"
)

const grpcPort = 55678
const grpcEndpoint = "localhost:55678"

// NewFactory creates a new OpenCensus receiver factory.
func NewFactory() receiver.Factory {
Expand All @@ -32,7 +31,7 @@ func createDefaultConfig() component.Config {
return &Config{
ServerConfig: configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: testutil.EndpointForPort(grpcPort),
Endpoint: grpcEndpoint,
Transport: confignet.TransportTypeTCP,
},
// We almost write 0 bytes, so no need to tune WriteBufferSize.
Expand Down
7 changes: 3 additions & 4 deletions receiver/sapmreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver/internal/metadata"
)

const (
// Default port to bind to.
defaultPort = 7276
// Default endpoint to bind to.
defaultEndpoint = "localhost:7276"
)

// NewFactory creates a factory for SAPM receiver.
Expand All @@ -37,7 +36,7 @@ func NewFactory() receiver.Factory {
func createDefaultConfig() component.Config {
return &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: testutil.EndpointForPort(defaultPort),
Endpoint: defaultEndpoint,
},
}
}
Expand Down
7 changes: 3 additions & 4 deletions receiver/signalfxreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver/internal/metadata"
)

// This file implements factory for SignalFx receiver.

const (

// Default port to bind to.
defaultPort = 9943
// Default endpoint to bind to.
defaultEndpoint = "localhost:9943"
)

// NewFactory creates a factory for SignalFx receiver.
Expand All @@ -40,7 +39,7 @@ func NewFactory() receiver.Factory {
func createDefaultConfig() component.Config {
return &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: testutil.EndpointForPort(defaultPort),
Endpoint: defaultEndpoint,
},
}
}
Expand Down
11 changes: 5 additions & 6 deletions receiver/skywalkingreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/skywalkingreceiver/internal/metadata"
)
Expand All @@ -29,9 +28,9 @@ const (
protoGRPC = "grpc"
protoHTTP = "http"

// Default ports to bind to.
defaultGRPCPort = 11800
defaultHTTPPort = 12800
// Default endpoints to bind to.
defaultGRPCEndpoint = "localhost:11800"
defaultHTTPEndpoint = "localhost:12800"
)

// NewFactory creates a new Skywalking receiver factory.
Expand All @@ -49,12 +48,12 @@ func createDefaultConfig() component.Config {
Protocols: Protocols{
GRPC: &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: testutil.EndpointForPort(defaultGRPCPort),
Endpoint: defaultGRPCEndpoint,
Transport: confignet.TransportTypeTCP,
},
},
HTTP: &confighttp.ServerConfig{
Endpoint: testutil.EndpointForPort(defaultHTTPPort),
Endpoint: defaultHTTPEndpoint,
},
},
}
Expand Down
7 changes: 3 additions & 4 deletions receiver/splunkhecreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"go.opentelemetry.io/collector/receiver"
conventions "go.opentelemetry.io/collector/semconv/v1.27.0"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver/internal/metadata"
Expand All @@ -21,8 +20,8 @@ import (
// This file implements factory for Splunk HEC receiver.

const (
// Default endpoints to bind to.
defaultPort = 8088
// Default endpoint to bind to.
defaultEndpoint = "localhost:8088"
)

// NewFactory creates a factory for Splunk HEC receiver.
Expand All @@ -38,7 +37,7 @@ func NewFactory() receiver.Factory {
func createDefaultConfig() component.Config {
return &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: testutil.EndpointForPort(defaultPort),
Endpoint: defaultEndpoint,
},
AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{},
HecToOtelAttrs: splunk.HecToOtelAttrs{
Expand Down
6 changes: 2 additions & 4 deletions receiver/zipkinreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver/internal/metadata"
)

// This file implements factory for Zipkin receiver.

const (
defaultHTTPPort = 9411
defaultBindEndpoint = "localhost:9411"
defaultHTTPEndpoint = "localhost:9411"
)

// NewFactory creates a new Zipkin receiver factory
Expand All @@ -35,7 +33,7 @@ func NewFactory() receiver.Factory {
func createDefaultConfig() component.Config {
return &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: testutil.EndpointForPort(defaultHTTPPort),
Endpoint: defaultHTTPEndpoint,
},
ParseStringTags: false,
}
Expand Down
5 changes: 2 additions & 3 deletions receiver/zookeeperreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import (
"go.opentelemetry.io/collector/scraper"
"go.opentelemetry.io/collector/scraper/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zookeeperreceiver/internal/metadata"
)

const (
defaultPort = 2181
defaultEndpoint = "localhost:2181"
defaultCollectionInterval = 10 * time.Second
defaultTimeout = 10 * time.Second
)
Expand All @@ -40,7 +39,7 @@ func createDefaultConfig() component.Config {
return &Config{
ControllerConfig: cfg,
TCPAddrConfig: confignet.TCPAddrConfig{
Endpoint: testutil.EndpointForPort(defaultPort),
Endpoint: defaultEndpoint,
},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
Expand Down

0 comments on commit 9a83df2

Please sign in to comment.