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

Make collector flag functions public to allow collector builders to use them #5130

Closed
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### 💡 Enhancements 💡

- Make flag functions public so they can be used by collector builders (#5130)

### 🧰 Bug fixes 🧰

## v0.48.0 Beta
Expand Down
4 changes: 2 additions & 2 deletions service/collector_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *WindowsService) Execute(args []string, requests <-chan svc.ChangeReques

func (s *WindowsService) start(elog *eventlog.Log, colErrorChannel chan error) error {
// Parse all the flags manually.
if err := flags().Parse(os.Args[1:]); err != nil {
if err := Flags().Parse(os.Args[1:]); err != nil {
return err
}
featuregate.Apply(gatesList)
Expand Down Expand Up @@ -144,7 +144,7 @@ func openEventLog(serviceName string) (*eventlog.Log, error) {

func newWithWindowsEventLogCore(set CollectorSettings, elog *eventlog.Log) (*Collector, error) {
if set.ConfigProvider == nil {
set.ConfigProvider = MustNewDefaultConfigProvider(getConfigFlag(), getSetFlag())
set.ConfigProvider = MustNewDefaultConfigProvider(GetConfigFlag(), GetSetFlag())
}
set.LoggingOptions = append(
set.LoggingOptions,
Expand Down
4 changes: 2 additions & 2 deletions service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewCommand(set CollectorSettings) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
featuregate.Apply(gatesList)
if set.ConfigProvider == nil {
set.ConfigProvider = MustNewDefaultConfigProvider(getConfigFlag(), getSetFlag())
set.ConfigProvider = MustNewDefaultConfigProvider(GetConfigFlag(), GetSetFlag())
}
col, err := New(set)
if err != nil {
Expand All @@ -39,6 +39,6 @@ func NewCommand(set CollectorSettings) *cobra.Command {
},
}

rootCmd.Flags().AddGoFlagSet(flags())
rootCmd.Flags().AddGoFlagSet(Flags())
return rootCmd
}
16 changes: 13 additions & 3 deletions service/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *stringArrayValue) String() string {
return "[" + strings.Join(s.values, ", ") + "]"
}

func flags() *flag.FlagSet {
func Flags() *flag.FlagSet {
flagSet := new(flag.FlagSet)

flagSet.Var(configFlag, "config", "Locations to the config file(s), note that only a"+
Expand All @@ -60,10 +60,20 @@ func flags() *flag.FlagSet {
return flagSet
}

func getConfigFlag() []string {
// ApplyFeatureGateFlags applies feature gates based on the content of the
// --feature-gate flag.
func ApplyFeatureGateFlags() {
featuregate.Apply(gatesList)
}

// GetConfigFlag returns the locations of config files based on the content
// of the --config flag.
func GetConfigFlag() []string {
return configFlag.values
}

func getSetFlag() []string {
// GetSetFlag returns the list of properties based on the content of the --set
// flag.
func GetSetFlag() []string {
return setFlag.values
}