-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Created dry run flag for collector #6445
Changes from 2 commits
dd53f75
c022686
a8c81e3
7ddc5ee
be8ffcc
7311780
79d57a1
e388d5e
ac2cbfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# 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: Added dry run flag to validate config file without running collector. | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [6445] | ||
|
||
# (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: |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,8 @@ type ConfigProvider interface { | |
// | ||
// Should never be called concurrently with itself or Get. | ||
Shutdown(ctx context.Context) error | ||
// DryRunGet validates the configuration, prints out all related errors without running the collector | ||
DryRunGet(ctx context.Context, factories component.Factories) (*Config, error, bool) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should "dry run" be a flag or a command? /cc @codeboten @jpkrohling who also reviewed #6322 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Update: after looking at what helm does, i think it should just be a command. I would rename
|
||
} | ||
|
||
type configProvider struct { | ||
|
@@ -116,6 +118,24 @@ func (cm *configProvider) Get(ctx context.Context, factories component.Factories | |
|
||
return cfg, nil | ||
} | ||
func (cm *configProvider) DryRunGet(ctx context.Context, factories component.Factories) (*Config, error, bool) { | ||
retMap, err := cm.mapResolver.Resolve(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot resolve the configuration: %w", err), false | ||
} | ||
|
||
var cfg *Config | ||
cfg, err, errorcheck := configunmarshaler.New().DryRunUnmarshal(retMap, factories) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot unmarshal the configuration: %w", err), false | ||
} | ||
if errorcheck { | ||
return nil, nil, errorcheck | ||
} | ||
|
||
cfg.DryRunValidate() | ||
return nil, nil, false | ||
} | ||
|
||
func (cm *configProvider) Watch() <-chan error { | ||
return cm.mapResolver.Watch() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package service | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/service/internal/configunmarshaler" | ||
) | ||
|
||
func printMarshalErrors(exterrs []configunmarshaler.ExtensionValidateError, experrs []configunmarshaler.ExporterValidateError, recerrs []configunmarshaler.ReceiverValidateError, procerrs []configunmarshaler.ProcessorValidateError) { | ||
count := 1 | ||
for _, exterr := range exterrs { | ||
validateErrorText(count, exterr.Component, exterr.Id, exterr.Err) | ||
count++ | ||
} | ||
for _, experr := range experrs { | ||
validateErrorText(count, experr.Component, experr.Id, experr.Err) | ||
count++ | ||
} | ||
for _, recerr := range recerrs { | ||
validateErrorText(count, recerr.Component, recerr.Id, recerr.Err) | ||
count++ | ||
} | ||
for _, procerr := range procerrs { | ||
validateErrorText(count, procerr.Component, procerr.Id, procerr.Err) | ||
count++ | ||
} | ||
} | ||
|
||
func validateErrorText(count int, idType string, id config.ComponentID, err string) { | ||
fmt.Printf("Error %d\n", count) | ||
fmt.Printf("=============\n") | ||
fmt.Printf("%s:\n", idType) | ||
fmt.Printf(" %s\n", id) | ||
fmt.Printf(" ^---^--- %s\n", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each one of the conditions needs its test to ensure its correctness.