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

[confignet] Change Transport from string to TransportType #9385

Merged
merged 23 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e827df2
Change Transport from string to TransportType
TylerHelmuth Jan 24, 2024
3094f16
Changelog
TylerHelmuth Jan 24, 2024
5280d66
update names
TylerHelmuth Jan 24, 2024
68f1f55
Update enum names
TylerHelmuth Jan 29, 2024
f936981
Merge branch 'main' into confignet-transport-type
TylerHelmuth Feb 1, 2024
d6df3f2
Update config field name to TransportType
TylerHelmuth Feb 1, 2024
687ec3f
Fix tests
TylerHelmuth Feb 1, 2024
49ad71f
Apply suggestions from code review
TylerHelmuth Feb 2, 2024
631721f
Dont break user configs
TylerHelmuth Feb 2, 2024
1f8d0d0
merge upstream/main
TylerHelmuth Feb 2, 2024
aa4b6a1
Merge branch 'main' into confignet-transport-type
TylerHelmuth Feb 2, 2024
517e516
Apply feedback
TylerHelmuth Feb 12, 2024
755576b
Merge branch 'confignet-transport-type' of https://github.com/TylerHe…
TylerHelmuth Feb 12, 2024
a89b7f3
merge in upstream/main
TylerHelmuth Feb 12, 2024
3554450
Adjust Unmarshal
TylerHelmuth Feb 12, 2024
602ba2d
Revert Unmarshal change
TylerHelmuth Feb 12, 2024
44dda15
Merge in upstream/main
TylerHelmuth Feb 13, 2024
a4a33a8
implement change as a single API breaking change
TylerHelmuth Mar 13, 2024
00aea6a
Cleanup comments
TylerHelmuth Mar 13, 2024
92ec983
Merge remote-tracking branch 'upstream/main' into confignet-transport…
TylerHelmuth Mar 13, 2024
83305d4
Merge remote-tracking branch 'upstream/main' into confignet-transport…
TylerHelmuth Mar 13, 2024
7c62f5a
Fix type reference
TylerHelmuth Mar 13, 2024
21608ea
Add test for UnmarshalText
TylerHelmuth Mar 13, 2024
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
25 changes: 25 additions & 0 deletions .chloggen/confignet-transport-type.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: confignet

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Change `Transport` field from `string` to `TransportType`

# One or more tracking issues or pull requests related to the change
issues: [9385]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
4 changes: 2 additions & 2 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ func (gss *GRPCServerSettings) ToServer(host component.Host, settings component.
}

