Address code review comments

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2021-01-13 18:49:06 +01:00
parent e1ab2477c0
commit 99e4a4fbae
2 changed files with 4 additions and 3 deletions

View File

@ -90,7 +90,7 @@ func (m *Matcher) Matches(s string) bool {
// openMetricsEscape is similar to the usual string escaping, but more // openMetricsEscape is similar to the usual string escaping, but more
// restricted. It merely replaces a new-line character with '\n', a double-quote // restricted. It merely replaces a new-line character with '\n', a double-quote
// character with '\"', and a backslack with '\\', which is the escaping used by // character with '\"', and a backslash with '\\', which is the escaping used by
// OpenMetrics. // OpenMetrics.
func openMetricsEscape(s string) string { func openMetricsEscape(s string) string {
r := strings.NewReplacer( r := strings.NewReplacer(

View File

@ -38,7 +38,7 @@ var (
// ParseMatchers parses a comma-separated list of Matchers. A leading '{' and/or // ParseMatchers parses a comma-separated list of Matchers. A leading '{' and/or
// a trailing '}' is optional and will be trimmed before further // a trailing '}' is optional and will be trimmed before further
// parsing. Individual Matchers are separated by commas outside of quoted parts // parsing. Individual Matchers are separated by commas outside of quoted parts
// of the input string. Those commas may be sorrounded by whitespace. Parts of the // of the input string. Those commas may be surrounded by whitespace. Parts of the
// string inside unescaped double quotes ('"…"') are considered quoted (and // string inside unescaped double quotes ('"…"') are considered quoted (and
// commas don't act as separators there). If double quotes are escaped with a // commas don't act as separators there). If double quotes are escaped with a
// single backslash ('\"'), they are ignored for the purpose of identifying // single backslash ('\"'), they are ignored for the purpose of identifying
@ -49,10 +49,11 @@ var (
// Examples for valid input strings: // Examples for valid input strings:
// {foo = "bar", dings != "bums", } // {foo = "bar", dings != "bums", }
// foo=bar,dings!=bums // foo=bar,dings!=bums
// foo=bar, dings!=bums
// {quote="She said: \"Hi, ladies! That's gender-neutral…\""} // {quote="She said: \"Hi, ladies! That's gender-neutral…\""}
// statuscode=~"5.." // statuscode=~"5.."
// //
// See ParseMatcher for details how an individual Matcher is parsed. // See ParseMatcher for details on how an individual Matcher is parsed.
func ParseMatchers(s string) ([]*Matcher, error) { func ParseMatchers(s string) ([]*Matcher, error) {
matchers := []*Matcher{} matchers := []*Matcher{}
s = strings.TrimPrefix(s, "{") s = strings.TrimPrefix(s, "{")