From 8313bd85f21d3593ce263849c084e5cd514ee421 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 28 Oct 2019 16:38:07 +0200 Subject: [PATCH 1/4] Fix the system-tag cli help default values after #1148 --- cmd/options.go | 4 ++-- stats/system_tag.go | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/options.go b/cmd/options.go index 2485f4fda28..dd88971e42f 100644 --- a/cmd/options.go +++ b/cmd/options.go @@ -68,8 +68,8 @@ func optionFlagSet() *pflag.FlagSet { // system-tags must have a default value, but we can't specify it here, otherwiese, it will always override others. // set it to nil here, and add the default in applyDefault() instead. systemTagsCliHelpText := fmt.Sprintf( - "only include these system tags in metrics (default %s)", - stats.DefaultSystemTagSet, + "only include these system tags in metrics (default %q)", + stats.DefaultSystemTagSet.SetString(), ) flags.StringSlice("system-tags", nil, systemTagsCliHelpText) flags.StringSlice("tag", nil, "add a `tag` to be applied to all samples, as `[name]=[value]`") diff --git a/stats/system_tag.go b/stats/system_tag.go index ccc08505dc2..830c3d58b58 100644 --- a/stats/system_tag.go +++ b/stats/system_tag.go @@ -3,6 +3,7 @@ package stats import ( "bytes" "encoding/json" + "sort" "strings" ) @@ -60,7 +61,7 @@ func (i *SystemTagSet) Has(tag SystemTagSet) bool { } // Map returns the TagSet with current value from SystemTagSet -func (i *SystemTagSet) Map() TagSet { +func (i SystemTagSet) Map() TagSet { m := TagSet{} for _, tag := range SystemTagSetValues() { if i.Has(tag) { @@ -70,6 +71,17 @@ func (i *SystemTagSet) Map() TagSet { return m } +// SetString is returns comma separeted list of the string representation of all values in the set +func (i SystemTagSet) SetString() string { + m := i.Map() + var keys = make([]string, 0, len(m)) + for key := range m { + keys = append(keys, key) + } + sort.Strings(keys) + return strings.Join(keys, ",") +} + // ToSystemTagSet converts list of tags to SystemTagSet // TODO: emit error instead of discarding invalid values. func ToSystemTagSet(tags []string) *SystemTagSet { From bea5352dda1a4773e4bae196e0c21d187f6c9785 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 28 Oct 2019 16:47:08 +0200 Subject: [PATCH 2/4] Typo and optimization --- stats/system_tag.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stats/system_tag.go b/stats/system_tag.go index 830c3d58b58..b1aa5c1eb90 100644 --- a/stats/system_tag.go +++ b/stats/system_tag.go @@ -71,12 +71,13 @@ func (i SystemTagSet) Map() TagSet { return m } -// SetString is returns comma separeted list of the string representation of all values in the set +// SetString returns comma separeted list of the string representation of all values in the set func (i SystemTagSet) SetString() string { - m := i.Map() - var keys = make([]string, 0, len(m)) - for key := range m { - keys = append(keys, key) + var keys []string + for _, tag := range SystemTagSetValues() { + if i.Has(tag) { + keys = append(keys, tag.String()) + } } sort.Strings(keys) return strings.Join(keys, ",") From 86916d07932f7c6499b671a6f1271538ffc1eecc Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 28 Oct 2019 16:47:53 +0200 Subject: [PATCH 3/4] Don't sort the keys in SetString as this was added because of maps being unordered --- stats/system_tag.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/stats/system_tag.go b/stats/system_tag.go index b1aa5c1eb90..6720442bc1f 100644 --- a/stats/system_tag.go +++ b/stats/system_tag.go @@ -3,7 +3,6 @@ package stats import ( "bytes" "encoding/json" - "sort" "strings" ) @@ -79,7 +78,6 @@ func (i SystemTagSet) SetString() string { keys = append(keys, tag.String()) } } - sort.Strings(keys) return strings.Join(keys, ",") } From 3dae038fc15c0455568f258ccb50f6432d6614cf Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Tue, 29 Oct 2019 07:41:20 +0200 Subject: [PATCH 4/4] typo --- stats/system_tag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stats/system_tag.go b/stats/system_tag.go index 6720442bc1f..fac1d0dda4d 100644 --- a/stats/system_tag.go +++ b/stats/system_tag.go @@ -70,7 +70,7 @@ func (i SystemTagSet) Map() TagSet { return m } -// SetString returns comma separeted list of the string representation of all values in the set +// SetString returns comma separated list of the string representation of all values in the set func (i SystemTagSet) SetString() string { var keys []string for _, tag := range SystemTagSetValues() {