Skip to content

Commit 7ec38e5

Browse files
authored
Fanout consumer does not need to mutate in some cases (#9062)
Follow up to #9053. @dmitryax pointed out [here](#9053 (comment)) that the fanout consumer will pass original data to a non-mutating consumer if any is available. This PR incorporates that point and updates test expectations accordingly.
1 parent 9b6a18b commit 7ec38e5

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

internal/fanoutconsumer/logs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ type logsConsumer struct {
4444
}
4545

4646
func (lsc *logsConsumer) Capabilities() consumer.Capabilities {
47-
return consumer.Capabilities{MutatesData: len(lsc.mutable) > 0}
47+
// If all consumers are mutating, then the original data will be passed to one of them.
48+
return consumer.Capabilities{MutatesData: len(lsc.mutable) > 0 && len(lsc.readonly) == 0}
4849
}
4950

5051
// ConsumeLogs exports the plog.Logs to all consumers wrapped by the current one.

internal/fanoutconsumer/logs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func TestLogsMultiplexingMixLastMutating(t *testing.T) {
148148
p3 := &mutatingLogsSink{LogsSink: new(consumertest.LogsSink)}
149149

150150
lfc := NewLogs([]consumer.Logs{p1, p2, p3})
151-
assert.True(t, lfc.Capabilities().MutatesData)
151+
assert.False(t, lfc.Capabilities().MutatesData)
152152
ld := testdata.GenerateLogs(1)
153153

154154
for i := 0; i < 2; i++ {
@@ -186,7 +186,7 @@ func TestLogsMultiplexingMixLastNonMutating(t *testing.T) {
186186
p3 := new(consumertest.LogsSink)
187187

188188
lfc := NewLogs([]consumer.Logs{p1, p2, p3})
189-
assert.True(t, lfc.Capabilities().MutatesData)
189+
assert.False(t, lfc.Capabilities().MutatesData)
190190
ld := testdata.GenerateLogs(1)
191191

192192
for i := 0; i < 2; i++ {

internal/fanoutconsumer/metrics.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ type metricsConsumer struct {
4242
}
4343

4444
func (msc *metricsConsumer) Capabilities() consumer.Capabilities {
45-
return consumer.Capabilities{MutatesData: len(msc.mutable) > 0}
45+
// If all consumers are mutating, then the original data will be passed to one of them.
46+
return consumer.Capabilities{MutatesData: len(msc.mutable) > 0 && len(msc.readonly) == 0}
4647
}
4748

4849
// ConsumeMetrics exports the pmetric.Metrics to all consumers wrapped by the current one.

internal/fanoutconsumer/metrics_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func TestMetricsMultiplexingMixLastMutating(t *testing.T) {
148148
p3 := &mutatingMetricsSink{MetricsSink: new(consumertest.MetricsSink)}
149149

150150
mfc := NewMetrics([]consumer.Metrics{p1, p2, p3})
151-
assert.True(t, mfc.Capabilities().MutatesData)
151+
assert.False(t, mfc.Capabilities().MutatesData)
152152
md := testdata.GenerateMetrics(1)
153153

154154
for i := 0; i < 2; i++ {
@@ -186,7 +186,7 @@ func TestMetricsMultiplexingMixLastNonMutating(t *testing.T) {
186186
p3 := new(consumertest.MetricsSink)
187187

188188
mfc := NewMetrics([]consumer.Metrics{p1, p2, p3})
189-
assert.True(t, mfc.Capabilities().MutatesData)
189+
assert.False(t, mfc.Capabilities().MutatesData)
190190
md := testdata.GenerateMetrics(1)
191191

192192
for i := 0; i < 2; i++ {

internal/fanoutconsumer/traces.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ type tracesConsumer struct {
4242
}
4343

4444
func (tsc *tracesConsumer) Capabilities() consumer.Capabilities {
45-
return consumer.Capabilities{MutatesData: len(tsc.mutable) > 0}
45+
// If all consumers are mutating, then the original data will be passed to one of them.
46+
return consumer.Capabilities{MutatesData: len(tsc.mutable) > 0 && len(tsc.readonly) == 0}
4647
}
4748

4849
// ConsumeTraces exports the ptrace.Traces to all consumers wrapped by the current one.

internal/fanoutconsumer/traces_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestTracesMultiplexingMixLastMutating(t *testing.T) {
149149
p3 := &mutatingTracesSink{TracesSink: new(consumertest.TracesSink)}
150150

151151
tfc := NewTraces([]consumer.Traces{p1, p2, p3})
152-
assert.True(t, tfc.Capabilities().MutatesData)
152+
assert.False(t, tfc.Capabilities().MutatesData)
153153
td := testdata.GenerateTraces(1)
154154

155155
for i := 0; i < 2; i++ {
@@ -187,7 +187,7 @@ func TestTracesMultiplexingMixLastNonMutating(t *testing.T) {
187187
p3 := new(consumertest.TracesSink)
188188

189189
tfc := NewTraces([]consumer.Traces{p1, p2, p3})
190-
assert.True(t, tfc.Capabilities().MutatesData)
190+
assert.False(t, tfc.Capabilities().MutatesData)
191191
td := testdata.GenerateTraces(1)
192192

193193
for i := 0; i < 2; i++ {

service/internal/graph/graph_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,17 +573,17 @@ func TestConnectorPipelinesGraph(t *testing.T) {
573573
pipelineConfigs: pipelines.Config{
574574
component.NewIDWithName("traces", "in"): {
575575
Receivers: []component.ID{component.NewID("examplereceiver")},
576-
Processors: []component.ID{component.NewID("exampleprocessor")},
576+
Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")},
577577
Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")},
578578
},
579579
component.NewIDWithName("metrics", "in"): {
580580
Receivers: []component.ID{component.NewID("examplereceiver")},
581-
Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector
581+
Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")},
582582
Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")},
583583
},
584584
component.NewIDWithName("logs", "in"): {
585585
Receivers: []component.ID{component.NewID("examplereceiver")},
586-
Processors: []component.ID{component.NewID("exampleprocessor")},
586+
Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")},
587587
Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")},
588588
},
589589
component.NewIDWithName("traces", "out"): {
@@ -593,12 +593,12 @@ func TestConnectorPipelinesGraph(t *testing.T) {
593593
},
594594
component.NewIDWithName("metrics", "out"): {
595595
Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")},
596-
Processors: []component.ID{component.NewID("exampleprocessor")},
596+
Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector
597597
Exporters: []component.ID{component.NewID("exampleexporter")},
598598
},
599599
component.NewIDWithName("logs", "out"): {
600600
Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")},
601-
Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")},
601+
Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector
602602
Exporters: []component.ID{component.NewID("exampleexporter")},
603603
},
604604
},

0 commit comments

Comments
 (0)