Skip to content

Commit bd7d8b2

Browse files
authored
Merge branch 'main' into feat/polling-interval
2 parents 5861a82 + 24aecac commit bd7d8b2

8 files changed

Lines changed: 149 additions & 26 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
change_type: bug_fix
2+
component: pkg/service
3+
note: Fix Prometheus config defaults mismatch when host is explicitly set in telemetry configuration.
4+
subtext: |
5+
When users explicitly configured the telemetry metrics section (e.g. to change the host),
6+
the Prometheus exporter boolean fields (WithoutScopeInfo, WithoutUnits, WithoutTypeSuffix)
7+
defaulted to nil/false instead of true, causing metric name format changes compared to the
8+
implicit default configuration. This fix applies the correct defaults during config unmarshaling.
9+
issues: [13867]
10+
change_logs: [user]

internal/e2e/metric_stability_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -121,47 +121,47 @@ func TestMetricStability(t *testing.T) {
121121
configFile: "metric_stability_test_readers.yaml",
122122
expectedMetrics: map[string]bool{
123123
// Process metrics
124-
"otelcol_process_uptime_seconds_total": false,
125-
"otelcol_process_cpu_seconds_total": false,
126-
"otelcol_process_memory_rss_bytes": false,
127-
"otelcol_process_runtime_heap_alloc_bytes": false,
128-
"otelcol_process_runtime_total_alloc_bytes_total": false,
129-
"otelcol_process_runtime_total_sys_memory_bytes": false,
124+
"otelcol_process_uptime": false,
125+
"otelcol_process_cpu_seconds": false,
126+
"otelcol_process_memory_rss": false,
127+
"otelcol_process_runtime_heap_alloc_bytes": false,
128+
"otelcol_process_runtime_total_alloc_bytes": false,
129+
"otelcol_process_runtime_total_sys_memory_bytes": false,
130130

131131
// Batch processor metrics
132-
"otelcol_processor_batch_batch_send_size": false,
133-
"otelcol_processor_batch_batch_send_size_bytes": false,
134-
"otelcol_processor_batch_metadata_cardinality": false,
135-
"otelcol_processor_batch_timeout_trigger_send_total": false,
132+
"otelcol_processor_batch_batch_send_size": false,
133+
"otelcol_processor_batch_batch_send_size_bytes": false,
134+
"otelcol_processor_batch_metadata_cardinality": false,
135+
"otelcol_processor_batch_timeout_trigger_send": false,
136136

137137
// HTTP server metrics
138-
"http_server_request_body_size_bytes": false,
139-
"http_server_request_duration_seconds": false,
140-
"http_server_response_body_size_bytes": false,
138+
"http_server_request_body_size": false,
139+
"http_server_request_duration": false,
140+
"http_server_response_body_size": false,
141141

142142
// Exporter metrics - Metrics
143-
"otelcol_exporter_sent_metric_points_total": false,
144-
"otelcol_exporter_send_failed_metric_points_total": false,
143+
"otelcol_exporter_sent_metric_points": false,
144+
"otelcol_exporter_send_failed_metric_points": false,
145145

146146
// Exporter metrics - Traces
147-
"otelcol_exporter_sent_spans_total": false,
148-
"otelcol_exporter_send_failed_spans_total": false,
147+
"otelcol_exporter_sent_spans": false,
148+
"otelcol_exporter_send_failed_spans": false,
149149

150150
// Exporter metrics - Logs
151-
"otelcol_exporter_sent_log_records_total": false,
152-
"otelcol_exporter_send_failed_log_records_total": false,
151+
"otelcol_exporter_sent_log_records": false,
152+
"otelcol_exporter_send_failed_log_records": false,
153153

154154
// Receiver metrics
155-
"otelcol_receiver_accepted_metric_points_total": false,
156-
"otelcol_receiver_refused_metric_points_total": false,
155+
"otelcol_receiver_accepted_metric_points": false,
156+
"otelcol_receiver_refused_metric_points": false,
157157

158158
// Receiver metrics - Traces
159-
"otelcol_receiver_accepted_spans_total": false,
160-
"otelcol_receiver_refused_spans_total": false,
159+
"otelcol_receiver_accepted_spans": false,
160+
"otelcol_receiver_refused_spans": false,
161161

162162
// Receiver metrics - Logs
163-
"otelcol_receiver_accepted_log_records_total": false,
164-
"otelcol_receiver_refused_log_records_total": false,
163+
"otelcol_receiver_accepted_log_records": false,
164+
"otelcol_receiver_refused_log_records": false,
165165

166166
// Other metrics
167167
"promhttp_metric_handler_errors_total": false,

service/telemetry/otelconftelemetry/config_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ func TestConfig(t *testing.T) {
9797
"config_invalid_metrics_views_level.yaml": {
9898
validateErr: `service::telemetry::metrics::views can only be set when service::telemetry::metrics::level is detailed`,
9999
},
100+
"config_prometheus_host_only.yaml": {
101+
config: func() *Config {
102+
cfg := createDefaultConfig().(*Config)
103+
host := "[::0]"
104+
cfg.Metrics.Readers = []config.MetricReader{
105+
{
106+
Pull: &config.PullMetricReader{Exporter: config.PullMetricExporter{Prometheus: &config.Prometheus{
107+
WithoutScopeInfo: ptr(true),
108+
WithoutUnits: ptr(true),
109+
WithoutTypeSuffix: ptr(true),
110+
Host: &host,
111+
Port: ptr(8888),
112+
}}},
113+
},
114+
}
115+
return cfg
116+
}(),
117+
},
100118
}
101119

102120
for filename, test := range tests {

service/telemetry/otelconftelemetry/internal/migration/testdata/v0.3.0_metrics_marshaled.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ readers:
1313
prometheus:
1414
host: 127.0.0.1
1515
port: 8902
16+
without_scope_info: true
17+
without_type_suffix: true
18+
without_units: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
level: normal
2+
readers:
3+
- pull:
4+
exporter:
5+
prometheus:
6+
host: 127.0.0.1
7+
port: 8888
8+
without_scope_info: false
9+
without_units: false
10+
without_type_suffix: false

service/telemetry/otelconftelemetry/internal/migration/v0.3.0.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,27 @@ func (c *MetricsConfigV030) Unmarshal(conf *confmap.Conf) error {
108108
c.MigratedFromV02 = true
109109
return metricsConfigV02ToV03(v02, c)
110110
}
111-
// ensure endpoint normalization occurs
112111
for _, r := range c.Readers {
112+
// ensure endpoint normalization occurs
113113
if r.Periodic != nil {
114114
if r.Periodic.Exporter.OTLP != nil && r.Periodic.Exporter.OTLP.Endpoint != nil {
115115
r.Periodic.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Periodic.Exporter.OTLP.Endpoint, r.Periodic.Exporter.OTLP.Insecure)
116116
}
117117
}
118+
// Apply Prometheus exporter defaults for fields not explicitly set.
119+
// When users explicitly configure the telemetry section (e.g. to
120+
// change the host), unset *bool fields default to nil which the
121+
// Prometheus exporter treats as false. This ensures the defaults
122+
// match the implicit/default configuration where these are true.
123+
//
124+
// This is necessary because specifying any metric readers in the
125+
// SDK config completely overwrites the list of readers, so the
126+
// Prometheus exporter is treated as a new config without any of
127+
// the defaults set in the createDefaultConfig function in
128+
// otelconftelemetry. We must re-apply those defaults here.
129+
if r.Pull != nil && r.Pull.Exporter.Prometheus != nil {
130+
applyPrometheusDefaults(r.Pull.Exporter.Prometheus)
131+
}
118132
}
119133
return nil
120134
}
@@ -132,6 +146,24 @@ func (c MetricsConfigV030) Marshal(conf *confmap.Conf) error {
132146
return conf.Marshal(sm)
133147
}
134148

149+
func boolPtr(v bool) *bool {
150+
return &v
151+
}
152+
153+
// applyPrometheusDefaults sets default values for Prometheus exporter
154+
// fields that were not explicitly provided in the configuration.
155+
func applyPrometheusDefaults(p *config.Prometheus) {
156+
if p.WithoutScopeInfo == nil {
157+
p.WithoutScopeInfo = boolPtr(true)
158+
}
159+
if p.WithoutUnits == nil {
160+
p.WithoutUnits = boolPtr(true)
161+
}
162+
if p.WithoutTypeSuffix == nil {
163+
p.WithoutTypeSuffix = boolPtr(true)
164+
}
165+
}
166+
135167
type LogsConfigV030 struct {
136168
// Level is the minimum enabled logging level.
137169
// (default = "INFO")

service/telemetry/otelconftelemetry/internal/migration/v0.3.0_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,35 @@ func TestUnmarshalMetricsConfigV030(t *testing.T) {
8585
require.Equal(t, "https://127.0.0.1:4317", *cfg.Readers[0].Periodic.Exporter.OTLP.Endpoint)
8686
// ensure migration flag is not set for native v0.3.0 config
8787
require.False(t, cfg.MigratedFromV02)
88+
89+
// check that Prometheus exporter defaults are applied even when not explicitly set
90+
prom := cfg.Readers[1].Pull.Exporter.Prometheus
91+
require.NotNil(t, prom)
92+
require.NotNil(t, prom.WithoutScopeInfo, "WithoutScopeInfo should default to non-nil")
93+
require.True(t, *prom.WithoutScopeInfo, "WithoutScopeInfo should default to true")
94+
require.NotNil(t, prom.WithoutUnits, "WithoutUnits should default to non-nil")
95+
require.True(t, *prom.WithoutUnits, "WithoutUnits should default to true")
96+
require.NotNil(t, prom.WithoutTypeSuffix, "WithoutTypeSuffix should default to non-nil")
97+
require.True(t, *prom.WithoutTypeSuffix, "WithoutTypeSuffix should default to true")
98+
}
99+
100+
func TestUnmarshalMetricsConfigV030_PrometheusExplicitFalse(t *testing.T) {
101+
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.3.0_metrics_prom_explicit.yaml"))
102+
require.NoError(t, err)
103+
104+
cfg := MetricsConfigV030{}
105+
require.NoError(t, cm.Unmarshal(&cfg))
106+
require.Len(t, cfg.Readers, 1)
107+
108+
// When explicitly set to false, values should remain false
109+
prom := cfg.Readers[0].Pull.Exporter.Prometheus
110+
require.NotNil(t, prom)
111+
require.NotNil(t, prom.WithoutScopeInfo)
112+
require.False(t, *prom.WithoutScopeInfo, "WithoutScopeInfo should be false when explicitly set")
113+
require.NotNil(t, prom.WithoutUnits)
114+
require.False(t, *prom.WithoutUnits, "WithoutUnits should be false when explicitly set")
115+
require.NotNil(t, prom.WithoutTypeSuffix)
116+
require.False(t, *prom.WithoutTypeSuffix, "WithoutTypeSuffix should be false when explicitly set")
88117
}
89118

90119
func TestMarshalMetricsConfigV030(t *testing.T) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
logs:
2+
level: info
3+
development: false
4+
encoding: console
5+
sampling:
6+
enabled: true
7+
tick: 10s
8+
initial: 10
9+
thereafter: 100
10+
output_paths:
11+
- stderr
12+
error_output_paths:
13+
- stderr
14+
metrics:
15+
level: normal
16+
readers:
17+
- pull:
18+
exporter:
19+
prometheus:
20+
host: "[::0]"
21+
port: 8888

0 commit comments

Comments
 (0)