Skip to content

Commit

Permalink
internal/components: move default address
Browse files Browse the repository at this point in the history
Signed-off-by: Benedikt Bongartz <[email protected]>
  • Loading branch information
frzifus committed Oct 7, 2024
1 parent 63f5d1c commit 7ffe1c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
17 changes: 10 additions & 7 deletions internal/components/multi_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type MultiPortOption func(parser *MultiPortReceiver)

// MultiPortReceiver is a special parser for components with endpoints for each protocol.
type MultiPortReceiver struct {
name string
name string
defaultRecAddr string

addrMappings map[string]string
portMappings map[string]*corev1.ServicePort
Expand Down Expand Up @@ -85,7 +86,7 @@ func (m *MultiPortReceiver) GetDefaultConfig(logger logr.Logger, config interfac
if ec != nil {
port = ec.GetPortNumOrDefault(logger, port)
}
var addr string
addr := m.defaultRecAddr
if defaultAddr, ok := m.addrMappings[protocol]; ok {
addr = defaultAddr
}
Expand Down Expand Up @@ -118,11 +119,11 @@ func (m *MultiPortReceiver) GetRBACRules(logr.Logger, interface{}) ([]rbacv1.Pol
type MultiPortBuilder[ComponentConfigType any] []Builder[ComponentConfigType]

func NewMultiPortReceiverBuilder(name string) MultiPortBuilder[*MultiProtocolEndpointConfig] {
return append(MultiPortBuilder[*MultiProtocolEndpointConfig]{}, NewBuilder[*MultiProtocolEndpointConfig]().WithName(name))
return append(MultiPortBuilder[*MultiProtocolEndpointConfig]{}, NewBuilder[*MultiProtocolEndpointConfig]().WithName(name).WithDefaultRecAddress("0.0.0.0"))
}

func NewProtocolBuilder(name string, port int32) Builder[*MultiProtocolEndpointConfig] {
return NewBuilder[*MultiProtocolEndpointConfig]().WithName(name).WithPort(port)
return NewBuilder[*MultiProtocolEndpointConfig]().WithName(name).WithPort(port).WithDefaultRecAddress("0.0.0.0")
}

func (mp MultiPortBuilder[ComponentConfigType]) AddPortMapping(builder Builder[ComponentConfigType]) MultiPortBuilder[ComponentConfigType] {
Expand All @@ -134,10 +135,12 @@ func (mp MultiPortBuilder[ComponentConfigType]) Build() (*MultiPortReceiver, err
return nil, fmt.Errorf("must provide at least one port mapping")
}

mb := mp[0].MustBuild()
multiReceiver := &MultiPortReceiver{
name: mp[0].MustBuild().name,
addrMappings: map[string]string{},
portMappings: map[string]*corev1.ServicePort{},
name: mb.name,
defaultRecAddr: mb.settings.defaultRecAddr,
addrMappings: map[string]string{},
portMappings: map[string]*corev1.ServicePort{},
}
for _, bu := range mp[1:] {
built, err := bu.Build()
Expand Down
24 changes: 0 additions & 24 deletions internal/components/receivers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,112 +52,88 @@ var (
components.NewMultiPortReceiverBuilder("otlp").
AddPortMapping(components.NewProtocolBuilder("grpc", 4317).
WithAppProtocol(&components.GrpcProtocol).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(4317)).
AddPortMapping(components.NewProtocolBuilder("http", 4318).
WithAppProtocol(&components.HttpProtocol).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(4318)).
MustBuild(),
components.NewMultiPortReceiverBuilder("skywalking").
AddPortMapping(components.NewProtocolBuilder(components.GrpcProtocol, 11800).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(11800).
WithAppProtocol(&components.GrpcProtocol)).
AddPortMapping(components.NewProtocolBuilder(components.HttpProtocol, 12800).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(12800).
WithAppProtocol(&components.HttpProtocol)).
MustBuild(),
components.NewMultiPortReceiverBuilder("jaeger").
AddPortMapping(components.NewProtocolBuilder(components.GrpcProtocol, 14250).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(14250).
WithProtocol(corev1.ProtocolTCP).
WithAppProtocol(&components.GrpcProtocol)).
AddPortMapping(components.NewProtocolBuilder("thrift_http", 14268).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(14268).
WithProtocol(corev1.ProtocolTCP).
WithAppProtocol(&components.HttpProtocol)).
AddPortMapping(components.NewProtocolBuilder("thrift_compact", 6831).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(6831).
WithProtocol(corev1.ProtocolUDP)).
AddPortMapping(components.NewProtocolBuilder("thrift_binary", 6832).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(6832).
WithProtocol(corev1.ProtocolUDP)).
MustBuild(),
components.NewMultiPortReceiverBuilder("loki").
AddPortMapping(components.NewProtocolBuilder(components.GrpcProtocol, 9095).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(9095).
WithAppProtocol(&components.GrpcProtocol)).
AddPortMapping(components.NewProtocolBuilder(components.HttpProtocol, 3100).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(3100).
WithAppProtocol(&components.HttpProtocol)).
MustBuild(),
components.NewSinglePortParserBuilder("awsxray", 2000).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(2000).
WithProtocol(corev1.ProtocolUDP).
MustBuild(),
components.NewSinglePortParserBuilder("carbon", 2003).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(2003).
MustBuild(),
components.NewSinglePortParserBuilder("collectd", 8081).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(8081).
MustBuild(),
components.NewSinglePortParserBuilder("fluentforward", 8006).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(8006).
MustBuild(),
components.NewSinglePortParserBuilder("influxdb", 8086).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(8086).
MustBuild(),
components.NewSinglePortParserBuilder("opencensus", 55678).
WithAppProtocol(nil).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(55678).
MustBuild(),
components.NewSinglePortParserBuilder("sapm", 7276).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(7276).
MustBuild(),
components.NewSinglePortParserBuilder("signalfx", 9943).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(9943).
MustBuild(),
components.NewSinglePortParserBuilder("splunk_hec", 8088).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(8088).
MustBuild(),
components.NewSinglePortParserBuilder("statsd", 8125).
WithDefaultRecAddress("0.0.0.0").
WithProtocol(corev1.ProtocolUDP).
WithTargetPort(8125).
MustBuild(),
components.NewSinglePortParserBuilder("tcplog", components.UnsetPort).
WithDefaultRecAddress("0.0.0.0").
WithProtocol(corev1.ProtocolTCP).
MustBuild(),
components.NewSinglePortParserBuilder("udplog", components.UnsetPort).
WithDefaultRecAddress("0.0.0.0").
WithProtocol(corev1.ProtocolUDP).
MustBuild(),
components.NewSinglePortParserBuilder("wavefront", 2003).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(2003).
MustBuild(),
components.NewSinglePortParserBuilder("zipkin", 9411).
WithAppProtocol(&components.HttpProtocol).
WithProtocol(corev1.ProtocolTCP).
WithDefaultRecAddress("0.0.0.0").
WithTargetPort(3100).
MustBuild(),
NewScraperParser("prometheus"),
Expand Down
4 changes: 2 additions & 2 deletions internal/components/single_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func internalParseSingleEndpoint(logger logr.Logger, name string, failSilently b
}

func NewSinglePortParserBuilder(name string, port int32) Builder[*SingleEndpointConfig] {
return NewBuilder[*SingleEndpointConfig]().WithPort(port).WithName(name).WithPortParser(ParseSingleEndpoint).WithDefaultsApplier(AddressDefaulter)
return NewBuilder[*SingleEndpointConfig]().WithPort(port).WithName(name).WithPortParser(ParseSingleEndpoint).WithDefaultsApplier(AddressDefaulter).WithDefaultRecAddress("0.0.0.0")
}

func NewSilentSinglePortParserBuilder(name string, port int32) Builder[*SingleEndpointConfig] {
return NewBuilder[*SingleEndpointConfig]().WithPort(port).WithName(name).WithPortParser(ParseSingleEndpointSilent).WithDefaultsApplier(AddressDefaulter)
return NewBuilder[*SingleEndpointConfig]().WithPort(port).WithName(name).WithPortParser(ParseSingleEndpointSilent).WithDefaultsApplier(AddressDefaulter).WithDefaultRecAddress("0.0.0.0")
}

func AddressDefaulter(logger logr.Logger, defaultRecAddr string, port int32, config *SingleEndpointConfig) (map[string]interface{}, error) {
Expand Down

0 comments on commit 7ffe1c2

Please sign in to comment.