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

Update validate command to use the new configuration options #10203

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions .chloggen/update-validate-command.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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: otelcol

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Update validate command to use the new configuration options

# One or more tracking issues or pull requests related to the change
issues: [10203]

# 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: [api]
15 changes: 2 additions & 13 deletions otelcol/command_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package otelcol // import "go.opentelemetry.io/collector/otelcol"

import (
"errors"
"flag"

"github.com/spf13/cobra"
Expand All @@ -17,18 +16,8 @@ func newValidateSubCommand(set CollectorSettings, flagSet *flag.FlagSet) *cobra.
Short: "Validates the config without running the collector",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, _ []string) error {
if set.ConfigProvider == nil {
var err error

configFlags := getConfigFlag(flagSet)
if len(configFlags) == 0 {
return errors.New("at least one config flag must be provided")
}

set.ConfigProvider, err = NewConfigProvider(newDefaultConfigProviderSettings(configFlags))
if err != nil {
return err
}
if err := updateSettingsUsingFlags(&set, flagSet); err != nil {
return err
}
col, err := NewCollector(set)
if err != nil {
Expand Down
20 changes: 8 additions & 12 deletions otelcol/command_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ func TestValidateSubCommandNoConfig(t *testing.T) {
}

func TestValidateSubCommandInvalidComponents(t *testing.T) {
cfgProvider, err := NewConfigProvider(
ConfigProviderSettings{
ResolverSettings: confmap.ResolverSettings{
URIs: []string{filepath.Join("testdata", "otelcol-invalid-components.yaml")},
ProviderFactories: []confmap.ProviderFactory{fileprovider.NewFactory()},
ConverterFactories: []confmap.ConverterFactory{expandconverter.NewFactory()},
},
})
require.NoError(t, err)

cmd := newValidateSubCommand(CollectorSettings{Factories: nopFactories, ConfigProvider: cfgProvider}, flags(featuregate.GlobalRegistry()))
err = cmd.Execute()
cmd := newValidateSubCommand(CollectorSettings{Factories: nopFactories, ConfigProviderSettings: ConfigProviderSettings{
ResolverSettings: confmap.ResolverSettings{
URIs: []string{filepath.Join("testdata", "otelcol-invalid-components.yaml")},
ProviderFactories: []confmap.ProviderFactory{fileprovider.NewFactory()},
ConverterFactories: []confmap.ConverterFactory{expandconverter.NewFactory()},
},
}}, flags(featuregate.GlobalRegistry()))
err := cmd.Execute()
require.Error(t, err)
require.Contains(t, err.Error(), "unknown type: \"nosuchprocessor\"")
}
Loading