Skip to content
Open
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
17 changes: 17 additions & 0 deletions .chloggen/expose_grpc_otelarrow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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: "Expose the default gRPC receiver port (4317) for otelarrow and automatically apply grpc protocol defaults when protocols are omitted or otelarrow is enabled."


# One or more tracking issues related to the change
issues: [4713]

# (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:
62 changes: 62 additions & 0 deletions apis/v1beta1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,71 @@ func (c *Config) GetAllRbacRules(logger logr.Logger) ([]rbacv1.PolicyRule, error
// ApplyDefaults applies default configuration values to the collector config.
// Optional DefaultsOption arguments can be provided to customize behavior.
func (c *Config) ApplyDefaults(logger logr.Logger, opts ...components.DefaultOption) ([]EventInfo, error) {
c.ensureOtelarrowGrpcDefaults(opts...)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please follow the patterns we use for other exporters, there should be no reason to override here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return c.applyDefaultForComponentKinds(logger, opts, KindReceiver, KindExporter, KindExtension)
}

func (c *Config) ensureOtelarrowGrpcDefaults(opts ...components.DefaultOption) {
if c == nil {
return
}

defaultCfg := &components.DefaultConfig{}
for _, opt := range opts {
if opt != nil {
opt(defaultCfg)
}
}

enabledReceivers := c.GetEnabledComponents()[KindReceiver]
if len(enabledReceivers) == 0 {
return
}

if c.Receivers.Object == nil {
c.Receivers.Object = map[string]any{}
}

for receiverName := range enabledReceivers {
if components.ComponentType(receiverName) != "otelarrow" {
continue
}

receiverCfg, ok := c.Receivers.Object[receiverName]
if !ok || receiverCfg == nil {
c.Receivers.Object[receiverName] = map[string]any{
"protocols": map[string]any{
components.GrpcProtocol: map[string]any{},
},
}
continue
}

receiverCfgMap, ok := receiverCfg.(map[string]any)
if !ok {
continue
}

protocolsValue, ok := receiverCfgMap["protocols"]
if !ok || protocolsValue == nil {
receiverCfgMap["protocols"] = map[string]any{
components.GrpcProtocol: map[string]any{},
}
c.Receivers.Object[receiverName] = receiverCfgMap
continue
}

protocols, ok := protocolsValue.(map[string]any)
if !ok || len(protocols) != 0 {
continue
}

protocols[components.GrpcProtocol] = map[string]any{}
receiverCfgMap["protocols"] = protocols
c.Receivers.Object[receiverName] = receiverCfgMap
}
}

// GetLivenessProbe gets the first enabled liveness probe. There should only ever be one extension enabled
// that provides the hinting for the liveness probe.
func (c *Config) GetLivenessProbe(logger logr.Logger) (*corev1.Probe, error) {
Expand Down
40 changes: 36 additions & 4 deletions apis/v1beta1/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,11 @@ func TestConfig_getEnvironmentVariablesForComponentKinds(t *testing.T) {

func TestConfig_GetReceiverPorts(t *testing.T) {
tests := []struct {
name string
file string
want []v1.ServicePort
wantErr bool
name string
file string
want []v1.ServicePort
wantErr bool
applyDefaults bool
}{
{
name: "k8sevents",
Expand Down Expand Up @@ -788,6 +789,33 @@ func TestConfig_GetReceiverPorts(t *testing.T) {
},
},
},
{
name: "otelarrow",
file: "testdata/otelcol-otelarrow.yaml",
want: []v1.ServicePort{
{
Name: "otelarrow-grpc",
Protocol: "",
AppProtocol: ptr.To("grpc"),
Port: 4317,
TargetPort: intstr.FromInt32(4317),
},
},
},
{
name: "otelarrow missing protocols",
file: "testdata/otelcol-otelarrow-no-protocols.yaml",
applyDefaults: true,
want: []v1.ServicePort{
{
Name: "otelarrow-grpc",
Protocol: "",
AppProtocol: ptr.To("grpc"),
Port: 4317,
TargetPort: intstr.FromInt32(4317),
},
},
},
{
name: "filelog",
file: "testdata/otelcol-filelog.yaml",
Expand All @@ -807,6 +835,10 @@ func TestConfig_GetReceiverPorts(t *testing.T) {
c := &Config{}
err = go_yaml.Unmarshal(collectorYaml, c)
require.NoError(t, err)
if tt.applyDefaults {
_, err = c.ApplyDefaults(logr.Discard())
require.NoError(t, err)
}
ports, err := c.GetReceiverPorts(logr.Discard())
if tt.wantErr {
require.Error(t, err)
Expand Down
11 changes: 11 additions & 0 deletions apis/v1beta1/testdata/otelcol-otelarrow-no-protocols.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
receivers:
otelarrow: {}

exporters:
debug:

service:
pipelines:
traces:
receivers: [otelarrow]
exporters: [debug]
13 changes: 13 additions & 0 deletions apis/v1beta1/testdata/otelcol-otelarrow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
receivers:
otelarrow:
protocols:
grpc:

exporters:
debug:

service:
pipelines:
traces:
receivers: [otelarrow]
exporters: [debug]
5 changes: 5 additions & 0 deletions internal/components/receivers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func ReceiverFor(name string) components.Parser {
}

var componentParsers = []components.Parser{
components.NewMultiPortReceiverBuilder("otelarrow").
AddPortMapping(components.NewProtocolBuilder("grpc", 4317).
WithAppProtocol(&components.GrpcProtocol).
WithTargetPort(4317)).
MustBuild(),
components.NewMultiPortReceiverBuilder("otlp").
AddPortMapping(components.NewProtocolBuilder("grpc", 4317).
WithAppProtocol(&components.GrpcProtocol).
Expand Down
Loading