Skip to content

Commit

Permalink
Add a collector flag to list available components.
Browse files Browse the repository at this point in the history
Add a `--list-components` flag to the collector service. This currently
show all the available components, their types and their signal stability
levels. In future, we could also show the Go module and version, but
that would require changes to the builder, so it's omitted for now.

This fixes open-telemetry#5709.

Signed-off-by: James Peach <jpeach@cloudflare.com>
  • Loading branch information
jpeach committed Jul 20, 2022
1 parent 389c047 commit 3611e9f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Expose `pcommon.NewSliceFromRaw` function (#5679)
- `loggingexporter`: create the exporter's logger from the service's logger (#5677)
- Add `otelcol_exporter_queue_capacity` metrics show the collector's exporter queue capacity (#5475)
- Add the Collector flag `--list-components` flag to show the available components. (#5709)

### 🧰 Bug fixes 🧰

Expand Down
5 changes: 5 additions & 0 deletions config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const (
LogsDataType DataType = "logs"
)

// AllDataTypes is a slice of all possible DataType values.
var AllDataTypes = []DataType{
TracesDataType, MetricsDataType, LogsDataType,
}

func unmarshal(componentSection *confmap.Conf, intoCfg interface{}) error {
if cu, ok := intoCfg.(Unmarshallable); ok {
return cu.Unmarshal(componentSection)
Expand Down
48 changes: 48 additions & 0 deletions service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,57 @@
package service // import "go.opentelemetry.io/collector/service"

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/converter/overwritepropertiesconverter"
"go.opentelemetry.io/collector/service/featuregate"
)

func printComponentSet(set CollectorSettings) {
printFactory := func(f component.Factory) {
var stability []string

for _, t := range config.AllDataTypes {
if s := f.StabilityLevel(t); s != component.StabilityLevelUndefined {
stability = append(stability, fmt.Sprintf("%s: %s", t, s))
}
}

if len(stability) == 0 {
fmt.Printf("\t%s\n", f.Type())
} else {
fmt.Printf("\t%s (%s)\n", f.Type(), strings.Join(stability, ", "))
}
}

fmt.Printf("exporters:\n")
for _, e := range set.Factories.Exporters {
printFactory(e)
}

fmt.Printf("receivers:\n")
for _, r := range set.Factories.Receivers {
printFactory(r)
}

fmt.Printf("processors:\n")
for _, p := range set.Factories.Processors {
printFactory(p)
}

fmt.Printf("extensions:\n")
for _, e := range set.Factories.Extensions {
printFactory(e)
}
}

// NewCommand constructs a new cobra.Command using the given CollectorSettings.
func NewCommand(set CollectorSettings) *cobra.Command {
flagSet := flags()
Expand All @@ -30,6 +74,10 @@ func NewCommand(set CollectorSettings) *cobra.Command {
Version: set.BuildInfo.Version,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if getListComponentsFlag(flagSet) {
printComponentSet(set)
os.Exit(0)
}
featuregate.GetRegistry().Apply(gatesList)
if set.ConfigProvider == nil {
var err error
Expand Down
7 changes: 7 additions & 0 deletions service/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ 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.Bool("list-components", false,
"List the available components and exit.")

return flagSet
}

Expand All @@ -70,3 +73,7 @@ func getConfigFlag(flagSet *flag.FlagSet) []string {
func getSetFlag(flagSet *flag.FlagSet) []string {
return flagSet.Lookup(setFlag).Value.(*stringArrayValue).values
}

func getListComponentsFlag(flagSet *flag.FlagSet) bool {
return flagSet.Lookup("list-components").Value.String() == "true"
}

0 comments on commit 3611e9f

Please sign in to comment.