diff --git a/service/README.md b/service/README.md index dec61dfdc81..2618860302b 100644 --- a/service/README.md +++ b/service/README.md @@ -35,3 +35,28 @@ 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 + + receivers: + - otlp +processors: + - batch + - memory_limiter +exporters: + - logging + - otlp + - otlphttp +extensions: + - memory_ballast + - zpages +``` diff --git a/service/command.go b/service/command.go index d9f96eab828..f160a7f5986 100644 --- a/service/command.go +++ b/service/command.go @@ -33,6 +33,10 @@ func NewCommand(set CollectorSettings) *cobra.Command { if err := featuregate.GetRegistry().Apply(gatesList); err != nil { return err } + if BuildFlag { + return getBuildInfo(flagSet, set) + } + if set.ConfigProvider == nil { var err error diff --git a/service/flags.go b/service/flags.go index 9b638effb19..da98410fb55 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,16 @@ type configFlagValue struct { sets []string } +type componentsOutput struct { + 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 +85,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, true, + "Displays list of components available in collector distribution in yaml format", + ) + return flagSet } @@ -78,3 +96,27 @@ func getConfigFlag(flagSet *flag.FlagSet) []string { cfv := flagSet.Lookup(configFlag).Value.(*configFlagValue) return append(cfv.values, cfv.sets...) } + +func getBuildInfo(flagSet *flag.FlagSet, 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) + } + yamlData, err := yaml.Marshal(components) + + if err != nil { + return err + } + + fmt.Println(string(yamlData)) + return nil +}