Skip to content

Commit a353088

Browse files
committed
internal/components: move default address
Signed-off-by: Benedikt Bongartz <[email protected]>
1 parent 63f5d1c commit a353088

File tree

3 files changed

+15
-32
lines changed

3 files changed

+15
-32
lines changed

internal/components/multi_endpoint.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ type MultiPortOption func(parser *MultiPortReceiver)
3838

3939
// MultiPortReceiver is a special parser for components with endpoints for each protocol.
4040
type MultiPortReceiver struct {
41-
name string
41+
name string
42+
defaultRecAddr string
4243

4344
addrMappings map[string]string
4445
portMappings map[string]*corev1.ServicePort
@@ -85,7 +86,7 @@ func (m *MultiPortReceiver) GetDefaultConfig(logger logr.Logger, config interfac
8586
if ec != nil {
8687
port = ec.GetPortNumOrDefault(logger, port)
8788
}
88-
var addr string
89+
addr := m.defaultRecAddr
8990
if defaultAddr, ok := m.addrMappings[protocol]; ok {
9091
addr = defaultAddr
9192
}
@@ -118,7 +119,7 @@ func (m *MultiPortReceiver) GetRBACRules(logr.Logger, interface{}) ([]rbacv1.Pol
118119
type MultiPortBuilder[ComponentConfigType any] []Builder[ComponentConfigType]
119120

120121
func NewMultiPortReceiverBuilder(name string) MultiPortBuilder[*MultiProtocolEndpointConfig] {
121-
return append(MultiPortBuilder[*MultiProtocolEndpointConfig]{}, NewBuilder[*MultiProtocolEndpointConfig]().WithName(name))
122+
return append(MultiPortBuilder[*MultiProtocolEndpointConfig]{}, NewBuilder[*MultiProtocolEndpointConfig]().WithName(name).WithDefaultRecAddress("0.0.0.0"))
122123
}
123124

124125
func NewProtocolBuilder(name string, port int32) Builder[*MultiProtocolEndpointConfig] {
@@ -134,10 +135,16 @@ func (mp MultiPortBuilder[ComponentConfigType]) Build() (*MultiPortReceiver, err
134135
return nil, fmt.Errorf("must provide at least one port mapping")
135136
}
136137

138+
defaultRecAddr := ""
139+
if mp[0].MustBuild().settings != nil {
140+
defaultRecAddr = mp[0].MustBuild().settings.defaultRecAddr
141+
}
142+
137143
multiReceiver := &MultiPortReceiver{
138-
name: mp[0].MustBuild().name,
139-
addrMappings: map[string]string{},
140-
portMappings: map[string]*corev1.ServicePort{},
144+
name: mp[0].MustBuild().name,
145+
defaultRecAddr: defaultRecAddr,
146+
addrMappings: map[string]string{},
147+
portMappings: map[string]*corev1.ServicePort{},
141148
}
142149
for _, bu := range mp[1:] {
143150
built, err := bu.Build()

internal/components/receivers/helpers.go

-24
Original file line numberDiff line numberDiff line change
@@ -52,112 +52,88 @@ var (
5252
components.NewMultiPortReceiverBuilder("otlp").
5353
AddPortMapping(components.NewProtocolBuilder("grpc", 4317).
5454
WithAppProtocol(&components.GrpcProtocol).
55-
WithDefaultRecAddress("0.0.0.0").
5655
WithTargetPort(4317)).
5756
AddPortMapping(components.NewProtocolBuilder("http", 4318).
5857
WithAppProtocol(&components.HttpProtocol).
59-
WithDefaultRecAddress("0.0.0.0").
6058
WithTargetPort(4318)).
6159
MustBuild(),
6260
components.NewMultiPortReceiverBuilder("skywalking").
6361
AddPortMapping(components.NewProtocolBuilder(components.GrpcProtocol, 11800).
64-
WithDefaultRecAddress("0.0.0.0").
6562
WithTargetPort(11800).
6663
WithAppProtocol(&components.GrpcProtocol)).
6764
AddPortMapping(components.NewProtocolBuilder(components.HttpProtocol, 12800).
68-
WithDefaultRecAddress("0.0.0.0").
6965
WithTargetPort(12800).
7066
WithAppProtocol(&components.HttpProtocol)).
7167
MustBuild(),
7268
components.NewMultiPortReceiverBuilder("jaeger").
7369
AddPortMapping(components.NewProtocolBuilder(components.GrpcProtocol, 14250).
74-
WithDefaultRecAddress("0.0.0.0").
7570
WithTargetPort(14250).
7671
WithProtocol(corev1.ProtocolTCP).
7772
WithAppProtocol(&components.GrpcProtocol)).
7873
AddPortMapping(components.NewProtocolBuilder("thrift_http", 14268).
79-
WithDefaultRecAddress("0.0.0.0").
8074
WithTargetPort(14268).
8175
WithProtocol(corev1.ProtocolTCP).
8276
WithAppProtocol(&components.HttpProtocol)).
8377
AddPortMapping(components.NewProtocolBuilder("thrift_compact", 6831).
84-
WithDefaultRecAddress("0.0.0.0").
8578
WithTargetPort(6831).
8679
WithProtocol(corev1.ProtocolUDP)).
8780
AddPortMapping(components.NewProtocolBuilder("thrift_binary", 6832).
88-
WithDefaultRecAddress("0.0.0.0").
8981
WithTargetPort(6832).
9082
WithProtocol(corev1.ProtocolUDP)).
9183
MustBuild(),
9284
components.NewMultiPortReceiverBuilder("loki").
9385
AddPortMapping(components.NewProtocolBuilder(components.GrpcProtocol, 9095).
94-
WithDefaultRecAddress("0.0.0.0").
9586
WithTargetPort(9095).
9687
WithAppProtocol(&components.GrpcProtocol)).
9788
AddPortMapping(components.NewProtocolBuilder(components.HttpProtocol, 3100).
98-
WithDefaultRecAddress("0.0.0.0").
9989
WithTargetPort(3100).
10090
WithAppProtocol(&components.HttpProtocol)).
10191
MustBuild(),
10292
components.NewSinglePortParserBuilder("awsxray", 2000).
103-
WithDefaultRecAddress("0.0.0.0").
10493
WithTargetPort(2000).
10594
WithProtocol(corev1.ProtocolUDP).
10695
MustBuild(),
10796
components.NewSinglePortParserBuilder("carbon", 2003).
108-
WithDefaultRecAddress("0.0.0.0").
10997
WithTargetPort(2003).
11098
MustBuild(),
11199
components.NewSinglePortParserBuilder("collectd", 8081).
112-
WithDefaultRecAddress("0.0.0.0").
113100
WithTargetPort(8081).
114101
MustBuild(),
115102
components.NewSinglePortParserBuilder("fluentforward", 8006).
116-
WithDefaultRecAddress("0.0.0.0").
117103
WithTargetPort(8006).
118104
MustBuild(),
119105
components.NewSinglePortParserBuilder("influxdb", 8086).
120-
WithDefaultRecAddress("0.0.0.0").
121106
WithTargetPort(8086).
122107
MustBuild(),
123108
components.NewSinglePortParserBuilder("opencensus", 55678).
124109
WithAppProtocol(nil).
125-
WithDefaultRecAddress("0.0.0.0").
126110
WithTargetPort(55678).
127111
MustBuild(),
128112
components.NewSinglePortParserBuilder("sapm", 7276).
129-
WithDefaultRecAddress("0.0.0.0").
130113
WithTargetPort(7276).
131114
MustBuild(),
132115
components.NewSinglePortParserBuilder("signalfx", 9943).
133-
WithDefaultRecAddress("0.0.0.0").
134116
WithTargetPort(9943).
135117
MustBuild(),
136118
components.NewSinglePortParserBuilder("splunk_hec", 8088).
137-
WithDefaultRecAddress("0.0.0.0").
138119
WithTargetPort(8088).
139120
MustBuild(),
140121
components.NewSinglePortParserBuilder("statsd", 8125).
141-
WithDefaultRecAddress("0.0.0.0").
142122
WithProtocol(corev1.ProtocolUDP).
143123
WithTargetPort(8125).
144124
MustBuild(),
145125
components.NewSinglePortParserBuilder("tcplog", components.UnsetPort).
146-
WithDefaultRecAddress("0.0.0.0").
147126
WithProtocol(corev1.ProtocolTCP).
148127
MustBuild(),
149128
components.NewSinglePortParserBuilder("udplog", components.UnsetPort).
150-
WithDefaultRecAddress("0.0.0.0").
151129
WithProtocol(corev1.ProtocolUDP).
152130
MustBuild(),
153131
components.NewSinglePortParserBuilder("wavefront", 2003).
154-
WithDefaultRecAddress("0.0.0.0").
155132
WithTargetPort(2003).
156133
MustBuild(),
157134
components.NewSinglePortParserBuilder("zipkin", 9411).
158135
WithAppProtocol(&components.HttpProtocol).
159136
WithProtocol(corev1.ProtocolTCP).
160-
WithDefaultRecAddress("0.0.0.0").
161137
WithTargetPort(3100).
162138
MustBuild(),
163139
NewScraperParser("prometheus"),

internal/components/single_endpoint.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ func internalParseSingleEndpoint(logger logr.Logger, name string, failSilently b
8484
}
8585

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

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

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

0 commit comments

Comments
 (0)