Skip to content

Commit

Permalink
Created a fix for open-telemetry#4671
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 f0c3ead
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
5 changes: 4 additions & 1 deletion service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package service // import "go.opentelemetry.io/collector/service"

import (
"errors"

"github.com/spf13/cobra"

"go.opentelemetry.io/collector/featuregate"
Expand All @@ -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

Expand Down
52 changes: 49 additions & 3 deletions service/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,41 @@ 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 {
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
Expand Down Expand Up @@ -71,10 +87,40 @@ 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
}

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
}

0 comments on commit f0c3ead

Please sign in to comment.