Skip to content

Commit

Permalink
[service] Return telemetry.Config validation errors (#12100)
Browse files Browse the repository at this point in the history
<!--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.
  • Loading branch information
evan-bradley authored Jan 30, 2025
1 parent 0276d78 commit 50b76b9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
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
Expand Up @@ -7,6 +7,7 @@ exporters:
service:
telemetry:
metrics:
level: none
readers: []
pipelines:
metrics:
Expand Down
2 changes: 1 addition & 1 deletion service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions service/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
Expand Down

0 comments on commit 50b76b9

Please sign in to comment.