Skip to content

Commit

Permalink
Added build-info flag, fix open-telemetry#4671
Browse files Browse the repository at this point in the history
Signed-off-by: Maureen <[email protected]>
  • Loading branch information
Chinwendu20 committed Oct 15, 2022
1 parent ee02bc7 commit 73be175
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
25 changes: 25 additions & 0 deletions service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
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 73be175

Please sign in to comment.