Skip to content

Commit 8af6b02

Browse files
committed
[exporterhelper] Fix exporter.PersistRequestContext feature gate
It was ignored before because the PersistRequestContextOnRead and PersistRequestContextOnWrite variables were initialized before the feature gate was set from the command line arguments.
1 parent 120736c commit 8af6b02

File tree

10 files changed

+55
-31
lines changed

10 files changed

+55
-31
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: exporterhelper
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix exporter.PersistRequestContext feature gate
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [13342]
14+
15+
# Optional: The change log or logs in which this entry should be included.
16+
# e.g. '[user]' or '[user, api]'
17+
# Include 'user' if the change is relevant to end users.
18+
# Include 'api' if there is a change to a library API.
19+
# Default: '[user]'
20+
change_logs: [user]

exporter/exporterhelper/internal/queue/fg.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ var PersistRequestContextFeatureGate = featuregate.GlobalRegistry().MustRegister
1313
featuregate.WithRegisterDescription("controls whether context should be stored alongside requests in the persistent queue"),
1414
)
1515

16-
// assign the feature gate to separate variables to make it possible to override the behavior in tests
16+
// assign the feature gate to separate functions to make it possible to override the behavior in tests
1717
// on write and read paths separately.
1818
var (
19-
PersistRequestContextOnRead = PersistRequestContextFeatureGate.IsEnabled()
20-
PersistRequestContextOnWrite = PersistRequestContextFeatureGate.IsEnabled()
19+
PersistRequestContextOnRead = PersistRequestContextFeatureGate.IsEnabled
20+
PersistRequestContextOnWrite = PersistRequestContextFeatureGate.IsEnabled
2121
)

exporter/exporterhelper/logs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type logsEncoding struct{}
5959
var _ QueueBatchEncoding[Request] = logsEncoding{}
6060

