Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper functions for printing flags #12094

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow. I am expecting to be able to run otelcol features

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, got it. Adding changes for the subcommand for otelcol features.

I thought that only go run ./cmd/jaeger features was required.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am expecting to be able to run otelcol features

When I try to run otelcol features, it is saying that otelcol is not a command. How to set up the command otelcol and how to bind a function with features

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd cmd/otelcorecol
go run . help

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
31 changes: 31 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,32 @@ 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
}
f.reg.VisitAll(func(g *featuregate.Gate) {
str := ""
id := g.ID()
desc := g.Description()
str += id + "\n"
str+= "Description: "+desc + "\n"
ref := g.ReferenceURL()
if(ref != ""){
str+= "ReferenceURL: "+ref + "\n"
}
if !g.IsEnabled() {
str+= "Default state: " + "On"
} else{
str+= "Default state: " + "Off"
}
str += "\n"
fmt.Println(str)
})
}

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