Skip to content

Commit

Permalink
Update validate command to use the new configuration options (open-te…
Browse files Browse the repository at this point in the history
…lemetry#10203)

After
open-telemetry#9516, the
`validate` sum-command works differently from the root command.

If a downstream distribution provides `URIs` as part of the new
`ConfigProviderSettings` without `--config` flag, the `validate` command
fails with
```
2024/05/21 15:53:25 main.go:85: application run finished with error: at least one config flag must be provided
```
  • Loading branch information
dmitryax authored and steves-canva committed Jun 13, 2024
1 parent e907e9e commit 4f70f4c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
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\"")
}

0 comments on commit 4f70f4c

Please sign in to comment.