From 20a320c48983a14b57fa058db0ff9c8d0de01559 Mon Sep 17 00:00:00 2001 From: "Ben B." Date: Mon, 7 Oct 2024 23:08:35 +0200 Subject: [PATCH] set default address for all parsed receivers (#3333) --- .chloggen/add_all_receiver_defaults.yaml | 16 ++++++++++++++++ internal/components/multi_endpoint.go | 17 ++++++++++------- internal/components/receivers/helpers.go | 2 -- internal/components/single_endpoint.go | 4 ++-- tests/e2e/smoke-targetallocator/00-assert.yaml | 4 ++-- tests/e2e/statefulset-features/00-assert.yaml | 2 +- tests/e2e/statefulset-features/01-assert.yaml | 2 +- 7 files changed, 32 insertions(+), 15 deletions(-) create mode 100755 .chloggen/add_all_receiver_defaults.yaml diff --git a/.chloggen/add_all_receiver_defaults.yaml b/.chloggen/add_all_receiver_defaults.yaml new file mode 100755 index 0000000000..4784ede779 --- /dev/null +++ b/.chloggen/add_all_receiver_defaults.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: collector + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: set default address for all parsed receivers + +# One or more tracking issues related to the change +issues: [3126] + +# (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: diff --git a/internal/components/multi_endpoint.go b/internal/components/multi_endpoint.go index 30162eeaee..39449cda2b 100644 --- a/internal/components/multi_endpoint.go +++ b/internal/components/multi_endpoint.go @@ -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 @@ -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 } @@ -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] { @@ -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() diff --git a/internal/components/receivers/helpers.go b/internal/components/receivers/helpers.go index 8823101cae..89a3cb6fe7 100644 --- a/internal/components/receivers/helpers.go +++ b/internal/components/receivers/helpers.go @@ -52,11 +52,9 @@ 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"). diff --git a/internal/components/single_endpoint.go b/internal/components/single_endpoint.go index 51a6124b61..849aebfdb4 100644 --- a/internal/components/single_endpoint.go +++ b/internal/components/single_endpoint.go @@ -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) { diff --git a/tests/e2e/smoke-targetallocator/00-assert.yaml b/tests/e2e/smoke-targetallocator/00-assert.yaml index 8b1e1a5645..aa86ab8094 100644 --- a/tests/e2e/smoke-targetallocator/00-assert.yaml +++ b/tests/e2e/smoke-targetallocator/00-assert.yaml @@ -29,7 +29,7 @@ data: jaeger: protocols: grpc: - endpoint: :14250 + endpoint: 0.0.0.0:14250 prometheus: config: global: @@ -52,4 +52,4 @@ data: - jaeger kind: ConfigMap metadata: - name: stateful-collector-a65c7bf4 + name: stateful-collector-57180221 diff --git a/tests/e2e/statefulset-features/00-assert.yaml b/tests/e2e/statefulset-features/00-assert.yaml index 3d6d879895..2929ec1138 100644 --- a/tests/e2e/statefulset-features/00-assert.yaml +++ b/tests/e2e/statefulset-features/00-assert.yaml @@ -21,7 +21,7 @@ spec: items: - key: collector.yaml path: collector.yaml - name: stateful-collector-1e082e0e + name: stateful-collector-4b08af22 name: otc-internal - emptyDir: {} name: testvolume diff --git a/tests/e2e/statefulset-features/01-assert.yaml b/tests/e2e/statefulset-features/01-assert.yaml index 72d1eb3013..a2ddf2ea5b 100644 --- a/tests/e2e/statefulset-features/01-assert.yaml +++ b/tests/e2e/statefulset-features/01-assert.yaml @@ -21,7 +21,7 @@ spec: items: - key: collector.yaml path: collector.yaml - name: stateful-collector-1e082e0e + name: stateful-collector-4b08af22 name: otc-internal - emptyDir: {} name: testvolume