diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b54742d833..fc1eba0140b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,7 @@ - Add prometheus metric prefix to Collector's own telemetry when using OpenTelemetry for internal telemetry (#6223) - `exporter/logging`: Apply consistent rendering of map values (#6244) - Add support in the confmap.Resolver to expand embedded config URIs inside configuration. (#6276) - +- Added build flag to output components in collector distribution in YAML format (#6322) ### 🧰 Bug fixes 🧰 - Fixed bug where `telemetryInitializer` is not cleaned up when `newService` errors (#6239) diff --git a/service/README.md b/service/README.md index dec61dfdc81..b6e2d2a6d12 100644 --- a/service/README.md +++ b/service/README.md @@ -35,3 +35,30 @@ For more technical details about how configuration is resolved you can read the 2. Merge a `config.yaml` file with the content of a yaml bytes configuration (overwrites the `exporters::logging::loglevel` config) and use the content as the config: `./otelcorecol --config=file:examples/local/otel-config.yaml --config="yaml:exporters::logging::loglevel: info"` + +# How to check components available in a distribution + +Use the flag --build-info. Below is an example: + +```bash + .\otelcol --build-info +``` +Sample output: + +```yaml + +version: 0.62.1-dev +receivers: + - otlp +processors: + - memory_limiter + - batch +exporters: + - logging + - otlp + - otlphttp +extensions: + - memory_ballast + - zpages + +``` diff --git a/service/command.go b/service/command.go index d9f96eab828..21aaa7c9423 100644 --- a/service/command.go +++ b/service/command.go @@ -16,7 +16,6 @@ package service // import "go.opentelemetry.io/collector/service" import ( "errors" - "github.com/spf13/cobra" "go.opentelemetry.io/collector/featuregate" @@ -33,6 +32,10 @@ func NewCommand(set CollectorSettings) *cobra.Command { if err := featuregate.GetRegistry().Apply(gatesList); err != nil { return err } + if BuildFlag { + return getBuildInfo(set) + } + if set.ConfigProvider == nil { var err error diff --git a/service/flags.go b/service/flags.go index 9b638effb19..ce532bc3e51 100644 --- a/service/flags.go +++ b/service/flags.go @@ -17,18 +17,22 @@ package service // import "go.opentelemetry.io/collector/service" import ( "errors" "flag" - "strings" - + "fmt" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/featuregate" + "gopkg.in/yaml.v3" + "strings" ) const ( - configFlag = "config" + configFlag = "config" + buildInfoFlag = "build-info" ) var ( // Command-line flag that control the configuration file. gatesList = featuregate.FlagValue{} + BuildFlag bool ) type configFlagValue struct { @@ -36,6 +40,18 @@ type configFlagValue struct { sets []string } +type componentsOutput struct { + Version string + + Receivers []config.Type + + Processors []config.Type + + Exporters []config.Type + + Extensions []config.Type +} + func (s *configFlagValue) Set(val string) error { s.values = append(s.values, val) return nil @@ -71,6 +87,10 @@ func flags() *flag.FlagSet { "feature-gates", "Comma-delimited list of feature gate identifiers. Prefix with '-' to disable the feature. '+' or no prefix will enable the feature.") + flagSet.BoolVar(&BuildFlag, buildInfoFlag, false, + "Displays list of components available in collector distribution in yaml format", + ) + return flagSet } @@ -78,3 +98,29 @@ func getConfigFlag(flagSet *flag.FlagSet) []string { cfv := flagSet.Lookup(configFlag).Value.(*configFlagValue) return append(cfv.values, cfv.sets...) } + +func getBuildInfo(set CollectorSettings) error { + components := componentsOutput{} + for ext, _ := range set.Factories.Extensions { + components.Extensions = append(components.Extensions, ext) + } + for prs, _ := range set.Factories.Processors { + components.Processors = append(components.Processors, prs) + } + for rcv, _ := range set.Factories.Receivers { + components.Receivers = append(components.Receivers, rcv) + } + for exp, _ := range set.Factories.Exporters { + components.Exporters = append(components.Exporters, exp) + } + components.Version = set.BuildInfo.Version + + yamlData, err := yaml.Marshal(components) + + if err != nil { + return err + } + + fmt.Println(string(yamlData)) + return nil +}