diff --git a/.chloggen/fix-componets-command.yaml b/.chloggen/fix-componets-command.yaml new file mode 100644 index 00000000000..fdcd6effb8f --- /dev/null +++ b/.chloggen/fix-componets-command.yaml @@ -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: component + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix issue where the `components` command wasn't properly printing the component type. + +# One or more tracking issues or pull requests related to the change +issues: [9856] + +# (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: [] diff --git a/component/config.go b/component/config.go index 03569aa166b..d86df1801bd 100644 --- a/component/config.go +++ b/component/config.go @@ -119,6 +119,11 @@ func (t Type) String() string { return t.name } +// MarshalText marshals returns the Type name. +func (t Type) MarshalText() ([]byte, error) { + return []byte(t.name), nil +} + // typeRegexp is used to validate the type of a component. // A type must start with an ASCII alphabetic character and // can only contain ASCII alphanumeric characters and '_'. diff --git a/otelcol/command_components_test.go b/otelcol/command_components_test.go index 141fb586010..c4e3c7fbf29 100644 --- a/otelcol/command_components_test.go +++ b/otelcol/command_components_test.go @@ -5,19 +5,17 @@ package otelcol import ( "bytes" + "os" "path/filepath" "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v3" "go.opentelemetry.io/collector/component" ) -var nopType = component.MustNewType("nop") - func TestNewBuildSubCommand(t *testing.T) { cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")})) require.NoError(t, err) @@ -30,56 +28,7 @@ func TestNewBuildSubCommand(t *testing.T) { cmd := NewCommand(set) cmd.SetArgs([]string{"components"}) - ExpectedYamlStruct := componentsOutput{ - BuildInfo: component.NewDefaultBuildInfo(), - Receivers: []componentWithStability{{ - Name: nopType, - Stability: map[string]string{ - "logs": "Stable", - "metrics": "Stable", - "traces": "Stable", - }, - }}, - Processors: []componentWithStability{{ - Name: nopType, - Stability: map[string]string{ - "logs": "Stable", - "metrics": "Stable", - "traces": "Stable", - }, - }}, - Exporters: []componentWithStability{{ - Name: nopType, - Stability: map[string]string{ - "logs": "Stable", - "metrics": "Stable", - "traces": "Stable", - }, - }}, - Connectors: []componentWithStability{{ - Name: nopType, - Stability: map[string]string{ - "logs-to-logs": "Development", - "logs-to-metrics": "Development", - "logs-to-traces": "Development", - - "metrics-to-logs": "Development", - "metrics-to-metrics": "Development", - "metrics-to-traces": "Development", - - "traces-to-logs": "Development", - "traces-to-metrics": "Development", - "traces-to-traces": "Development", - }, - }}, - Extensions: []componentWithStability{{ - Name: nopType, - Stability: map[string]string{ - "extension": "Stable", - }, - }}, - } - ExpectedOutput, err := yaml.Marshal(ExpectedYamlStruct) + ExpectedOutput, err := os.ReadFile(filepath.Join("testdata", "components-output.yaml")) require.NoError(t, err) b := bytes.NewBufferString("") @@ -89,5 +38,5 @@ func TestNewBuildSubCommand(t *testing.T) { // Trim new line at the end of the two strings to make a better comparison as string() adds an extra new // line that makes the test fail. - assert.Equal(t, strings.Trim(string(ExpectedOutput), "\n"), strings.Trim(b.String(), "\n")) + assert.Equal(t, strings.ReplaceAll(strings.ReplaceAll(string(ExpectedOutput), "\n", ""), "\r", ""), strings.ReplaceAll(strings.ReplaceAll(b.String(), "\n", ""), "\r", "")) } diff --git a/otelcol/testdata/components-output.yaml b/otelcol/testdata/components-output.yaml new file mode 100644 index 00000000000..bfac28484ec --- /dev/null +++ b/otelcol/testdata/components-output.yaml @@ -0,0 +1,38 @@ +buildinfo: + command: otelcol + description: OpenTelemetry Collector + version: latest +receivers: + - name: nop + stability: + logs: Stable + metrics: Stable + traces: Stable +processors: + - name: nop + stability: + logs: Stable + metrics: Stable + traces: Stable +exporters: + - name: nop + stability: + logs: Stable + metrics: Stable + traces: Stable +connectors: + - name: nop + stability: + logs-to-logs: Development + logs-to-metrics: Development + logs-to-traces: Development + metrics-to-logs: Development + metrics-to-metrics: Development + metrics-to-traces: Development + traces-to-logs: Development + traces-to-metrics: Development + traces-to-traces: Development +extensions: + - name: nop + stability: + extension: Stable