Skip to content

Commit e2d8b6b

Browse files
authored
Add support for providers in components command (#11900)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR adds support for printing config providers with the `components` command. <!-- Issue number if applicable --> #### Link to tracking issue Related to #11570 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> --------- Signed-off-by: ChrsMark <[email protected]>
1 parent 461a355 commit e2d8b6b

File tree

7 files changed

+59
-1
lines changed

7 files changed

+59
-1
lines changed
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: enhancement
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: Adds support for listing config providers in components command's output
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [11570]
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: [user]

cmd/builder/internal/builder/templates/main.go.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func main() {
4545
DefaultScheme: "{{ .ConfResolver.DefaultURIScheme }}",
4646
{{- end }}
4747
},
48-
},
48+
}, ProviderModules: map[string]string{
49+
{{- range .ConfmapProviders}}
50+
{{.Name}}.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "{{.GoMod}}",
51+
{{- end}}
52+
},
4953
}
5054

5155
if err := run(set); err != nil {

cmd/otelcorecol/main.go

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

otelcol/collector.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ type CollectorSettings struct {
6969
// confmap.Providers watch for configuration changes.
7070
ConfigProviderSettings ConfigProviderSettings
7171

72+
// ProviderModules maps provider schemes to their respective go modules.
73+
ProviderModules map[string]string
74+
7275
// LoggingOptions provides a way to change behavior of zap logging.
7376
LoggingOptions []zap.Option
7477

otelcol/command_components.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ type componentWithStability struct {
2424
Stability map[string]string
2525
}
2626

27+
type componentWithoutStability struct {
28+
Scheme string
29+
Module string
30+
}
31+
2732
type componentsOutput struct {
2833
BuildInfo component.BuildInfo
2934
Receivers []componentWithStability
3035
Processors []componentWithStability
3136
Exporters []componentWithStability
3237
Connectors []componentWithStability
3338
Extensions []componentWithStability
39+
Providers []componentWithoutStability
3440
}
3541

3642
// newComponentsCommand constructs a new components command using the given CollectorSettings.
@@ -109,6 +115,14 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
109115
})
110116
}
111117
components.BuildInfo = set.BuildInfo
118+
119+
for providerScheme, providerModuleModule := range set.ProviderModules {
120+
components.Providers = append(components.Providers, componentWithoutStability{
121+
Scheme: providerScheme,
122+
Module: providerModuleModule,
123+
})
124+
}
125+
112126
yamlData, err := yaml.Marshal(components)
113127
if err != nil {
114128
return err

otelcol/command_components_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ func TestNewBuildSubCommand(t *testing.T) {
2121
BuildInfo: component.NewDefaultBuildInfo(),
2222
Factories: nopFactories,
2323
ConfigProviderSettings: newDefaultConfigProviderSettings(t, []string{filepath.Join("testdata", "otelcol-nop.yaml")}),
24+
ProviderModules: map[string]string{
25+
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
26+
},
2427
}
2528
cmd := NewCommand(set)
2629
cmd.SetArgs([]string{"components"})

otelcol/testdata/components-output.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ extensions:
4141
module: go.opentelemetry.io/collector/extension/extensiontest v1.2.3
4242
stability:
4343
extension: Stable
44+
providers:
45+
- scheme: nop
46+
module: go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3

0 commit comments

Comments
 (0)