Skip to content

Commit

Permalink
[chore] don't reference testutil from non-test code (#37090)
Browse files Browse the repository at this point in the history
#### Description

Update various receiver factories to stop using
testutil.EndpointForPort, and directly specify the default endpoint.
This removes test-related packages from the main binary's dependency
tree.

#### Link to tracking issue

N/A

#### Testing

N/A

#### Documentation

N/A
  • Loading branch information
axw authored Jan 8, 2025
1 parent 92ea44b commit 5825efc
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 84 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: 0 additions & 5 deletions receiver/awsfirehosereceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.22.0

require (
github.com/gogo/protobuf v1.3.2
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.117.0
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/collector/component v0.117.0
go.opentelemetry.io/collector/component/componentstatus v0.117.0
Expand Down Expand Up @@ -33,7 +32,6 @@ require (
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
Expand All @@ -53,7 +51,6 @@ require (
go.opentelemetry.io/collector/consumer/xconsumer v0.117.0 // indirect
go.opentelemetry.io/collector/extension v0.117.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.117.0 // indirect
go.opentelemetry.io/collector/featuregate v1.23.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.117.0 // indirect
go.opentelemetry.io/collector/pipeline v0.117.0 // indirect
go.opentelemetry.io/collector/receiver/xreceiver v0.117.0 // indirect
Expand All @@ -78,5 +75,3 @@ retract (
v0.76.1
v0.65.0
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common
4 changes: 0 additions & 4 deletions receiver/awsfirehosereceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
5 changes: 0 additions & 5 deletions receiver/skywalkingreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.22.0

require (
github.com/gorilla/mux v1.8.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.117.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.117.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/skywalking v0.117.0
github.com/stretchr/testify v1.10.0
Expand Down Expand Up @@ -39,7 +38,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
Expand All @@ -62,7 +60,6 @@ require (
go.opentelemetry.io/collector/consumer/xconsumer v0.117.0 // indirect
go.opentelemetry.io/collector/extension v0.117.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.117.0 // indirect
go.opentelemetry.io/collector/featuregate v1.23.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.117.0 // indirect
go.opentelemetry.io/collector/pipeline v0.117.0 // indirect
go.opentelemetry.io/collector/receiver/xreceiver v0.117.0 // indirect
Expand Down Expand Up @@ -90,5 +87,3 @@ retract (
v0.76.1
v0.65.0
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common
4 changes: 0 additions & 4 deletions receiver/skywalkingreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
Loading

0 comments on commit 5825efc

Please sign in to comment.