Skip to content

Commit

Permalink
Fix validate command (#9866)
Browse files Browse the repository at this point in the history
**Description:**
Fixes issue where validate command was not properly printing valid
values.

**Link to tracking Issue:**
Closes
#9863

**Testing:**
Updated unit tests
  • Loading branch information
TylerHelmuth authored Mar 27, 2024
1 parent 8dd42ec commit 38316de
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
25 changes: 25 additions & 0 deletions .chloggen/fix-validate-command.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: otelcol

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix issue where the `validate` command wasn't properly printing valid component type.

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

# (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:

# 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 changes: 4 additions & 3 deletions cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ require (
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
Expand Down Expand Up @@ -121,11 +121,12 @@ require (
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/text v0.14.0 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
18 changes: 6 additions & 12 deletions cmd/otelcorecol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions otelcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/sys v0.18.0
google.golang.org/grpc v1.62.1
gopkg.in/yaml.v3 v3.0.1
Expand Down
7 changes: 4 additions & 3 deletions otelcol/internal/configunmarshaler/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ package configunmarshaler // import "go.opentelemetry.io/collector/otelcol/inter

import (
"fmt"
"reflect"

"golang.org/x/exp/maps"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
Expand Down Expand Up @@ -34,7 +35,7 @@ func (c *Configs[F]) Unmarshal(conf *confmap.Conf) error {
// Find factory based on component kind and type that we read from config source.
factory, ok := c.factories[id.Type()]
if !ok {
return errorUnknownType(id, reflect.ValueOf(c.factories).MapKeys())
return errorUnknownType(id, maps.Keys(c.factories))
}

// Create the default config for this component.
Expand All @@ -56,7 +57,7 @@ func (c *Configs[F]) Configs() map[component.ID]component.Config {
return c.cfgs
}

func errorUnknownType(id component.ID, factories []reflect.Value) error {
func errorUnknownType(id component.ID, factories []component.Type) error {
return fmt.Errorf("unknown type: %q for id: %q (valid values: %v)", id.Type(), id, factories)
}

Expand Down
2 changes: 1 addition & 1 deletion otelcol/internal/configunmarshaler/configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestUnmarshalError(t *testing.T) {
conf: confmap.NewFromStringMap(map[string]any{
"nosuch" + tk.kind: nil,
}),
expectedError: "unknown type: \"nosuch" + tk.kind + "\"",
expectedError: "unknown type: \"nosuch" + tk.kind + "\" for id: \"nosuch" + tk.kind + "\" (valid values: [nop])",
},
{
name: "duplicate",
Expand Down

0 comments on commit 38316de

Please sign in to comment.