Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Maureen <amaka013@gmail.com>
  • Loading branch information
Chinwendu20 committed Oct 15, 2022
1 parent ee02bc7 commit 0f14527
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
48 changes: 45 additions & 3 deletions service/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,39 @@ 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 {
values []string
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
Expand Down Expand Up @@ -71,10 +85,38 @@ 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
}

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
}

0 comments on commit 0f14527

Please sign in to comment.