6161
func (logsEncoding) Unmarshal(bytes []byte) (context.Context, Request, error) {
62-
if queue.PersistRequestContextOnRead {
62+
if queue.PersistRequestContextOnRead() {
6363
ctx, logs, err := pdatareq.UnmarshalLogs(bytes)
6464
if errors.Is(err, pdatareq.ErrInvalidFormat) {
6565
// fall back to unmarshaling without context
@@ -78,7 +78,7 @@ func (logsEncoding) Unmarshal(bytes []byte) (context.Context, Request, error) {
7878

7979
func (logsEncoding) Marshal(ctx context.Context, req Request) ([]byte, error) {
8080
logs := req.(*logsRequest).ld
81-
if queue.PersistRequestContextOnWrite {
81+
if queue.PersistRequestContextOnWrite() {
8282
return pdatareq.MarshalLogs(ctx, logs)
8383
}
8484
return logsMarshaler.MarshalLogs(logs)

exporter/exporterhelper/logs_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ func TestLogsRequest_Default_ExportError(t *testing.T) {
170170
}
171171

172172
func TestLogs_WithPersistentQueue(t *testing.T) {
173-
fgOrigState := queue.PersistRequestContextFeatureGate.IsEnabled()
173+
fgOrigReadState := queue.PersistRequestContextOnRead
174+
fgOrigWriteState := queue.PersistRequestContextOnWrite
174175
qCfg := NewDefaultQueueConfig()
175176
storageID := component.MustNewIDWithName("file_storage", "storage")
176177
qCfg.StorageID = configoptional.Some(storageID)
@@ -212,11 +213,11 @@ func TestLogs_WithPersistentQueue(t *testing.T) {
212213
}
213214
for _, tt := range tests {
214215
t.Run(tt.name, func(t *testing.T) {
215-
queue.PersistRequestContextOnRead = tt.fgEnabledOnRead
216-
queue.PersistRequestContextOnWrite = tt.fgEnabledOnWrite
216+
queue.PersistRequestContextOnRead = func() bool { return tt.fgEnabledOnRead }
217+
queue.PersistRequestContextOnWrite = func() bool { return tt.fgEnabledOnWrite }
217218
t.Cleanup(func() {
218-
queue.PersistRequestContextOnRead = fgOrigState
219-
queue.PersistRequestContextOnWrite = fgOrigState
219+
queue.PersistRequestContextOnRead = fgOrigReadState
220+
queue.PersistRequestContextOnWrite = fgOrigWriteState
220221
})
221222

222223
ls := consumertest.LogsSink{}

exporter/exporterhelper/metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type metricsEncoding struct{}
5959
var _ QueueBatchEncoding[Request] = metricsEncoding{}
6060

6161
func (metricsEncoding) Unmarshal(bytes []byte) (context.Context, Request, error) {
62-
if queue.PersistRequestContextOnRead {
62+
if queue.PersistRequestContextOnRead() {
6363
ctx, metrics, err := pdatareq.UnmarshalMetrics(bytes)
6464
if errors.Is(err, pdatareq.ErrInvalidFormat) {
6565
// fall back to unmarshaling without context
@@ -77,7 +77,7 @@ func (metricsEncoding) Unmarshal(bytes []byte) (context.Context, Request, error)
7777

7878
func (metricsEncoding) Marshal(ctx context.Context, req Request) ([]byte, error) {
7979
metrics := req.(*metricsRequest).md
80-
if queue.PersistRequestContextOnWrite {
80+
if queue.PersistRequestContextOnWrite() {
8181
return pdatareq.MarshalMetrics(ctx, metrics)
8282
}
8383
return metricsMarshaler.MarshalMetrics(metrics)

exporter/exporterhelper/metrics_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ func TestMetricsRequest_Default_ExportError(t *testing.T) {
170170
}
171171

172172
func TestMetrics_WithPersistentQueue(t *testing.T) {
173-
fgOrigState := queue.PersistRequestContextFeatureGate.IsEnabled()
173+
fgOrigReadState := queue.PersistRequestContextOnRead
174+
fgOrigWriteState := queue.PersistRequestContextOnWrite
174175
qCfg := NewDefaultQueueConfig()
175176
storageID := component.MustNewIDWithName("file_storage", "storage")
176177
qCfg.StorageID = configoptional.Some(storageID)
@@ -212,11 +213,11 @@ func TestMetrics_WithPersistentQueue(t *testing.T) {
212213
}
213214
for _, tt := range tests {
214215
t.Run(tt.name, func(t *testing.T) {
215-
queue.PersistRequestContextOnRead = tt.fgEnabledOnRead
216-
queue.PersistRequestContextOnWrite = tt.fgEnabledOnWrite
216+
queue.PersistRequestContextOnRead = func() bool { return tt.fgEnabledOnRead }
217+
queue.PersistRequestContextOnWrite = func() bool { return tt.fgEnabledOnWrite }
217218
t.Cleanup(func() {
218-
queue.PersistRequestContextOnRead = fgOrigState
219-
queue.PersistRequestContextOnWrite = fgOrigState
219+
queue.PersistRequestContextOnRead = fgOrigReadState
220+
queue.PersistRequestContextOnWrite = fgOrigWriteState
220221
})
221222

222223
ms := consumertest.MetricsSink{}

exporter/exporterhelper/traces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type tracesEncoding struct{}
5959
var _ QueueBatchEncoding[Request] = tracesEncoding{}
6060

6161
func (tracesEncoding) Unmarshal(bytes []byte) (context.Context, Request, error) {
62-
if queue.PersistRequestContextOnRead {
62+
if queue.PersistRequestContextOnRead() {
6363
ctx, traces, err := pdatareq.UnmarshalTraces(bytes)
6464
if errors.Is(err, pdatareq.ErrInvalidFormat) {
6565
// fall back to unmarshaling without context
@@ -77,7 +77,7 @@ func (tracesEncoding) Unmarshal(bytes []byte) (context.Context, Request, error)
7777

7878
func (tracesEncoding) Marshal(ctx context.Context, req Request) ([]byte, error) {
7979
traces := req.(*tracesRequest).td
80-
if queue.PersistRequestContextOnWrite {
80+
if queue.PersistRequestContextOnWrite() {
8181
return pdatareq.MarshalTraces(ctx, traces)
8282
}
8383
return tracesMarshaler.MarshalTraces(traces)

exporter/exporterhelper/traces_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ func TestTracesRequest_Default_ExportError(t *testing.T) {
168168
}
169169

170170
func TestTraces_WithPersistentQueue(t *testing.T) {
171-
fgOrigState := queue.PersistRequestContextFeatureGate.IsEnabled()
171+
fgOrigReadState := queue.PersistRequestContextOnRead
172+
fgOrigWriteState := queue.PersistRequestContextOnWrite
172173
qCfg := NewDefaultQueueConfig()
173174
storageID := component.MustNewIDWithName("file_storage", "storage")
174175
qCfg.StorageID = configoptional.Some(storageID)
@@ -210,11 +211,11 @@ func TestTraces_WithPersistentQueue(t *testing.T) {
210211
}
211212
for _, tt := range tests {
212213
t.Run(tt.name, func(t *testing.T) {
213-
queue.PersistRequestContextOnRead = tt.fgEnabledOnRead
214-
queue.PersistRequestContextOnWrite = tt.fgEnabledOnWrite
214+
queue.PersistRequestContextOnRead = func() bool { return tt.fgEnabledOnRead }
215+
queue.PersistRequestContextOnWrite = func() bool { return tt.fgEnabledOnWrite }
215216
t.Cleanup(func() {
216-
queue.PersistRequestContextOnRead = fgOrigState
217-
queue.PersistRequestContextOnWrite = fgOrigState
217+
queue.PersistRequestContextOnRead = fgOrigReadState
218+
queue.PersistRequestContextOnWrite = fgOrigWriteState
218219
})
219220

220221
ts := consumertest.TracesSink{}

exporter/exporterhelper/xexporterhelper/profiles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type profilesEncoding struct{}
6262
var _ exporterhelper.QueueBatchEncoding[request.Request] = profilesEncoding{}
6363

6464
func (profilesEncoding) Unmarshal(bytes []byte) (context.Context, request.Request, error) {
65-
if queue.PersistRequestContextOnRead {
65+
if queue.PersistRequestContextOnRead() {
6666
ctx, profiles, err := pdatareq.UnmarshalProfiles(bytes)
6767
if errors.Is(err, pdatareq.ErrInvalidFormat) {
6868
// fall back to unmarshaling without context
@@ -80,7 +80,7 @@ func (profilesEncoding) Unmarshal(bytes []byte) (context.Context, request.Reques
8080

8181
func (profilesEncoding) Marshal(ctx context.Context, req request.Request) ([]byte, error) {
8282
profiles := req.(*profilesRequest).pd
83-
if queue.PersistRequestContextOnWrite {
83+
if queue.PersistRequestContextOnWrite() {
8484
return pdatareq.MarshalProfiles(ctx, profiles)
8585
}
8686
return profilesMarshaler.MarshalProfiles(profiles)

exporter/exporterhelper/xexporterhelper/profiles_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ func TestProfilesRequestExporter_Default_ExportError(t *testing.T) {
168168
}
169169

170170
func TestProfiles_WithPersistentQueue(t *testing.T) {
171-
fgOrigState := queue.PersistRequestContextFeatureGate.IsEnabled()
171+
fgOrigReadState := queue.PersistRequestContextOnRead
172+
fgOrigWriteState := queue.PersistRequestContextOnWrite
172173
qCfg := exporterhelper.NewDefaultQueueConfig()
173174
storageID := component.MustNewIDWithName("file_storage", "storage")
174175
qCfg.StorageID = configoptional.Some(storageID)
@@ -210,11 +211,11 @@ func TestProfiles_WithPersistentQueue(t *testing.T) {
210211
}
211212
for _, tt := range tests {
212213
t.Run(tt.name, func(t *testing.T) {
213-
queue.PersistRequestContextOnRead = tt.fgEnabledOnRead
214-
queue.PersistRequestContextOnWrite = tt.fgEnabledOnWrite
214+
queue.PersistRequestContextOnRead = func() bool { return tt.fgEnabledOnRead }
215+
queue.PersistRequestContextOnWrite = func() bool { return tt.fgEnabledOnWrite }
215216
t.Cleanup(func() {
216-
queue.PersistRequestContextOnRead = fgOrigState
217-
queue.PersistRequestContextOnWrite = fgOrigState
217+
queue.PersistRequestContextOnRead = fgOrigReadState
218+
queue.PersistRequestContextOnWrite = fgOrigWriteState
218219
})
219220

220221
ts := consumertest.ProfilesSink{}

0 commit comments

Comments
 (0)