-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kuma-cp) sanitize metrics for StatsD and Prometheus (#562)
- Loading branch information
1 parent
ed330f1
commit f007f8d
Showing
25 changed files
with
285 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package xds | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var ( | ||
illegalChars = regexp.MustCompile(`[^a-zA-Z_\-0-9]`) | ||
) | ||
|
||
// We need to sanitize metrics in order to not break statsd and prometheus format. | ||
// StatsD only allow [a-zA-Z_\-0-9.] characters, everything else is removed | ||
// Extra dots breaks many regexes that converts statsd metric to prometheus one with tags | ||
func SanitizeMetric(metric string) string { | ||
return illegalChars.ReplaceAllString(metric, "_") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package xds_test | ||
|
||
import ( | ||
"github.com/Kong/kuma/pkg/util/xds" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Metric sanitizer", func() { | ||
It("should sanitize metrics", func() { | ||
// given | ||
metric := "some metric with chars :/_-0123{version=3.0}" | ||
|
||
// when | ||
sanitized := xds.SanitizeMetric(metric) | ||
|
||
// then | ||
Expect(sanitized).To(Equal("some_metric_with_chars____-0123_version_3_0_")) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.