Skip to content

Commit

Permalink
Fix -bind.stats-groups settings
Browse files Browse the repository at this point in the history
Make it possible to completely overwrite the existing stats groups and
also add a verification of duplicated stats groups listing.

This removes the option to repeat the -bind.stats-groups flags.
  • Loading branch information
grobie committed Sep 26, 2016
1 parent cee0943 commit 1df984c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions bind_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,28 @@ func (s *statisticGroups) String() string {

// Set implements flag.Value.
func (s *statisticGroups) Set(value string) error {
*s = []bind.StatisticGroup{}
if len(value) == 0 {
*s = []bind.StatisticGroup{}
return nil
}
var sg bind.StatisticGroup
for _, dt := range strings.Split(value, ",") {
switch dt {
case string(bind.ServerStats):
*s = append(*s, bind.ServerStats)
sg = bind.ServerStats
case string(bind.ViewStats):
*s = append(*s, bind.ViewStats)
sg = bind.ViewStats
case string(bind.TaskStats):
*s = append(*s, bind.TaskStats)
sg = bind.TaskStats
default:
return fmt.Errorf("unknown stats group %q", dt)
}
for _, existing := range *s {
if existing == sg {
return fmt.Errorf("duplicated stats group %q", sg)
}
}
*s = append(*s, sg)
}
return nil
}
Expand Down

0 comments on commit 1df984c

Please sign in to comment.