[service] Return `telemetry.Config` validation errors (#12100)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Currently these are just printed, which hides validation issues with `telemetry.Config`. If we don't want to return these errors, we should document that and print them at a warning log level.
This commit is contained in:
parent
0276d781be
commit
50b76b95bf
|
@ -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: []
|
|
@ -7,6 +7,7 @@ exporters:
|
|||
service:
|
||||
telemetry:
|
||||
metrics:
|
||||
level: none
|
||||
readers: []
|
||||
pipelines:
|
||||
metrics:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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…
Reference in New Issue