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

set default address for all parsed receivers #3333

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions .chloggen/add_all_receiver_defaults.yaml
Original file line number Diff line number Diff line change
@@ -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:
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"))
frzifus marked this conversation as resolved.
Show resolved Hide resolved
}

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
2 changes: 0 additions & 2 deletions internal/components/receivers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
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] {
frzifus marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 2 additions & 2 deletions tests/e2e/smoke-targetallocator/00-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data:
jaeger:
protocols:
grpc:
endpoint: :14250
endpoint: 0.0.0.0:14250
prometheus:
config:
global:
Expand All @@ -52,4 +52,4 @@ data:
- jaeger
kind: ConfigMap
metadata:
name: stateful-collector-a65c7bf4
name: stateful-collector-57180221
2 changes: 1 addition & 1 deletion tests/e2e/statefulset-features/00-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/statefulset-features/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading