Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[service] Return telemetry.Config validation errors #12100

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/service-config-validate.yaml
Original file line number Diff line number Diff line change
@@ -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: [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.
# 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: []
1 change: 1 addition & 0 deletions otelcol/testdata/otelcol-emptyreaders.yaml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ exporters:
service:
telemetry:
metrics:
level: none
readers: []
pipelines:
metrics:
2 changes: 1 addition & 1 deletion service/config.go
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions service/config_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
Loading