Skip to content

Commit 38316de

Browse files
authored
Fix validate command (#9866)
**Description:** Fixes issue where validate command was not properly printing valid values. **Link to tracking Issue:** Closes #9863 **Testing:** Updated unit tests
1 parent 8dd42ec commit 38316de

File tree

6 files changed

+41
-19
lines changed

6 files changed

+41
-19
lines changed

.chloggen/fix-validate-command.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: otelcol
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix issue where the `validate` command wasn't properly printing valid component type.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [9866]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: []

cmd/otelcorecol/go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ require (
4343
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
4444
github.com/gogo/protobuf v1.3.2 // indirect
4545
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
46-
github.com/golang/protobuf v1.5.3 // indirect
46+
github.com/golang/protobuf v1.5.4 // indirect
4747
github.com/golang/snappy v0.0.4 // indirect
4848
github.com/google/uuid v1.6.0 // indirect
4949
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
@@ -121,11 +121,12 @@ require (
121121
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
122122
go.uber.org/multierr v1.11.0 // indirect
123123
go.uber.org/zap v1.27.0 // indirect
124+
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
124125
golang.org/x/net v0.22.0 // indirect
125126
golang.org/x/text v0.14.0 // indirect
126127
gonum.org/v1/gonum v0.15.0 // indirect
127-
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
128-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
128+
google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c // indirect
129+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
129130
google.golang.org/grpc v1.62.1 // indirect
130131
google.golang.org/protobuf v1.33.0 // indirect
131132
gopkg.in/yaml.v3 v3.0.1 // indirect

cmd/otelcorecol/go.sum

Lines changed: 6 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

otelcol/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require (
2424
go.uber.org/goleak v1.3.0
2525
go.uber.org/multierr v1.11.0
2626
go.uber.org/zap v1.27.0
27+
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
2728
golang.org/x/sys v0.18.0
2829
google.golang.org/grpc v1.62.1
2930
gopkg.in/yaml.v3 v3.0.1

otelcol/internal/configunmarshaler/configs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ package configunmarshaler // import "go.opentelemetry.io/collector/otelcol/inter
55

66
import (
77
"fmt"
8-
"reflect"
8+
9+
"golang.org/x/exp/maps"
910

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

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

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

otelcol/internal/configunmarshaler/configs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestUnmarshalError(t *testing.T) {
104104
conf: confmap.NewFromStringMap(map[string]any{
105105
"nosuch" + tk.kind: nil,
106106
}),
107-
expectedError: "unknown type: \"nosuch" + tk.kind + "\"",
107+
expectedError: "unknown type: \"nosuch" + tk.kind + "\" for id: \"nosuch" + tk.kind + "\" (valid values: [nop])",
108108
},
109109
{
110110
name: "duplicate",

0 commit comments

Comments
 (0)