From 9e772e931b1b2b2d27c6d2c4a03b133c745fc8ef Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Wed, 15 Jan 2025 11:46:48 -0500 Subject: [PATCH 1/3] [service] Return telemetry.Config validation errors --- .chloggen/service-config-validate.yaml | 25 ++++++++++++++++++++++ otelcol/testdata/otelcol-emptyreaders.yaml | 1 + service/config.go | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .chloggen/service-config-validate.yaml diff --git a/.chloggen/service-config-validate.yaml b/.chloggen/service-config-validate.yaml new file mode 100644 index 00000000000..7cb483d00f8 --- /dev/null +++ b/.chloggen/service-config-validate.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: service + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Include validation errors from telemetry.Config when validating the service config + +# One or more tracking issues or pull requests related to the change +issues: [] + +# (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: Previously validation errors were only printed to the console + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/otelcol/testdata/otelcol-emptyreaders.yaml b/otelcol/testdata/otelcol-emptyreaders.yaml index 3a71b541f1a..f8f78dc7ba6 100644 --- a/otelcol/testdata/otelcol-emptyreaders.yaml +++ b/otelcol/testdata/otelcol-emptyreaders.yaml @@ -7,6 +7,7 @@ exporters: service: telemetry: metrics: + level: none readers: [] pipelines: metrics: diff --git a/service/config.go b/service/config.go index 9c3eb4d7d74..2cf2d26934d 100644 --- a/service/config.go +++ b/service/config.go @@ -29,7 +29,7 @@ func (cfg *Config) Validate() error { } if err := cfg.Telemetry.Validate(); err != nil { - fmt.Printf("service::telemetry config validation failed: %v\n", err) + return fmt.Errorf("service::telemetry config validation failed: %w", err) } return nil From 92dfb4c9f96caf623506611d1c1c80fa4ab384d0 Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Wed, 22 Jan 2025 10:09:08 -0500 Subject: [PATCH 2/3] Fix test --- service/config_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/service/config_test.go b/service/config_test.go index ab292a2665d..f313b1aa318 100644 --- a/service/config_test.go +++ b/service/config_test.go @@ -71,14 +71,19 @@ func TestConfigValidate(t *testing.T) { cfg.Telemetry.Metrics.Readers = nil return cfg }, - expected: nil, + expected: errors.New("service::telemetry config validation failed: collector telemetry metrics reader should exist when metric level is not none"), }, } for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { cfg := tt.cfgFn() - assert.Equal(t, tt.expected, cfg.Validate()) + err := cfg.Validate() + if tt.expected != nil { + assert.EqualError(t, err, tt.expected.Error()) + } else { + assert.NoError(t, err) + } }) } } From c1b198046ca5c8cda8b9612aa9bb8533905a1a6f Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:41:32 -0500 Subject: [PATCH 3/3] Add issue number --- .chloggen/service-config-validate.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/service-config-validate.yaml b/.chloggen/service-config-validate.yaml index 7cb483d00f8..03abd62cb71 100644 --- a/.chloggen/service-config-validate.yaml +++ b/.chloggen/service-config-validate.yaml @@ -10,7 +10,7 @@ component: service note: Include validation errors from telemetry.Config when validating the service config # One or more tracking issues or pull requests related to the change -issues: [] +issues: [12100] # (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.