Skip to content

Commit

Permalink
Added helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ADI-ROXX committed Jan 15, 2025
1 parent d21cf4a commit 4a50b89
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions otelcol/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func NewCommand(set CollectorSettings) *cobra.Command {
return rootCmd
}

// Helper function for "make features" commmand for Jaeger
func FeatureCommand(set CollectorSettings) {
featureflags(featuregate.GlobalRegistry())
}

// Puts command line flags from flags into the CollectorSettings, to be used during config resolution.
func updateSettingsUsingFlags(set *CollectorSettings, flags *flag.FlagSet) error {
resolverSet := &set.ConfigProviderSettings.ResolverSettings
Expand Down
42 changes: 42 additions & 0 deletions otelcol/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package otelcol // import "go.opentelemetry.io/collector/otelcol"
import (
"errors"
"flag"
"fmt"
"strings"

"go.opentelemetry.io/collector/featuregate"
Expand All @@ -15,6 +16,10 @@ const (
configFlag = "config"
)

type flagValue struct {
reg *featuregate.Registry
}

type configFlagValue struct {
values []string
sets []string
Expand Down Expand Up @@ -53,6 +58,43 @@ func flags(reg *featuregate.Registry) *flag.FlagSet {
return flagSet
}

// Function to beautify and print the feature flags.
func featureflags(reg *featuregate.Registry) {
f := &flagValue{reg: reg}
if f.reg == nil {
return
}
c := 1

f.reg.VisitAll(func(g *featuregate.Gate) {
str := ""
id := g.ID()
desc := g.Description()
if !g.IsEnabled() {
id = "-" + id
}
str += fmt.Sprint(c) + "." + id + "\n"
str+= "Description: "+desc + "\n"
ref := g.ReferenceURL()
from := g.FromVersion()
to := g.ToVersion()
if(ref != ""){
str+= "ReferenceURL: "+desc + "\n"
}
if(from != "v<nil>"){
str+= "From version: "+from + "\n"

}
if(to != "v<nil>"){
str+= "From version: "+to + "\n"

}
// str += "\n"
c+=1
fmt.Println(str)
})
}

func getConfigFlag(flagSet *flag.FlagSet) []string {
cfv := flagSet.Lookup(configFlag).Value.(*configFlagValue)
return append(cfv.values, cfv.sets...)
Expand Down

0 comments on commit 4a50b89

Please sign in to comment.