From e7ccf85edd09dbed7e9ea92805713d010fd882bc Mon Sep 17 00:00:00 2001 From: Evan Bradley Date: Thu, 1 Jun 2023 16:25:30 -0400 Subject: [PATCH] Add connectors to the components command --- .../add-connectors-to-components-command.yaml | 16 ++++++++++++++++ otelcol/command_components.go | 4 ++++ otelcol/command_components_test.go | 1 + otelcol/configprovider_test.go | 6 ++++-- otelcol/factories_test.go | 6 ++++++ otelcol/testdata/otelcol-nop.yaml | 7 +++++-- 6 files changed, 36 insertions(+), 4 deletions(-) create mode 100755 .chloggen/add-connectors-to-components-command.yaml diff --git a/.chloggen/add-connectors-to-components-command.yaml b/.chloggen/add-connectors-to-components-command.yaml new file mode 100755 index 00000000000..6a7d34fca12 --- /dev/null +++ b/.chloggen/add-connectors-to-components-command.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# 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: Add connectors to output of the `components` command + +# One or more tracking issues or pull requests related to the change +issues: [7809] + +# (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: diff --git a/otelcol/command_components.go b/otelcol/command_components.go index 783f082f272..23388280122 100644 --- a/otelcol/command_components.go +++ b/otelcol/command_components.go @@ -17,6 +17,7 @@ type componentsOutput struct { Receivers []component.Type Processors []component.Type Exporters []component.Type + Connectors []component.Type Extensions []component.Type } @@ -29,6 +30,9 @@ func newBuildSubCommand(set CollectorSettings) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { components := componentsOutput{} + for con := range set.Factories.Connectors { + components.Connectors = append(components.Connectors, con) + } for ext := range set.Factories.Extensions { components.Extensions = append(components.Extensions, ext) } diff --git a/otelcol/command_components_test.go b/otelcol/command_components_test.go index 81920eb7d52..37e923276f5 100644 --- a/otelcol/command_components_test.go +++ b/otelcol/command_components_test.go @@ -36,6 +36,7 @@ func TestNewBuildSubCommand(t *testing.T) { Receivers: []component.Type{"nop"}, Processors: []component.Type{"nop"}, Exporters: []component.Type{"nop"}, + Connectors: []component.Type{"nop"}, Extensions: []component.Type{"nop"}, } ExpectedOutput, err := yaml.Marshal(ExpectedYamlStruct) diff --git a/otelcol/configprovider_test.go b/otelcol/configprovider_test.go index 464af306456..7584950bd40 100644 --- a/otelcol/configprovider_test.go +++ b/otelcol/configprovider_test.go @@ -18,6 +18,7 @@ import ( "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/confmap/provider/fileprovider" "go.opentelemetry.io/collector/confmap/provider/yamlprovider" + "go.opentelemetry.io/collector/connector/connectortest" "go.opentelemetry.io/collector/exporter/exportertest" "go.opentelemetry.io/collector/extension/extensiontest" "go.opentelemetry.io/collector/processor/processortest" @@ -30,6 +31,7 @@ var configNop = &Config{ Receivers: map[component.ID]component.Config{component.NewID("nop"): receivertest.NewNopFactory().CreateDefaultConfig()}, Processors: map[component.ID]component.Config{component.NewID("nop"): processortest.NewNopFactory().CreateDefaultConfig()}, Exporters: map[component.ID]component.Config{component.NewID("nop"): exportertest.NewNopFactory().CreateDefaultConfig()}, + Connectors: map[component.ID]component.Config{component.NewIDWithName("nop", "con"): connectortest.NewNopFactory().CreateDefaultConfig()}, Extensions: map[component.ID]component.Config{component.NewID("nop"): extensiontest.NewNopFactory().CreateDefaultConfig()}, Service: service.Config{ Extensions: []component.ID{component.NewID("nop")}, @@ -37,7 +39,7 @@ var configNop = &Config{ component.NewID("traces"): { Receivers: []component.ID{component.NewID("nop")}, Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + Exporters: []component.ID{component.NewID("nop"), component.NewIDWithName("nop", "con")}, }, component.NewID("metrics"): { Receivers: []component.ID{component.NewID("nop")}, @@ -45,7 +47,7 @@ var configNop = &Config{ Exporters: []component.ID{component.NewID("nop")}, }, component.NewID("logs"): { - Receivers: []component.ID{component.NewID("nop")}, + Receivers: []component.ID{component.NewID("nop"), component.NewIDWithName("nop", "con")}, Processors: []component.ID{component.NewID("nop")}, Exporters: []component.ID{component.NewID("nop")}, }, diff --git a/otelcol/factories_test.go b/otelcol/factories_test.go index 869a4c01f20..645d59c7db2 100644 --- a/otelcol/factories_test.go +++ b/otelcol/factories_test.go @@ -4,6 +4,8 @@ package otelcol import ( + "go.opentelemetry.io/collector/connector" + "go.opentelemetry.io/collector/connector/connectortest" "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exportertest" "go.opentelemetry.io/collector/extension" @@ -18,6 +20,10 @@ func nopFactories() (Factories, error) { var factories Factories var err error + if factories.Connectors, err = connector.MakeFactoryMap(connectortest.NewNopFactory()); err != nil { + return Factories{}, err + } + if factories.Extensions, err = extension.MakeFactoryMap(extensiontest.NewNopFactory()); err != nil { return Factories{}, err } diff --git a/otelcol/testdata/otelcol-nop.yaml b/otelcol/testdata/otelcol-nop.yaml index 6780b937e13..c83a07c536c 100644 --- a/otelcol/testdata/otelcol-nop.yaml +++ b/otelcol/testdata/otelcol-nop.yaml @@ -10,6 +10,9 @@ exporters: extensions: nop: +connectors: + nop/con: + service: telemetry: metrics: @@ -19,12 +22,12 @@ service: traces: receivers: [nop] processors: [nop] - exporters: [nop] + exporters: [nop, nop/con] metrics: receivers: [nop] processors: [nop] exporters: [nop] logs: - receivers: [nop] + receivers: [nop, nop/con] processors: [nop] exporters: [nop]