func (gss *GRPCServerSettings) toServerOption(host component.Host, settings component.TelemetrySettings) ([]grpc.ServerOption, error) {
switch gss.NetAddr.Transport {
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
switch gss.NetAddr.TransportType {
case confignet.TransportTypeTCP, confignet.TransportTypeTCP4, confignet.TransportTypeTCP6, confignet.TransportTypeUDP, confignet.TransportTypeUDP4, confignet.TransportTypeUDP6:
internal.WarnOnUnspecifiedHost(settings.Logger, gss.NetAddr.Endpoint)
}

Expand Down
10 changes: 5 additions & 5 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ func TestGRPCServerWarning(t *testing.T) {
{
settings: GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:1234",
Transport: "tcp",
Endpoint: "0.0.0.0:1234",
TransportType: confignet.TransportTypeTCP,
},
},
len: 1,
Expand Down Expand Up @@ -701,7 +701,7 @@ func TestContextWithClient(t *testing.T) {
expected: client.Info{},
},
{
desc: "existing client with IP, no peer information",
desc: "existing client with TransportTypeIP, no peer information",
input: client.NewContext(context.Background(), client.Info{
Addr: &net.IPAddr{
IP: net.IPv4(1, 2, 3, 4),
Expand All @@ -727,7 +727,7 @@ func TestContextWithClient(t *testing.T) {
},
},
{
desc: "existing client, existing IP gets overridden with peer information",
desc: "existing client, existing TransportTypeIP gets overridden with peer information",
input: peer.NewContext(client.NewContext(context.Background(), client.Info{
Addr: &net.IPAddr{
IP: net.IPv4(1, 2, 3, 4),
Expand Down Expand Up @@ -1074,7 +1074,7 @@ func (gts *grpcTraceServer) Export(ctx context.Context, _ ptraceotlp.ExportReque
return ptraceotlp.NewExportResponse(), nil
}

// tempSocketName provides a temporary Unix socket name for testing.
// tempSocketName provides a temporary TransportTypeUnix socket name for testing.
func tempSocketName(t *testing.T) string {
tmpfile, err := os.CreateTemp("", "sock")
require.NoError(t, err)
Expand Down
76 changes: 68 additions & 8 deletions config/confignet/confignet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,53 @@

import (
"context"
"fmt"
"net"
"time"
)

// TransportType represents a type of network transport protocol
type TransportType string
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved

const (
TransportTypeTCP TransportType = "tcp"
TransportTypeTCP4 TransportType = "tcp4"
TransportTypeTCP6 TransportType = "tcp6"
TransportTypeUDP TransportType = "udp"
TransportTypeUDP4 TransportType = "udp4"
TransportTypeUDP6 TransportType = "udp6"
TransportTypeIP TransportType = "ip"
TransportTypeIP4 TransportType = "ip4"
TransportTypeIP6 TransportType = "ip6"
TransportTypeUnix TransportType = "unix"
TransportTypeUnixgram TransportType = "unixgram"
TransportTypeUnixPacket TransportType = "unixpacket"
)

// UnmarshalText unmarshalls text to a TransportType.
// Valid values are "tcp", "tcp4", "tcp6", "udp", "udp4",
// "udp6", "ip", "ip4", "ip6", "unix", "unixgram" and "unixpacket"
func (tt *TransportType) UnmarshalText(in []byte) error {
switch typ := TransportType(in); typ {

Check warning on line 35 in config/confignet/confignet.go

View check run for this annotation

Codecov / codecov/patch

config/confignet/confignet.go#L34-L35

Added lines #L34 - L35 were not covered by tests
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
case TransportTypeTCP,
TransportTypeTCP4,
TransportTypeTCP6,
TransportTypeUDP,
TransportTypeUDP4,
TransportTypeUDP6,
TransportTypeIP,
TransportTypeIP4,
TransportTypeIP6,
TransportTypeUnix,
TransportTypeUnixgram,
TransportTypeUnixPacket:
*tt = typ
return nil
default:
return fmt.Errorf("unsupported transport type %q", typ)

Check warning on line 51 in config/confignet/confignet.go

View check run for this annotation

Codecov / codecov/patch

config/confignet/confignet.go#L47-L51

Added lines #L47 - L51 were not covered by tests
}
}

// DialerConfig contains options for connecting to an address.
type DialerConfig struct {
// Timeout is the maximum amount of time a dial will wait for
Expand All @@ -19,37 +62,54 @@
// NetAddr represents a network endpoint address.
type NetAddr struct {
// Endpoint configures the address for this network connection.
// For TCP and UDP networks, the address has the form "host:port". The host must be a literal IP address,
// or a host name that can be resolved to IP addresses. The port must be a literal port number or a service name.
// For TransportTypeTCP and TransportTypeUDP networks, the address has the form "host:port". The host must be a literal TransportTypeIP address,
// or a host name that can be resolved to TransportTypeIP addresses. The port must be a literal port number or a service name.
// If the host is a literal IPv6 address it must be enclosed in square brackets, as in "[2001:db8::1]:80" or
// "[fe80::1%zone]:80". The zone specifies the scope of the literal IPv6 address as defined in RFC 4007.
Endpoint string `mapstructure:"endpoint"`

// Transport to use. Known protocols are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only),
// "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix", "unixgram" and "unixpacket".
// Deprecated: [0.94.0] Use TransportType instead
Transport string `mapstructure:"transport"`

// TransportType to use. Allowed protocols are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only),
// "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix", "unixgram" and "unixpacket".
TransportType TransportType `mapstructure:"transport_type"`

// DialerConfig contains options for connecting to an address.
DialerConfig DialerConfig `mapstructure:"dialer"`
}

// Dial equivalent with net.Dialer's DialContext for this address.
func (na *NetAddr) Dial(ctx context.Context) (net.Conn, error) {
d := net.Dialer{Timeout: na.DialerConfig.Timeout}
return d.DialContext(ctx, na.Transport, na.Endpoint)

tt := string(na.TransportType)
if na.Transport != "" {
tt = na.Transport
}
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved

return d.DialContext(ctx, tt, na.Endpoint)
}

// Listen equivalent with net.ListenConfig's Listen for this address.
func (na *NetAddr) Listen(ctx context.Context) (net.Listener, error) {
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
lc := net.ListenConfig{}
return lc.Listen(ctx, na.Transport, na.Endpoint)

tt := string(na.TransportType)
if na.Transport != "" {
tt = na.Transport
}

Check warning on line 103 in config/confignet/confignet.go

View check run for this annotation

Codecov / codecov/patch

config/confignet/confignet.go#L102-L103

Added lines #L102 - L103 were not covered by tests

return lc.Listen(ctx, tt, na.Endpoint)
}

// TCPAddr represents a TCP endpoint address.
type TCPAddr struct {
// Endpoint configures the address for this network connection.
// The address has the form "host:port". The host must be a literal IP address, or a host name that can be
// resolved to IP addresses. The port must be a literal port number or a service name.
// The address has the form "host:port". The host must be a literal TransportTypeIP address, or a host name that can be
// resolved to TransportTypeIP addresses. The port must be a literal port number or a service name.
// If the host is a literal IPv6 address it must be enclosed in square brackets, as in "[2001:db8::1]:80" or
// "[fe80::1%zone]:80". The zone specifies the scope of the literal IPv6 address as defined in RFC 4007.
Endpoint string `mapstructure:"endpoint"`
Expand All @@ -61,11 +121,11 @@
// Dial equivalent with net.Dialer's DialContext for this address.
func (na *TCPAddr) Dial(ctx context.Context) (net.Conn, error) {
d := net.Dialer{Timeout: na.DialerConfig.Timeout}
return d.DialContext(ctx, "tcp", na.Endpoint)
return d.DialContext(ctx, string(TransportTypeTCP), na.Endpoint)
}

// Listen equivalent with net.ListenConfig's Listen for this address.
func (na *TCPAddr) Listen(ctx context.Context) (net.Listener, error) {
lc := net.ListenConfig{}
return lc.Listen(ctx, "tcp", na.Endpoint)
return lc.Listen(ctx, string(TransportTypeTCP), na.Endpoint)
}
8 changes: 4 additions & 4 deletions config/confignet/confignet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

func TestNetAddrTimeout(t *testing.T) {
nac := &NetAddr{
Endpoint: "localhost:0",
Transport: "tcp",
Endpoint: "localhost:0",
TransportType: "tcp",
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved
DialerConfig: DialerConfig{
Timeout: -1 * time.Second,
},
Expand Down Expand Up @@ -50,8 +50,8 @@ func TestTCPAddrTimeout(t *testing.T) {

func TestNetAddr(t *testing.T) {
nas := &NetAddr{
Endpoint: "localhost:0",
Transport: "tcp",
Endpoint: "localhost:0",
TransportType: "tcp",
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved
}
ln, err := nas.Listen(context.Background())
assert.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions receiver/otlpreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func TestUnmarshalConfig(t *testing.T) {
Protocols: Protocols{
GRPC: &configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:4317",
Transport: "tcp",
Endpoint: "0.0.0.0:4317",
TransportType: confignet.TransportTypeTCP,
},
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
Expand Down Expand Up @@ -149,8 +149,8 @@ func TestUnmarshalConfigUnix(t *testing.T) {
Protocols: Protocols{
GRPC: &configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "/tmp/grpc_otlp.sock",
Transport: "unix",
Endpoint: "/tmp/grpc_otlp.sock",
TransportType: confignet.TransportTypeUnix,
},
ReadBufferSize: 512 * 1024,
},
Expand Down
4 changes: 2 additions & 2 deletions receiver/otlpreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func createDefaultConfig() component.Config {
Protocols: Protocols{
GRPC: &configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: localhostgate.EndpointForPort(grpcPort),
Transport: "tcp",
Endpoint: localhostgate.EndpointForPort(grpcPort),
TransportType: confignet.TransportTypeTCP,
},
// We almost write 0 bytes, so no need to tune WriteBufferSize.
ReadBufferSize: 512 * 1024,
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/testdata/uds.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The following entry demonstrates how to specify a Unix Domain Socket for the server.
protocols:
grpc:
transport: unix
transport_type: unix
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
endpoint: /tmp/grpc_otlp.sock
http:
# transport: unix
Expand Down
Loading