Skip to content

Commit 4a50b89

Browse files
committed
Added helper functions
1 parent d21cf4a commit 4a50b89

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

otelcol/command.go

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func NewCommand(set CollectorSettings) *cobra.Command {
4242
return rootCmd
4343
}
4444

45+
// Helper function for "make features" commmand for Jaeger
46+
func FeatureCommand(set CollectorSettings) {
47+
featureflags(featuregate.GlobalRegistry())
48+
}
49+
4550
// Puts command line flags from flags into the CollectorSettings, to be used during config resolution.
4651
func updateSettingsUsingFlags(set *CollectorSettings, flags *flag.FlagSet) error {
4752
resolverSet := &set.ConfigProviderSettings.ResolverSettings

otelcol/flags.go

+42
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package otelcol // import "go.opentelemetry.io/collector/otelcol"
66
import (
77
"errors"
88
"flag"
9+
"fmt"
910
"strings"
1011

1112
"go.opentelemetry.io/collector/featuregate"
@@ -15,6 +16,10 @@ const (
1516
configFlag = "config"
1617
)
1718

19+
type flagValue struct {
20+
reg *featuregate.Registry
21+
}
22+
1823
type configFlagValue struct {
1924
values []string
2025
sets []string
@@ -53,6 +58,43 @@ func flags(reg *featuregate.Registry) *flag.FlagSet {
5358
return flagSet
5459
}
5560

61+
// Function to beautify and print the feature flags.
62+
func featureflags(reg *featuregate.Registry) {
63+
f := &flagValue{reg: reg}
64+
if f.reg == nil {
65+
return
66+
}
67+
c := 1
68+
69+
f.reg.VisitAll(func(g *featuregate.Gate) {
70+
str := ""
71+
id := g.ID()
72+
desc := g.Description()
73+
if !g.IsEnabled() {
74+
id = "-" + id
75+
}
76+
str += fmt.Sprint(c) + "." + id + "\n"
77+
str+= "Description: "+desc + "\n"
78+
ref := g.ReferenceURL()
79+
from := g.FromVersion()
80+
to := g.ToVersion()
81+
if(ref != ""){
82+
str+= "ReferenceURL: "+desc + "\n"
83+
}
84+
if(from != "v<nil>"){
85+
str+= "From version: "+from + "\n"
86+
87+
}
88+
if(to != "v<nil>"){
89+
str+= "From version: "+to + "\n"
90+
91+
}
92+
// str += "\n"
93+
c+=1
94+
fmt.Println(str)
95+
})
96+
}
97+
5698
func getConfigFlag(flagSet *flag.FlagSet) []string {
5799
cfv := flagSet.Lookup(configFlag).Value.(*configFlagValue)
58100
return append(cfv.values, cfv.sets...)

0 commit comments

Comments
 (0)