From 78de4b11db89179bd7fcdad636a2eb6845f1613c Mon Sep 17 00:00:00 2001 From: Jens Bissinger Date: Wed, 20 Sep 2017 12:27:12 +0200 Subject: [PATCH] Fix matching empty statsd metric components --- mapper.go | 2 +- mapper_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/mapper.go b/mapper.go index ef98d6c..d2559e0 100644 --- a/mapper.go +++ b/mapper.go @@ -97,7 +97,7 @@ func (m *metricMapper) initFromYAMLString(fileContents string) error { // Translate the glob-style metric match line into a proper regex that we // can use to match metrics later on. metricRe := strings.Replace(currentMapping.Match, ".", "\\.", -1) - metricRe = strings.Replace(metricRe, "*", "([^.]+)", -1) + metricRe = strings.Replace(metricRe, "*", "([^.]*)", -1) currentMapping.regex = regexp.MustCompile("^" + metricRe + "$") } else { currentMapping.regex = regexp.MustCompile(currentMapping.Match) diff --git a/mapper_test.go b/mapper_test.go index 9e4b2ee..72bb343 100644 --- a/mapper_test.go +++ b/mapper_test.go @@ -43,6 +43,21 @@ mappings: action: "$2" result: "$3" job: "test_dispatcher" +- match: request_time.*.*.*.*.*.*.*.*.*.*.*.* + labels: + name: "tyk_http_request" + method_and_path: "${1}" + response_code: "${2}" + apikey: "${3}" + apiversion: "${4}" + apiname: "${5}" + apiid: "${6}" + ipv4_t1: "${7}" + ipv4_t2: "${8}" + ipv4_t3: "${9}" + ipv4_t4: "${10}" + orgid: "${11}" + oauthid: "${12}" - match: "*.*" labels: name: "catchall" @@ -75,6 +90,21 @@ mappings: "result": "succeeded", "job": "test_dispatcher", }, + "request_time.get/threads/1/posts.200.00000000.nonversioned.discussions.a11bbcdf0ac64ec243658dc64b7100fb.172.20.0.1.12ba97b7eaa1a50001000001.": map[string]string{ + "name": "tyk_http_request", + "method_and_path": "get/threads/1/posts", + "response_code": "200", + "apikey": "00000000", + "apiversion": "nonversioned", + "apiname": "discussions", + "apiid": "a11bbcdf0ac64ec243658dc64b7100fb", + "ipv4_t1": "172", + "ipv4_t2": "20", + "ipv4_t3": "0", + "ipv4_t4": "1", + "orgid": "12ba97b7eaa1a50001000001", + "oauthid": "", + }, "foo.bar": map[string]string{ "name": "catchall", "first": "foo",