Skip to content

Commit db60a91

Browse files
authored
Merge branch 'main' into 41535
2 parents d52cba8 + 791d30d commit db60a91

File tree

10 files changed

+58
-36
lines changed

10 files changed

+58
-36
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: prometheusremotewriteexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Use configoptional for WAL configuration
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [41980]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [api]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ For more information about the approver role, see the [community repository](htt
107107
- [Murphy Chen](https://github.com/Frapschen), DaoCloud
108108
- [Ondrej Dubaj](https://github.com/odubajDT), Dynatrace
109109
- [Paulo Janotti](https://github.com/pjanotti), Splunk
110+
- [Roger Coll](https://github.com/rogercoll), Elastic
110111
- [Vihas Makwana](https://github.com/VihasMakwana), Elastic
111112
- Actively seeking contributors to triage issues
112113

exporter/prometheusremotewriteexporter/config.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/prometheus/prometheus/config"
1111
"go.opentelemetry.io/collector/component"
1212
"go.opentelemetry.io/collector/config/confighttp"
13+
"go.opentelemetry.io/collector/config/configoptional"
1314
"go.opentelemetry.io/collector/config/configretry"
1415
"go.opentelemetry.io/collector/exporter/exporterhelper"
1516

@@ -43,11 +44,11 @@ type Config struct {
4344
// ResourceToTelemetrySettings is the option for converting resource attributes to telemetry attributes.
4445
// "Enabled" - A boolean field to enable/disable this option. Default is `false`.
4546
// If enabled, all the resource attributes will be converted to metric labels by default.
46-
ResourceToTelemetrySettings resourcetotelemetry.Settings `mapstructure:"resource_to_telemetry_conversion"`
47-
WAL *WALConfig `mapstructure:"wal"`
47+
ResourceToTelemetrySettings resourcetotelemetry.Settings `mapstructure:"resource_to_telemetry_conversion"`
48+
WAL configoptional.Optional[WALConfig] `mapstructure:"wal"`
4849

4950
// TargetInfo allows customizing the target_info metric
50-
TargetInfo *TargetInfo `mapstructure:"target_info,omitempty"`
51+
TargetInfo TargetInfo `mapstructure:"target_info,omitempty"`
5152

5253
// AddMetricSuffixes controls whether unit and type suffixes are added to metrics on export
5354
AddMetricSuffixes bool `mapstructure:"add_metric_suffixes"`
@@ -107,11 +108,6 @@ func (cfg *Config) Validate() error {
107108
return errors.New("remote write consumer number can't be negative")
108109
}
109110

110-
if cfg.TargetInfo == nil {
111-
cfg.TargetInfo = &TargetInfo{
112-
Enabled: true,
113-
}
114-
}
115111
if cfg.MaxBatchSizeBytes < 0 {
116112
return errors.New("max_batch_byte_size must be greater than 0")
117113
}

exporter/prometheusremotewriteexporter/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestLoadConfig(t *testing.T) {
7979
ExternalLabels: map[string]string{"key1": "value1", "key2": "value2"},
8080
ClientConfig: clientConfig,
8181
ResourceToTelemetrySettings: resourcetotelemetry.Settings{Enabled: true},
82-
TargetInfo: &TargetInfo{
82+
TargetInfo: TargetInfo{
8383
Enabled: true,
8484
},
8585
RemoteWriteProtoMsg: config.RemoteWriteProtoMsgV1,

exporter/prometheusremotewriteexporter/exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func newPRWExporter(cfg *Config, set exporter.Settings) (*prwExporter, error) {
194194

195195
prwe.settings.Logger.Info("starting prometheus remote write exporter", zap.Any("ProtoMsg", cfg.RemoteWriteProtoMsg))
196196

197-
prwe.wal, err = newWAL(cfg.WAL, set, prwe.export)
197+
prwe.wal, err = newWAL(cfg.WAL.Get(), set, prwe.export)
198198
if err != nil {
199199
return nil, err
200200
}

exporter/prometheusremotewriteexporter/exporter_concurrency_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func Test_PushMetricsConcurrent(t *testing.T) {
108108
ClientConfig: clientConfig,
109109
MaxBatchSizeBytes: 3000000,
110110
RemoteWriteQueue: RemoteWriteQueue{NumConsumers: 1},
111-
TargetInfo: &TargetInfo{
111+
TargetInfo: TargetInfo{
112112
Enabled: true,
113113
},
114114
BackOffConfig: retrySettings,

exporter/prometheusremotewriteexporter/exporter_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"go.opentelemetry.io/collector/component"
2929
"go.opentelemetry.io/collector/component/componenttest"
3030
"go.opentelemetry.io/collector/config/confighttp"
31+
"go.opentelemetry.io/collector/config/configoptional"
3132
"go.opentelemetry.io/collector/config/configretry"
3233
"go.opentelemetry.io/collector/config/configtls"
3334
"go.opentelemetry.io/collector/consumer/consumererror"
@@ -56,7 +57,7 @@ func Test_NewPRWExporter(t *testing.T) {
5657
Namespace: "",
5758
ExternalLabels: map[string]string{},
5859
ClientConfig: confighttp.NewDefaultClientConfig(),
59-
TargetInfo: &TargetInfo{
60+
TargetInfo: TargetInfo{
6061
Enabled: true,
6162
},
6263
}
@@ -150,7 +151,7 @@ func Test_Start(t *testing.T) {
150151
MaxBatchSizeBytes: 3000000,
151152
Namespace: "",
152153
ExternalLabels: map[string]string{},
153-
TargetInfo: &TargetInfo{
154+
TargetInfo: TargetInfo{
154155
Enabled: true,
155156
},
156157
}
@@ -740,7 +741,7 @@ func Test_PushMetrics(t *testing.T) {
740741
ClientConfig: clientConfig,
741742
MaxBatchSizeBytes: 3000000,
742743
RemoteWriteQueue: RemoteWriteQueue{NumConsumers: 1},
743-
TargetInfo: &TargetInfo{
744+
TargetInfo: TargetInfo{
744745
Enabled: true,
745746
},
746747
BackOffConfig: retrySettings,
@@ -756,9 +757,9 @@ func Test_PushMetrics(t *testing.T) {
756757
}
757758

758759
if useWAL {
759-
cfg.WAL = &WALConfig{
760+
cfg.WAL = configoptional.Some(WALConfig{
760761
Directory: t.TempDir(),
761-
}
762+
})
762763
}
763764

764765
assert.NotNil(t, cfg)
@@ -969,11 +970,11 @@ func TestWALOnExporterRoundTrip(t *testing.T) {
969970
Namespace: "test_ns",
970971
ClientConfig: clientConfig,
971972
RemoteWriteQueue: RemoteWriteQueue{NumConsumers: 1},
972-
WAL: &WALConfig{
973+
WAL: configoptional.Some(WALConfig{
973974
Directory: tempDir,
974975
BufferSize: 1,
975-
},
976-
TargetInfo: &TargetInfo{
976+
}),
977+
TargetInfo: TargetInfo{
977978
Enabled: true,
978979
},
979980
}
@@ -1017,7 +1018,7 @@ func TestWALOnExporterRoundTrip(t *testing.T) {
10171018

10181019
// 3. Let's now read back all of the WAL records and ensure
10191020
// that all the prompb.WriteRequest values exist as we sent them.
1020-
wal, _, werr := cfg.WAL.createWAL()
1021+
wal, _, werr := cfg.WAL.Get().createWAL()
10211022
assert.NoError(t, werr)
10221023
assert.NotNil(t, wal)
10231024
t.Cleanup(func() {
@@ -1350,7 +1351,7 @@ func benchmarkPushMetrics(b *testing.B, numMetrics, numConsumers int) {
13501351
MaxBatchSizeBytes: 3000,
13511352
RemoteWriteQueue: RemoteWriteQueue{NumConsumers: numConsumers},
13521353
BackOffConfig: retrySettings,
1353-
TargetInfo: &TargetInfo{Enabled: true},
1354+
TargetInfo: TargetInfo{Enabled: true},
13541355
}
13551356
exporter, err := newPRWExporter(cfg, set)
13561357
require.NoError(b, err)

exporter/prometheusremotewriteexporter/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func createDefaultConfig() component.Config {
123123
QueueSize: 10000,
124124
NumConsumers: numConsumers,
125125
},
126-
TargetInfo: &TargetInfo{
126+
TargetInfo: TargetInfo{
127127
Enabled: true,
128128
},
129129
}

exporter/prometheusremotewriteexporter/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require (
1818
go.opentelemetry.io/collector/component/componenttest v0.132.0
1919
go.opentelemetry.io/collector/config/confighttp v0.132.0
2020
go.opentelemetry.io/collector/config/configopaque v1.38.0
21+
go.opentelemetry.io/collector/config/configoptional v0.132.0
2122
go.opentelemetry.io/collector/config/configretry v1.38.0
2223
go.opentelemetry.io/collector/config/configtls v1.38.0
2324
go.opentelemetry.io/collector/confmap v1.38.0
@@ -110,7 +111,6 @@ require (
110111
go.opentelemetry.io/collector/config/configauth v0.132.0 // indirect
111112
go.opentelemetry.io/collector/config/configcompression v1.38.0 // indirect
112113
go.opentelemetry.io/collector/config/configmiddleware v0.132.0 // indirect
113-
go.opentelemetry.io/collector/config/configoptional v0.132.0 // indirect
114114
go.opentelemetry.io/collector/consumer v1.38.0 // indirect
115115
go.opentelemetry.io/collector/consumer/consumertest v0.132.0 // indirect
116116
go.opentelemetry.io/collector/consumer/xconsumer v0.132.0 // indirect

exporter/prometheusremotewriteexporter/wal_test.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"go.opentelemetry.io/collector/component"
2424
"go.opentelemetry.io/collector/component/componenttest"
2525
"go.opentelemetry.io/collector/config/confighttp"
26+
"go.opentelemetry.io/collector/config/configoptional"
2627
"go.opentelemetry.io/collector/exporter/exportertest"
2728
"go.opentelemetry.io/otel/sdk/metric/metricdata"
2829
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"
@@ -176,10 +177,9 @@ func TestWAL_persist(t *testing.T) {
176177

177178
func TestExportWithWALEnabled(t *testing.T) {
178179
cfg := &Config{
179-
WAL: &WALConfig{
180+
WAL: configoptional.Some(WALConfig{
180181
Directory: t.TempDir(),
181-
},
182-
TargetInfo: &TargetInfo{}, // Declared just to avoid nil pointer dereference.
182+
}),
183183
RemoteWriteProtoMsg: config.RemoteWriteProtoMsgV1,
184184
}
185185
buildInfo := component.BuildInfo{
@@ -241,10 +241,9 @@ func TestWALWrite_Telemetry(t *testing.T) {
241241
set := metadatatest.NewSettings(tel)
242242

243243
cfg := &Config{
244-
WAL: &WALConfig{
244+
WAL: configoptional.Some(WALConfig{
245245
Directory: t.TempDir(),
246-
},
247-
TargetInfo: &TargetInfo{}, // Declared just to avoid nil pointer dereference.
246+
}),
248247
RemoteWriteProtoMsg: config.RemoteWriteProtoMsgV2,
249248
}
250249

@@ -312,11 +311,10 @@ func TestWALRead_Telemetry(t *testing.T) {
312311
// Create a temporary directory for the WAL
313312
tempDir := t.TempDir()
314313
cfg := &Config{
315-
WAL: &WALConfig{
314+
WAL: configoptional.Some(WALConfig{
316315
BufferSize: 1,
317316
Directory: tempDir,
318-
},
319-
TargetInfo: &TargetInfo{}, // Declared just to avoid nil pointer dereference.
317+
}),
320318
RemoteWriteProtoMsg: config.RemoteWriteProtoMsgV2,
321319
}
322320

@@ -389,12 +387,11 @@ func TestWALLag_Telemetry(t *testing.T) {
389387
set := metadatatest.NewSettings(tel)
390388

391389
cfg := &Config{
392-
WAL: &WALConfig{
390+
WAL: configoptional.Some(WALConfig{
393391
Directory: t.TempDir(),
394392
BufferSize: 1,
395393
LagRecordFrequency: 10 * time.Millisecond, // Very short interval for testing
396-
},
397-
TargetInfo: &TargetInfo{},
394+
}),
398395
RemoteWriteProtoMsg: config.RemoteWriteProtoMsgV2,
399396
}
400397

@@ -431,7 +428,7 @@ func TestWALLag_Telemetry(t *testing.T) {
431428
require.NoError(t, err)
432429

433430
// Wait for lag recording to happen (longer than lagRecordFrequency)
434-
time.Sleep(5 * cfg.WAL.LagRecordFrequency)
431+
time.Sleep(5 * cfg.WAL.Get().LagRecordFrequency)
435432

436433
_, err = tel.GetMetric("otelcol_exporter_prometheusremotewrite_wal_lag")
437434
require.NoError(t, err)

0 commit comments

Comments
 (0)