Skip to content

Commit

Permalink
Merge pull request #471 from grafana/support-storage-aggregation-patt…
Browse files Browse the repository at this point in the history
…erns-special-chars

Support storage aggregation patterns special chars
  • Loading branch information
Dieterbe committed Jul 7, 2021
2 parents 9b95fae + 272215f commit acff7f3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/gorilla/context v0.0.0-20141217160251-215affda49ad // indirect
github.com/gorilla/handlers v1.4.0
github.com/gorilla/mux v0.0.0-20140624184626-14cafe285133
github.com/grafana/configparser v0.0.0-20210622142741-3e3967fd8d20
github.com/grafana/configparser v0.0.0-20210707122942-2593eb86a3ee
github.com/grafana/metrictank v1.0.1-0.20210114150051-52835b9a8775
github.com/jpillora/backoff v0.0.0-20160414055204-0496a6c14df0
github.com/kisielk/og-rek v0.0.0-20170405223746-ec792bc6e6aa
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ github.com/gorilla/mux v0.0.0-20140624184626-14cafe285133 h1:ukbzVQxXffKnAteyOe2
github.com/gorilla/mux v0.0.0-20140624184626-14cafe285133/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/grafana/configparser v0.0.0-20210622142741-3e3967fd8d20 h1:vU/muwCTymcNiJZvuYzPtebHNkDPH8FF42QWBGMO3ms=
github.com/grafana/configparser v0.0.0-20210622142741-3e3967fd8d20/go.mod h1:5kq854/YXuu4gJm0A2hON7r5IeAKTpap20ARcCZSugw=
github.com/grafana/configparser v0.0.0-20210707122942-2593eb86a3ee h1:5j5kbjPdpun9I6taPXXvQnjUYaHxHg4Akgrh9JGB+4k=
github.com/grafana/configparser v0.0.0-20210707122942-2593eb86a3ee/go.mod h1:5kq854/YXuu4gJm0A2hON7r5IeAKTpap20ARcCZSugw=
github.com/grafana/metrictank v1.0.1-0.20210114150051-52835b9a8775 h1:5DryQe90TlOk9FiaS2fAShAQAkzy4OlSs0DS1LQU9rI=
github.com/grafana/metrictank v1.0.1-0.20210114150051-52835b9a8775/go.mod h1:+W7kcYMB3XFMCQdmZSrXvqb8KCE84tQMaijapcRbptE=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
Expand Down
42 changes: 34 additions & 8 deletions pkg/mt-conf/aggregations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestReadAggregations(t *testing.T) {
{
title: "commented out pattern is still missing",
in: `[foo]
;pattern = foo.*`,
#pattern = foo.*`,
expErr: true,
},
{
Expand Down Expand Up @@ -91,31 +91,48 @@ func TestReadAggregations(t *testing.T) {
},
{
title: "lots of comments",
in: `;[this is not a section]
in: `#[this is not a section]
[foo] # [commented]
pattern = fo#ooo;.* # another comment here. note that literal ; and # are allowed
; pattern = this-should-be-ignored
# pattern = this-should-be-ignored
xFilesFactor = 0.8 # comment
;xFilesFactor = 0.9
;aggregationMethod = min,avg
#xFilesFactor = 0.9
#aggregationMethod = min,avg
#aggregationMethod = min,avg
aggregationMethod = max
;aggregationMethod = min,avg
#aggregationMethod = min,avg
; and a final comment on its own line`,
# and a final comment on its own line`,
expErr: false,
expAgg: Aggregations{
Data: []Aggregation{
{
Name: "foo",
Pattern: regexp.MustCompile("fo#ooo;.*"),
Pattern: regexp.MustCompile("fo"),
XFilesFactor: 0.8,
AggregationMethod: []Method{Max},
},
},
DefaultAggregation: defaultAggregation(),
},
},
{
title: "pattern with special characters",
in: `[foo]
pattern = [^ab](x|y)\p{Greek}.*,:;!@%&=+-_/?<>"'~$#ab
`,
expErr: false,
expAgg: Aggregations{
Data: []Aggregation{
{
Name: "foo",
Pattern: regexp.MustCompile(`[^ab](x|y)\p{Greek}.*,:;!@%&=+-_/?<>"'~$`),
XFilesFactor: 0.5,
AggregationMethod: []Method{Avg},
},
},
DefaultAggregation: defaultAggregation(),
},
},
{
title: "grafanacloud_default",
in: `[default]
Expand Down Expand Up @@ -336,6 +353,10 @@ aggregationMethod = avg,min,max
[fancy-x-y-z%%$]
xFilesFactor = 0.9
pattern = [^ab](x|y)\p{Greek}.*,:;!@%&=+-_/?<>"'~$#ab
aggregationMethod = min
# another comment
Expand All @@ -355,6 +376,11 @@ pattern = ^patt2.*$
xFilesFactor = 0.2
aggregationMethod = avg,min,max
[fancy-x-y-z%%$]
pattern = [^ab](x|y)\p{Greek}.*,:;!@%&=+-_/?<>"'~$
xFilesFactor = 0.9
aggregationMethod = min
[hello]
pattern = .*
xFilesFactor = 0.5
Expand Down

0 comments on commit acff7f3

Please sign in to comment.