2015-02-18 21:40:55 +00:00
|
|
|
// Copyright 2013 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2013-07-05 17:31:53 +00:00
|
|
|
//
|
2015-02-18 21:40:55 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2013-07-05 17:31:53 +00:00
|
|
|
|
2018-08-10 12:28:38 +00:00
|
|
|
package mapper
|
2013-07-05 17:31:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-12-13 13:53:40 +00:00
|
|
|
"time"
|
2021-01-28 18:37:56 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2021-02-07 00:22:29 +00:00
|
|
|
|
2021-02-07 04:27:11 +00:00
|
|
|
"github.com/prometheus/statsd_exporter/pkg/mappercache/lru"
|
2021-02-19 16:17:27 +00:00
|
|
|
"github.com/prometheus/statsd_exporter/pkg/mappercache/randomreplacement"
|
2013-07-05 17:31:53 +00:00
|
|
|
)
|
|
|
|
|
2019-06-08 00:04:33 +00:00
|
|
|
type mappings []struct {
|
|
|
|
statsdMetric string
|
|
|
|
name string
|
|
|
|
labels map[string]string
|
|
|
|
quantiles []metricObjective
|
|
|
|
notPresent bool
|
|
|
|
ttl time.Duration
|
|
|
|
metricType MetricType
|
2020-01-27 14:50:34 +00:00
|
|
|
maxAge time.Duration
|
|
|
|
ageBuckets uint32
|
|
|
|
bufCap uint32
|
2021-01-28 18:37:56 +00:00
|
|
|
buckets []float64
|
2017-11-13 12:21:29 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 16:17:27 +00:00
|
|
|
func newTestMapperWithCache(cacheType string, size int) *MetricMapper {
|
|
|
|
mapper := MetricMapper{}
|
|
|
|
var cache MetricMapperCache
|
|
|
|
switch cacheType {
|
|
|
|
case "lru":
|
|
|
|
cache, _ = lru.NewMetricMapperLRUCache(mapper.Registerer, size)
|
|
|
|
case "random":
|
|
|
|
cache, _ = randomreplacement.NewMetricMapperRRCache(mapper.Registerer, size)
|
|
|
|
case "none":
|
|
|
|
return &mapper
|
|
|
|
}
|
|
|
|
mapper.UseCache(cache)
|
|
|
|
return &mapper
|
|
|
|
}
|
|
|
|
|
2017-07-27 20:58:10 +00:00
|
|
|
func TestMetricMapperYAML(t *testing.T) {
|
|
|
|
scenarios := []struct {
|
2021-01-28 18:37:56 +00:00
|
|
|
testName string
|
2017-07-27 20:58:10 +00:00
|
|
|
config string
|
|
|
|
configBad bool
|
2017-11-13 12:21:29 +00:00
|
|
|
mappings mappings
|
2017-07-27 20:58:10 +00:00
|
|
|
}{
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Empty config",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config with several mapping definitions",
|
2017-07-27 20:58:10 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.dispatcher.*.*.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "dispatch_events"
|
2021-06-17 16:19:52 +00:00
|
|
|
labels:
|
2017-07-27 20:58:10 +00:00
|
|
|
processor: "$1"
|
|
|
|
action: "$2"
|
|
|
|
result: "$3"
|
|
|
|
job: "test_dispatcher"
|
|
|
|
- match: test.my-dispatch-host01.name.dispatcher.*.*.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "host_dispatch_events"
|
2017-07-27 20:58:10 +00:00
|
|
|
labels:
|
|
|
|
processor: "$1"
|
|
|
|
action: "$2"
|
|
|
|
result: "$3"
|
|
|
|
job: "test_dispatcher"
|
2017-09-20 10:27:12 +00:00
|
|
|
- match: request_time.*.*.*.*.*.*.*.*.*.*.*.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "tyk_http_request"
|
2017-09-20 10:27:12 +00:00
|
|
|
labels:
|
|
|
|
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}"
|
2017-07-27 20:58:10 +00:00
|
|
|
- match: "*.*"
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "catchall"
|
2017-07-27 20:58:10 +00:00
|
|
|
labels:
|
|
|
|
first: "$1"
|
|
|
|
second: "$2"
|
|
|
|
third: "$3"
|
|
|
|
job: "$1-$2-$3"
|
2017-09-29 07:57:17 +00:00
|
|
|
- match: (.*)\.(.*)-(.*)\.(.*)
|
|
|
|
match_type: regex
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "proxy_requests_total"
|
2017-09-29 07:57:17 +00:00
|
|
|
labels:
|
|
|
|
job: "$1"
|
|
|
|
protocol: "$2"
|
|
|
|
endpoint: "$3"
|
|
|
|
result: "$4"
|
|
|
|
|
2017-07-27 20:58:10 +00:00
|
|
|
`,
|
2017-11-13 12:21:29 +00:00
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.dispatcher.FooProcessor.send.succeeded",
|
|
|
|
name: "dispatch_events",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"processor": "FooProcessor",
|
|
|
|
"action": "send",
|
|
|
|
"result": "succeeded",
|
|
|
|
"job": "test_dispatcher",
|
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.my-dispatch-host01.name.dispatcher.FooProcessor.send.succeeded",
|
|
|
|
name: "host_dispatch_events",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"processor": "FooProcessor",
|
|
|
|
"action": "send",
|
|
|
|
"result": "succeeded",
|
|
|
|
"job": "test_dispatcher",
|
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "request_time.get/threads/1/posts.200.00000000.nonversioned.discussions.a11bbcdf0ac64ec243658dc64b7100fb.172.20.0.1.12ba97b7eaa1a50001000001.",
|
|
|
|
name: "tyk_http_request",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"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": "",
|
|
|
|
},
|
2017-09-20 10:27:12 +00:00
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "foo.bar",
|
|
|
|
name: "catchall",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"first": "foo",
|
|
|
|
"second": "bar",
|
|
|
|
"third": "",
|
|
|
|
"job": "foo-bar-",
|
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "foo.bar.baz",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "proxy-1.http-goober.success",
|
|
|
|
name: "proxy_requests_total",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"job": "proxy-1",
|
|
|
|
"protocol": "http",
|
|
|
|
"endpoint": "goober",
|
|
|
|
"result": "success",
|
|
|
|
},
|
2017-09-29 07:57:17 +00:00
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
},
|
|
|
|
},
|
2018-09-13 01:18:12 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with backtracking",
|
2018-09-13 01:18:12 +00:00
|
|
|
config: `
|
2018-09-13 18:46:41 +00:00
|
|
|
defaults:
|
|
|
|
glob_disable_ordering: true
|
2018-09-13 01:18:12 +00:00
|
|
|
mappings:
|
2018-09-13 18:46:41 +00:00
|
|
|
- match: backtrack.*.bbb
|
2018-09-13 01:18:12 +00:00
|
|
|
name: "testb"
|
|
|
|
labels:
|
|
|
|
label: "${1}_foo"
|
2018-09-13 18:46:41 +00:00
|
|
|
- match: backtrack.justatest.aaa
|
2018-09-13 01:18:12 +00:00
|
|
|
name: "testa"
|
|
|
|
labels:
|
|
|
|
label: "${1}_foo"
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "backtrack.good.bbb",
|
|
|
|
name: "testb",
|
2018-09-13 01:18:12 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "good_foo",
|
|
|
|
},
|
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "backtrack.justatest.bbb",
|
|
|
|
name: "testb",
|
2018-09-13 01:18:12 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "justatest_foo",
|
|
|
|
},
|
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "backtrack.justatest.aaa",
|
|
|
|
name: "testa",
|
2018-12-05 19:25:43 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "_foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//Config with backtracking, the non-matched rule has star(s)
|
|
|
|
// A metric like full.name.anothertest will first match full.name.* and then tries
|
|
|
|
// to match *.dummy.* and then failed.
|
|
|
|
// This test case makes sure the captures in the non-matched later rule
|
|
|
|
// doesn't affect the captures in the first matched rule.
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with backtracking, the non-matched rule has star(s)",
|
2018-12-05 19:25:43 +00:00
|
|
|
config: `
|
|
|
|
defaults:
|
|
|
|
glob_disable_ordering: false
|
|
|
|
mappings:
|
|
|
|
- match: '*.dummy.*'
|
|
|
|
name: metric_one
|
|
|
|
labels:
|
|
|
|
system: $1
|
|
|
|
attribute: $2
|
|
|
|
- match: 'full.name.*'
|
|
|
|
name: metric_two
|
|
|
|
labels:
|
|
|
|
system: static
|
|
|
|
attribute: $1
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "whatever.dummy.test",
|
|
|
|
name: "metric_one",
|
2018-12-05 19:25:43 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"system": "whatever",
|
|
|
|
"attribute": "test",
|
|
|
|
},
|
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "full.name.anothertest",
|
|
|
|
name: "metric_two",
|
2018-12-05 19:25:43 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"system": "static",
|
|
|
|
"attribute": "anothertest",
|
|
|
|
},
|
|
|
|
},
|
2018-09-13 01:18:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with super sets, disables ordering",
|
2018-09-13 01:18:12 +00:00
|
|
|
config: `
|
2018-09-13 18:46:41 +00:00
|
|
|
defaults:
|
|
|
|
glob_disable_ordering: true
|
2018-09-13 01:18:12 +00:00
|
|
|
mappings:
|
2018-09-13 18:46:41 +00:00
|
|
|
- match: noorder.*.*
|
|
|
|
name: "testa"
|
|
|
|
labels:
|
|
|
|
label: "${1}_foo"
|
|
|
|
- match: noorder.*.bbb
|
2018-09-13 01:18:12 +00:00
|
|
|
name: "testb"
|
|
|
|
labels:
|
|
|
|
label: "${1}_foo"
|
2018-09-13 18:46:41 +00:00
|
|
|
- match: noorder.ccc.bbb
|
|
|
|
name: "testc"
|
|
|
|
labels:
|
|
|
|
label: "ccc_foo"
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "noorder.good.bbb",
|
|
|
|
name: "testb",
|
2018-09-13 18:46:41 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "good_foo",
|
|
|
|
},
|
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "noorder.ccc.bbb",
|
|
|
|
name: "testc",
|
2018-09-13 18:46:41 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "ccc_foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with super sets, keeps ordering",
|
2018-09-13 18:46:41 +00:00
|
|
|
config: `
|
|
|
|
defaults:
|
|
|
|
glob_disable_ordering: false
|
|
|
|
mappings:
|
|
|
|
- match: order.*.*
|
2018-09-13 01:18:12 +00:00
|
|
|
name: "testa"
|
|
|
|
labels:
|
|
|
|
label: "${1}_foo"
|
2018-09-13 18:46:41 +00:00
|
|
|
- match: order.*.bbb
|
|
|
|
name: "testb"
|
|
|
|
labels:
|
|
|
|
label: "${1}_foo"
|
2018-09-13 01:18:12 +00:00
|
|
|
`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "order.good.bbb",
|
|
|
|
name: "testa",
|
2018-09-13 01:18:12 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "good_foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with bad regex reference",
|
2017-07-27 20:58:10 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "name"
|
2017-07-27 20:58:10 +00:00
|
|
|
labels:
|
|
|
|
label: "$1_foo"
|
|
|
|
`,
|
2017-11-13 12:21:29 +00:00
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.a",
|
|
|
|
name: "name",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "",
|
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with good regex reference",
|
2017-07-27 20:58:10 +00:00
|
|
|
config: `
|
|
|
|
mappings:
|
|
|
|
- match: test.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "name"
|
2017-07-27 20:58:10 +00:00
|
|
|
labels:
|
|
|
|
label: "${1}_foo"
|
|
|
|
`,
|
2017-11-13 12:21:29 +00:00
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.a",
|
|
|
|
name: "name",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "a_foo",
|
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-07 16:13:35 +00:00
|
|
|
{
|
2021-03-26 16:54:29 +00:00
|
|
|
testName: "Match metric segment with a number",
|
2021-02-07 16:13:35 +00:00
|
|
|
config: `
|
|
|
|
mappings:
|
|
|
|
- match: test.99.myapp.*
|
|
|
|
name: "name"
|
|
|
|
labels:
|
|
|
|
label: "${1}_foo"
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.99.myapp.create",
|
|
|
|
name: "name",
|
|
|
|
labels: map[string]string{
|
|
|
|
"label": "create_foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-26 16:54:29 +00:00
|
|
|
testName: "Match metric segment starting with a number",
|
|
|
|
config: `
|
|
|
|
mappings:
|
|
|
|
- match: test.99test.myapp.*
|
|
|
|
name: "name"
|
|
|
|
labels:
|
|
|
|
label: "${1}_foo"
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.99test.myapp.create",
|
|
|
|
name: "name",
|
|
|
|
labels: map[string]string{
|
|
|
|
"label": "create_foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Match metric segment with a number #328 example",
|
2021-02-07 16:13:35 +00:00
|
|
|
config: `
|
|
|
|
mappings:
|
|
|
|
- match: kafka.server.FetcherStats.brokerHost.hostname.brokerPort.9092.clientId.ReplicaFetcherThread-0-1.BytesPerSec.1MinuteRate.gauge
|
|
|
|
name: "example_name"
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "kafka.server.FetcherStats.brokerHost.hostname.brokerPort.9092.clientId.ReplicaFetcherThread-0-1.BytesPerSec.1MinuteRate.gauge",
|
|
|
|
name: "example_name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-26 16:54:29 +00:00
|
|
|
{
|
|
|
|
testName: "Single segment match",
|
|
|
|
config: `
|
|
|
|
mappings:
|
|
|
|
- match: '*'
|
|
|
|
name: single_segment
|
|
|
|
labels:
|
|
|
|
label: "${1}"
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test",
|
|
|
|
name: "single_segment",
|
|
|
|
labels: map[string]string{
|
|
|
|
"label": "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with bad metric line",
|
2017-07-27 20:58:10 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
2021-06-17 16:19:52 +00:00
|
|
|
- match: bad!!metric-line.*.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
2017-07-27 20:58:10 +00:00
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
2021-06-17 16:19:52 +00:00
|
|
|
{
|
|
|
|
testName: "Config with multiple dashes in metric name",
|
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: "foo--bar.*"
|
|
|
|
name: "foo_bar_${1}"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "foo--bar.count",
|
|
|
|
name: "foo_bar_count",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-01-16 13:16:15 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with dynamic metric name",
|
2018-01-16 13:16:15 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test1.*.*
|
|
|
|
name: "$1"
|
|
|
|
labels: {}
|
|
|
|
- match: test2.*.*
|
|
|
|
name: "${1}_$2"
|
|
|
|
labels: {}
|
|
|
|
- match: test3\.(\w+)\.(\w+)
|
|
|
|
match_type: regex
|
|
|
|
name: "${2}_$1"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test1.total_requests.count",
|
|
|
|
name: "total_requests",
|
2018-01-16 13:16:15 +00:00
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test2.total_requests.count",
|
|
|
|
name: "total_requests_count",
|
2018-01-16 13:16:15 +00:00
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test3.total_requests.count",
|
|
|
|
name: "count_total_requests",
|
2018-01-16 13:16:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with bad metric name",
|
2017-07-27 20:58:10 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "0foo"
|
|
|
|
labels: {}
|
2017-07-27 20:58:10 +00:00
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with no metric name",
|
2017-07-27 20:58:10 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
labels:
|
|
|
|
this: "$1"
|
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with no mappings",
|
2017-07-27 20:58:10 +00:00
|
|
|
config: ``,
|
2017-11-13 12:21:29 +00:00
|
|
|
mappings: mappings{},
|
2017-07-27 20:58:10 +00:00
|
|
|
},
|
2017-11-10 20:01:15 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config without a trailing newline",
|
2017-11-10 20:01:15 +00:00
|
|
|
config: `mappings:
|
|
|
|
- match: test.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "name"
|
2017-11-10 20:01:15 +00:00
|
|
|
labels:
|
|
|
|
label: "${1}_foo"`,
|
2017-11-13 12:21:29 +00:00
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.a",
|
|
|
|
name: "name",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "a_foo",
|
|
|
|
},
|
2017-11-10 20:01:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-11-10 20:01:57 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with an improperly escaped *",
|
2017-11-10 20:01:57 +00:00
|
|
|
config: `
|
|
|
|
mappings:
|
|
|
|
- match: *.test.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "name"
|
2017-11-10 20:01:57 +00:00
|
|
|
labels:
|
|
|
|
label: "${1}_foo"`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with a properly escaped *",
|
2017-11-10 20:01:57 +00:00
|
|
|
config: `
|
|
|
|
mappings:
|
|
|
|
- match: "*.test.*"
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "name"
|
2017-11-10 20:01:57 +00:00
|
|
|
labels:
|
|
|
|
label: "${2}_foo"`,
|
2017-11-13 12:21:29 +00:00
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "foo.test.a",
|
|
|
|
name: "name",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"label": "a_foo",
|
|
|
|
},
|
2017-11-10 20:01:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-07-27 21:01:12 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with good observer type",
|
2017-07-27 21:01:12 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
2020-06-15 21:26:20 +00:00
|
|
|
observer_type: summary
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
2020-06-15 22:41:16 +00:00
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
- quantile: 0.7
|
|
|
|
error: 0.002
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.42, Error: 0.04},
|
|
|
|
{Quantile: 0.7, Error: 0.002},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with good observer type and unused timer type",
|
2020-06-15 22:41:16 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: summary
|
|
|
|
timer_type: histogram
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
2018-08-09 02:41:41 +00:00
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
- quantile: 0.7
|
|
|
|
error: 0.002
|
2017-07-27 21:01:12 +00:00
|
|
|
`,
|
2017-11-13 12:21:29 +00:00
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
2018-08-09 02:41:41 +00:00
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.42, Error: 0.04},
|
|
|
|
{Quantile: 0.7, Error: 0.002},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with good observertype and no defaults",
|
2018-08-09 02:41:41 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test1.*.*
|
2020-06-15 21:26:20 +00:00
|
|
|
observer_type: summary
|
2018-08-09 02:41:41 +00:00
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
2020-06-15 22:41:16 +00:00
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test1.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.5, Error: 0.05},
|
|
|
|
{Quantile: 0.9, Error: 0.01},
|
|
|
|
{Quantile: 0.99, Error: 0.001},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with good deprecated timer type",
|
2020-06-15 22:41:16 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test1.*.*
|
|
|
|
timer_type: summary
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
2018-08-09 02:41:41 +00:00
|
|
|
`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test1.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
2018-08-09 02:41:41 +00:00
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.5, Error: 0.05},
|
|
|
|
{Quantile: 0.9, Error: 0.01},
|
|
|
|
{Quantile: 0.99, Error: 0.001},
|
|
|
|
},
|
2017-07-27 21:01:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with bad observer type",
|
2017-07-27 21:01:12 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
2020-06-15 21:26:20 +00:00
|
|
|
observer_type: wrong
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "foo"
|
2020-06-15 22:41:16 +00:00
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with bad deprecated timer type",
|
2020-06-15 22:41:16 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
timer_type: wrong
|
|
|
|
name: "foo"
|
2018-06-14 12:27:28 +00:00
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
2020-01-16 16:55:09 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "New style quantiles",
|
2020-01-16 16:55:09 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
2020-06-15 21:26:20 +00:00
|
|
|
observer_type: summary
|
2020-01-16 16:55:09 +00:00
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
- quantile: 0.7
|
|
|
|
error: 0.002
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.42, Error: 0.04},
|
|
|
|
{Quantile: 0.7, Error: 0.002},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-01-27 14:50:34 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with summary options",
|
2020-01-27 14:50:34 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
2020-06-15 21:26:20 +00:00
|
|
|
observer_type: summary
|
2020-01-27 14:50:34 +00:00
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
- quantile: 0.7
|
|
|
|
error: 0.002
|
|
|
|
max_age: 5m
|
|
|
|
age_buckets: 2
|
|
|
|
buf_cap: 1000
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.42, Error: 0.04},
|
|
|
|
{Quantile: 0.7, Error: 0.002},
|
|
|
|
},
|
|
|
|
maxAge: 5 * time.Minute,
|
|
|
|
ageBuckets: 2,
|
|
|
|
bufCap: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-01-16 16:55:09 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with default summary options",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
- quantile: 0.7
|
|
|
|
error: 0.002
|
|
|
|
max_age: 5m
|
|
|
|
age_buckets: 2
|
|
|
|
buf_cap: 1000
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.42, Error: 0.04},
|
|
|
|
{Quantile: 0.7, Error: 0.002},
|
|
|
|
},
|
|
|
|
maxAge: 5 * time.Minute,
|
|
|
|
ageBuckets: 2,
|
|
|
|
bufCap: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config with default summary options without quantiles",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
summary_options:
|
|
|
|
max_age: 5m
|
|
|
|
age_buckets: 2
|
|
|
|
buf_cap: 1000
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: defaultQuantiles,
|
|
|
|
maxAge: 5 * time.Minute,
|
|
|
|
ageBuckets: 2,
|
|
|
|
bufCap: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config with default summary options overrides quantiles",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.9
|
|
|
|
error: 0.1
|
|
|
|
- quantile: 0.99
|
|
|
|
error: 0.01
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
- quantile: 0.7
|
|
|
|
error: 0.002
|
|
|
|
max_age: 5m
|
|
|
|
age_buckets: 2
|
|
|
|
buf_cap: 1000
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.42, Error: 0.04},
|
|
|
|
{Quantile: 0.7, Error: 0.002},
|
|
|
|
},
|
|
|
|
maxAge: 5 * time.Minute,
|
|
|
|
ageBuckets: 2,
|
|
|
|
bufCap: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config that overrides default summary options",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.042
|
|
|
|
error: 0.4
|
|
|
|
- quantile: 0.07
|
|
|
|
error: 0.02
|
|
|
|
max_age: 15m
|
|
|
|
age_buckets: 3
|
|
|
|
buf_cap: 100
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
- quantile: 0.7
|
|
|
|
error: 0.002
|
|
|
|
max_age: 5m
|
|
|
|
age_buckets: 2
|
|
|
|
buf_cap: 1000
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.42, Error: 0.04},
|
|
|
|
{Quantile: 0.7, Error: 0.002},
|
|
|
|
},
|
|
|
|
maxAge: 5 * time.Minute,
|
|
|
|
ageBuckets: 2,
|
|
|
|
bufCap: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config that overrides default summary options and a default options mapping",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.9
|
|
|
|
error: 0.1
|
|
|
|
- quantile: 0.99
|
|
|
|
error: 0.01
|
|
|
|
max_age: 15m
|
|
|
|
age_buckets: 3
|
|
|
|
buf_cap: 100
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
- quantile: 0.7
|
|
|
|
error: 0.002
|
|
|
|
max_age: 5m
|
|
|
|
age_buckets: 2
|
|
|
|
buf_cap: 1000
|
|
|
|
- match: test_default.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo_default"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.42, Error: 0.04},
|
|
|
|
{Quantile: 0.7, Error: 0.002},
|
|
|
|
},
|
|
|
|
maxAge: 5 * time.Minute,
|
|
|
|
ageBuckets: 2,
|
|
|
|
bufCap: 1000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "test_default.*.*",
|
|
|
|
name: "foo_default",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.9, Error: 0.1},
|
|
|
|
{Quantile: 0.99, Error: 0.01},
|
|
|
|
},
|
|
|
|
maxAge: 15 * time.Minute,
|
|
|
|
ageBuckets: 3,
|
|
|
|
bufCap: 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config that partially overrides default summary quantiles and a default options mapping",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.9
|
|
|
|
error: 0.1
|
|
|
|
- quantile: 0.99
|
|
|
|
error: 0.01
|
|
|
|
max_age: 15m
|
|
|
|
age_buckets: 3
|
|
|
|
buf_cap: 100
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
- quantile: 0.7
|
|
|
|
error: 0.002
|
|
|
|
- match: test_default.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo_default"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.42, Error: 0.04},
|
|
|
|
{Quantile: 0.7, Error: 0.002},
|
|
|
|
},
|
|
|
|
maxAge: 15 * time.Minute,
|
|
|
|
ageBuckets: 3,
|
|
|
|
bufCap: 100,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "test_default.*.*",
|
|
|
|
name: "foo_default",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.9, Error: 0.1},
|
|
|
|
{Quantile: 0.99, Error: 0.01},
|
|
|
|
},
|
|
|
|
maxAge: 15 * time.Minute,
|
|
|
|
ageBuckets: 3,
|
|
|
|
bufCap: 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-01-28 19:24:41 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config that partially overrides default summary max_age and a default options mapping",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.9
|
|
|
|
error: 0.1
|
|
|
|
- quantile: 0.99
|
|
|
|
error: 0.01
|
|
|
|
max_age: 15m
|
|
|
|
age_buckets: 3
|
|
|
|
buf_cap: 100
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
summary_options:
|
|
|
|
max_age: 5m
|
|
|
|
- match: test_default.*.*
|
|
|
|
observer_type: summary
|
|
|
|
name: "foo_default"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.9, Error: 0.1},
|
|
|
|
{Quantile: 0.99, Error: 0.01},
|
|
|
|
},
|
|
|
|
maxAge: 5 * time.Minute,
|
|
|
|
ageBuckets: 3,
|
|
|
|
bufCap: 100,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "test_default.*.*",
|
|
|
|
name: "foo_default",
|
|
|
|
labels: map[string]string{},
|
|
|
|
quantiles: []metricObjective{
|
|
|
|
{Quantile: 0.9, Error: 0.1},
|
|
|
|
{Quantile: 0.99, Error: 0.01},
|
|
|
|
},
|
|
|
|
maxAge: 15 * time.Minute,
|
|
|
|
ageBuckets: 3,
|
|
|
|
bufCap: 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config with histogram options",
|
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: histogram
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
histogram_options:
|
|
|
|
buckets: [0.1, 1, 10, 100, 1000]
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
buckets: []float64{0.1, 1, 10, 100, 1000},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config with default histogram options",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
histogram_options:
|
|
|
|
buckets: [0.1, 1, 10, 100, 1000]
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: histogram
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
buckets: []float64{0.1, 1, 10, 100, 1000},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config with default histogram options without buckets",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
histogram_options:
|
|
|
|
buckets: []
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: histogram
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
buckets: prometheus.DefBuckets,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config with default histogram options overrides buckets",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
buckets: [0.2, 2, 20, 200, 2000]
|
|
|
|
histogram_options:
|
|
|
|
buckets: [0.1, 1, 10, 100, 1000]
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: histogram
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
buckets: []float64{0.1, 1, 10, 100, 1000},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config that overrides default histogram configuration",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
histogram_options:
|
|
|
|
buckets: [0.2, 2, 20, 200, 2000]
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: histogram
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
histogram_options:
|
|
|
|
buckets: [0.1, 1, 10, 100, 1000]
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
buckets: []float64{0.1, 1, 10, 100, 1000},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Config that overrides default histogram configuration and a default options mapping",
|
|
|
|
config: `---
|
|
|
|
defaults:
|
|
|
|
histogram_options:
|
|
|
|
buckets: [0.2, 2, 20, 200]
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
observer_type: histogram
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
histogram_options:
|
|
|
|
buckets: [0.1, 1, 10, 100, 1000]
|
|
|
|
- match: test_default.*.*
|
|
|
|
observer_type: histogram
|
|
|
|
name: "foo_default"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.*.*",
|
|
|
|
name: "foo",
|
|
|
|
labels: map[string]string{},
|
|
|
|
buckets: []float64{0.1, 1, 10, 100, 1000},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "test_default.*.*",
|
|
|
|
name: "foo_default",
|
|
|
|
labels: map[string]string{},
|
|
|
|
buckets: []float64{0.2, 2, 20, 200},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testName: "Duplicate quantiles are bad",
|
2020-01-16 16:55:09 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
2020-06-15 21:26:20 +00:00
|
|
|
observer_type: summary
|
2020-01-16 16:55:09 +00:00
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
summary_options:
|
|
|
|
quantiles:
|
|
|
|
- quantile: 0.42
|
|
|
|
error: 0.04
|
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
2018-06-14 12:27:28 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with good metric type",
|
2018-06-14 12:27:28 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
match_metric_type: counter
|
|
|
|
name: "foo"
|
2020-06-15 22:46:20 +00:00
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with good metric type observer",
|
2020-06-15 22:46:20 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
match_metric_type: observer
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with good metric type timer",
|
2020-06-15 22:46:20 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
match_metric_type: timer
|
|
|
|
name: "foo"
|
2018-06-14 12:27:28 +00:00
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with bad metric type matcher",
|
2018-06-14 12:27:28 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
match_metric_type: wrong
|
|
|
|
name: "foo"
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: {}
|
2017-09-29 07:57:17 +00:00
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with multiple explicit metric types",
|
2019-06-08 00:04:33 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.foo.*
|
|
|
|
name: "test_foo_sum"
|
|
|
|
match_metric_type: counter
|
|
|
|
- match: test.foo.*
|
|
|
|
name: "test_foo_current"
|
|
|
|
match_metric_type: gauge
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "test.foo.test",
|
|
|
|
name: "test_foo_sum",
|
|
|
|
metricType: MetricTypeCounter,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "test.foo.test",
|
|
|
|
name: "test_foo_current",
|
|
|
|
metricType: MetricTypeGauge,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-09-29 07:57:17 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with uncompilable regex",
|
2017-09-29 07:57:17 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
2018-02-22 22:44:09 +00:00
|
|
|
- match: "*\\.foo"
|
2017-11-13 12:21:29 +00:00
|
|
|
match_type: regex
|
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with non-matched metric",
|
2017-11-13 12:21:29 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: foo.*.*
|
2020-06-15 21:26:20 +00:00
|
|
|
observer_type: summary
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "foo"
|
|
|
|
labels: {}
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.1.2",
|
|
|
|
name: "test_1_2",
|
|
|
|
labels: map[string]string{},
|
|
|
|
notPresent: true,
|
2017-11-13 12:21:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with no name",
|
2017-11-13 12:21:29 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: *\.foo
|
2017-09-29 07:57:17 +00:00
|
|
|
match_type: regex
|
2017-07-27 21:01:12 +00:00
|
|
|
labels:
|
2017-11-13 12:21:29 +00:00
|
|
|
bar: "foo"
|
2017-07-27 21:01:12 +00:00
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
2020-05-29 07:45:22 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config with labels from glob",
|
2020-05-29 07:45:22 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: p.*.*.c.*
|
|
|
|
match_type: glob
|
|
|
|
name: issue_256
|
|
|
|
labels:
|
|
|
|
one: $1
|
|
|
|
two: $2
|
|
|
|
three: $3
|
|
|
|
`,
|
|
|
|
mappings: mappings{
|
|
|
|
{
|
|
|
|
statsdMetric: "p.one.two.c.three",
|
|
|
|
name: "issue_256",
|
|
|
|
labels: map[string]string{
|
|
|
|
"one": "one",
|
|
|
|
"two": "two",
|
|
|
|
"three": "three",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-11-10 20:18:57 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Example from the README",
|
2017-11-10 20:18:57 +00:00
|
|
|
config: `
|
|
|
|
mappings:
|
|
|
|
- match: test.dispatcher.*.*.*
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "dispatcher_events_total"
|
2017-11-10 20:18:57 +00:00
|
|
|
labels:
|
|
|
|
processor: "$1"
|
|
|
|
action: "$2"
|
|
|
|
outcome: "$3"
|
|
|
|
job: "test_dispatcher"
|
|
|
|
- match: "*.signup.*.*"
|
2017-11-13 12:21:29 +00:00
|
|
|
name: "signup_events_total"
|
2017-11-10 20:18:57 +00:00
|
|
|
labels:
|
|
|
|
provider: "$2"
|
|
|
|
outcome: "$3"
|
|
|
|
job: "${1}_server"
|
|
|
|
`,
|
2017-11-13 12:21:29 +00:00
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.dispatcher.FooProcessor.send.success",
|
|
|
|
name: "dispatcher_events_total",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"processor": "FooProcessor",
|
|
|
|
"action": "send",
|
|
|
|
"outcome": "success",
|
|
|
|
"job": "test_dispatcher",
|
|
|
|
},
|
2017-11-10 20:18:57 +00:00
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "foo_product.signup.facebook.failure",
|
|
|
|
name: "signup_events_total",
|
2017-11-13 12:21:29 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"provider": "facebook",
|
|
|
|
"outcome": "failure",
|
|
|
|
"job": "foo_product_server",
|
|
|
|
},
|
|
|
|
},
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.web-server.foo.bar",
|
|
|
|
name: "test_web_server_foo_bar",
|
|
|
|
labels: map[string]string{},
|
2017-11-10 20:18:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-01-02 22:21:50 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config that drops all",
|
2018-01-02 22:21:50 +00:00
|
|
|
config: `mappings:
|
|
|
|
- match: .
|
|
|
|
match_type: regex
|
|
|
|
name: "drop"
|
|
|
|
action: drop`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "abc",
|
|
|
|
},
|
2018-01-02 22:21:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config that has a catch-all to drop all",
|
2018-01-02 22:21:50 +00:00
|
|
|
config: `mappings:
|
|
|
|
- match: web.*
|
|
|
|
name: "web"
|
|
|
|
labels:
|
|
|
|
site: "$1"
|
|
|
|
- match: .
|
|
|
|
match_type: regex
|
|
|
|
name: "drop"
|
|
|
|
action: drop`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "web.localhost",
|
|
|
|
name: "web",
|
2018-01-02 22:21:50 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"site": "localhost",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-12-13 13:53:40 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config that has a ttl",
|
2018-12-13 13:53:40 +00:00
|
|
|
config: `mappings:
|
|
|
|
- match: web.*
|
|
|
|
name: "web"
|
|
|
|
ttl: 10s
|
|
|
|
labels:
|
|
|
|
site: "$1"`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "web.localhost",
|
|
|
|
name: "web",
|
2018-12-13 13:53:40 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"site": "localhost",
|
|
|
|
},
|
|
|
|
ttl: time.Second * 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config that has a default ttl",
|
2018-12-13 13:53:40 +00:00
|
|
|
config: `defaults:
|
|
|
|
ttl: 1m2s
|
|
|
|
mappings:
|
|
|
|
- match: web.*
|
|
|
|
name: "web"
|
|
|
|
labels:
|
|
|
|
site: "$1"`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "web.localhost",
|
|
|
|
name: "web",
|
2018-12-13 13:53:40 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"site": "localhost",
|
|
|
|
},
|
|
|
|
ttl: time.Minute + time.Second*2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "Config that override a default ttl",
|
2018-12-13 13:53:40 +00:00
|
|
|
config: `defaults:
|
|
|
|
ttl: 1m2s
|
|
|
|
mappings:
|
|
|
|
- match: web.*
|
|
|
|
name: "web"
|
|
|
|
ttl: 5s
|
|
|
|
labels:
|
|
|
|
site: "$1"`,
|
|
|
|
mappings: mappings{
|
2019-06-08 00:04:33 +00:00
|
|
|
{
|
|
|
|
statsdMetric: "test.a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
statsdMetric: "web.localhost",
|
|
|
|
name: "web",
|
2018-12-13 13:53:40 +00:00
|
|
|
labels: map[string]string{
|
|
|
|
"site": "localhost",
|
|
|
|
},
|
|
|
|
ttl: time.Second * 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-07-27 20:58:10 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 12:28:38 +00:00
|
|
|
mapper := MetricMapper{}
|
2021-02-07 00:22:29 +00:00
|
|
|
cache, _ := lru.NewMetricMapperLRUCache(mapper.Registerer, 1000)
|
|
|
|
mapper.UseCache(cache)
|
|
|
|
|
2017-07-27 20:58:10 +00:00
|
|
|
for i, scenario := range scenarios {
|
2021-01-28 18:37:56 +00:00
|
|
|
if scenario.testName == "" {
|
|
|
|
t.Fatalf("Missing testName in scenario %+v", scenario)
|
2017-07-27 20:58:10 +00:00
|
|
|
}
|
2021-01-28 18:37:56 +00:00
|
|
|
t.Run(scenario.testName, func(t *testing.T) {
|
2021-02-07 00:22:29 +00:00
|
|
|
err := mapper.InitFromYAMLString(scenario.config)
|
2021-01-28 18:37:56 +00:00
|
|
|
if err != nil && !scenario.configBad {
|
|
|
|
t.Fatalf("%d. Config load error: %s %s", i, scenario.config, err)
|
2017-07-27 20:58:10 +00:00
|
|
|
}
|
2021-01-28 18:37:56 +00:00
|
|
|
if err == nil && scenario.configBad {
|
|
|
|
t.Fatalf("%d. Expected bad config, but loaded ok: %s", i, scenario.config)
|
2017-07-27 20:58:10 +00:00
|
|
|
}
|
2021-01-28 18:37:56 +00:00
|
|
|
|
|
|
|
for metric, mapping := range scenario.mappings {
|
|
|
|
// exporter will call mapper.GetMapping with valid MetricType
|
|
|
|
// so we also pass a sane MetricType in testing if it's not specified
|
|
|
|
mapType := mapping.metricType
|
|
|
|
if mapType == "" {
|
|
|
|
mapType = MetricTypeCounter
|
|
|
|
}
|
|
|
|
m, labels, present := mapper.GetMapping(mapping.statsdMetric, mapType)
|
|
|
|
if present && mapping.name != "" && m.Name != mapping.name {
|
|
|
|
t.Fatalf("%d.%q: Expected name %v, got %v", i, metric, m.Name, mapping.name)
|
|
|
|
}
|
|
|
|
if mapping.notPresent && present {
|
|
|
|
t.Fatalf("%d.%q: Expected metric to not be present", i, metric)
|
|
|
|
}
|
|
|
|
if len(labels) != len(mapping.labels) {
|
|
|
|
t.Fatalf("%d.%q: Expected %d labels, got %d", i, metric, len(mapping.labels), len(labels))
|
|
|
|
}
|
|
|
|
for label, value := range labels {
|
|
|
|
if mapping.labels[label] != value {
|
|
|
|
t.Fatalf("%d.%q: Expected labels %v, got %v", i, metric, mapping, labels)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if mapping.ttl > 0 && mapping.ttl != m.Ttl {
|
|
|
|
t.Fatalf("%d.%q: Expected ttl of %s, got %s", i, metric, mapping.ttl.String(), m.Ttl.String())
|
|
|
|
}
|
|
|
|
if mapping.metricType != "" && mapType != m.MatchMetricType {
|
|
|
|
t.Fatalf("%d.%q: Expected match metric of %s, got %s", i, metric, mapType, m.MatchMetricType)
|
2017-07-27 20:58:10 +00:00
|
|
|
}
|
2017-11-13 12:21:29 +00:00
|
|
|
|
2021-01-28 18:37:56 +00:00
|
|
|
if len(mapping.buckets) != 0 {
|
|
|
|
if len(mapping.buckets) != len(m.HistogramOptions.Buckets) {
|
|
|
|
t.Fatalf("%d.%q: Expected %d buckets, got %d", i, metric, len(mapping.buckets), len(m.HistogramOptions.Buckets))
|
|
|
|
}
|
|
|
|
for i, bucket := range mapping.buckets {
|
|
|
|
if bucket != m.HistogramOptions.Buckets[i] {
|
|
|
|
t.Fatalf("%d.%q: Expected bucket %v, got %v", i, metric, m.HistogramOptions.Buckets[i], bucket)
|
|
|
|
}
|
|
|
|
}
|
2018-08-09 02:41:41 +00:00
|
|
|
}
|
2021-01-28 18:37:56 +00:00
|
|
|
|
|
|
|
if len(mapping.quantiles) != 0 {
|
|
|
|
if len(mapping.quantiles) != len(m.SummaryOptions.Quantiles) {
|
|
|
|
t.Fatalf("%d.%q: Expected %d quantiles, got %d", i, metric, len(mapping.quantiles), len(m.SummaryOptions.Quantiles))
|
2018-08-09 02:41:41 +00:00
|
|
|
}
|
2021-01-28 18:37:56 +00:00
|
|
|
for i, quantile := range mapping.quantiles {
|
|
|
|
if quantile.Quantile != m.SummaryOptions.Quantiles[i].Quantile {
|
|
|
|
t.Fatalf("%d.%q: Expected quantile %v, got %v", i, metric, m.SummaryOptions.Quantiles[i].Quantile, quantile.Quantile)
|
|
|
|
}
|
|
|
|
if quantile.Error != m.SummaryOptions.Quantiles[i].Error {
|
|
|
|
t.Fatalf("%d.%q: Expected Error margin %v, got %v", i, metric, m.SummaryOptions.Quantiles[i].Error, quantile.Error)
|
|
|
|
}
|
2018-08-09 02:41:41 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-28 18:37:56 +00:00
|
|
|
if mapping.maxAge != 0 && mapping.maxAge != m.SummaryOptions.MaxAge {
|
|
|
|
t.Fatalf("%d.%q: Expected max age %v, got %v", i, metric, mapping.maxAge, m.SummaryOptions.MaxAge)
|
|
|
|
}
|
|
|
|
if mapping.ageBuckets != 0 && mapping.ageBuckets != m.SummaryOptions.AgeBuckets {
|
|
|
|
t.Fatalf("%d.%q: Expected max age %v, got %v", i, metric, mapping.ageBuckets, m.SummaryOptions.AgeBuckets)
|
|
|
|
}
|
|
|
|
if mapping.bufCap != 0 && mapping.bufCap != m.SummaryOptions.BufCap {
|
|
|
|
t.Fatalf("%d.%q: Expected max age %v, got %v", i, metric, mapping.bufCap, m.SummaryOptions.BufCap)
|
|
|
|
}
|
2018-08-09 02:41:41 +00:00
|
|
|
}
|
2021-01-28 18:37:56 +00:00
|
|
|
})
|
2017-07-27 20:58:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-02 22:21:50 +00:00
|
|
|
|
|
|
|
func TestAction(t *testing.T) {
|
|
|
|
scenarios := []struct {
|
2021-01-28 18:37:56 +00:00
|
|
|
testName string
|
2018-01-02 22:21:50 +00:00
|
|
|
config string
|
|
|
|
configBad bool
|
2018-08-10 12:28:38 +00:00
|
|
|
expectedAction ActionType
|
2018-01-02 22:21:50 +00:00
|
|
|
}{
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "no action set",
|
2018-01-02 22:21:50 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
name: "foo"
|
|
|
|
`,
|
|
|
|
configBad: false,
|
2018-08-10 12:28:38 +00:00
|
|
|
expectedAction: ActionTypeMap,
|
2018-01-02 22:21:50 +00:00
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "map action set",
|
2018-01-02 22:21:50 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
name: "foo"
|
|
|
|
action: map
|
|
|
|
`,
|
|
|
|
configBad: false,
|
2018-08-10 12:28:38 +00:00
|
|
|
expectedAction: ActionTypeMap,
|
2018-01-02 22:21:50 +00:00
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "drop action set",
|
2018-01-02 22:21:50 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
name: "foo"
|
|
|
|
action: drop
|
|
|
|
`,
|
|
|
|
configBad: false,
|
2018-08-10 12:28:38 +00:00
|
|
|
expectedAction: ActionTypeDrop,
|
2018-01-02 22:21:50 +00:00
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "invalid action set",
|
2018-01-02 22:21:50 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: test.*.*
|
|
|
|
name: "foo"
|
|
|
|
action: xyz
|
|
|
|
`,
|
|
|
|
configBad: true,
|
2018-08-10 12:28:38 +00:00
|
|
|
expectedAction: ActionTypeDrop,
|
2018-01-02 22:21:50 +00:00
|
|
|
},
|
2019-11-26 08:56:14 +00:00
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "valid yaml example",
|
2019-11-26 08:56:14 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: "test\\.(\\w+)\\.(\\w+)\\.counter"
|
|
|
|
match_type: regex
|
|
|
|
name: "${2}_total"
|
|
|
|
labels:
|
|
|
|
provider: "$1"
|
|
|
|
`,
|
|
|
|
configBad: false,
|
|
|
|
expectedAction: ActionTypeMap,
|
|
|
|
},
|
|
|
|
{
|
2021-01-28 18:37:56 +00:00
|
|
|
testName: "invalid yaml example",
|
2019-11-26 08:56:14 +00:00
|
|
|
config: `---
|
|
|
|
mappings:
|
|
|
|
- match: "test\.(\w+)\.(\w+)\.counter"
|
|
|
|
match_type: regex
|
|
|
|
name: "${2}_total"
|
|
|
|
labels:
|
|
|
|
provider: "$1"
|
|
|
|
`,
|
|
|
|
configBad: true,
|
|
|
|
},
|
2018-01-02 22:21:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, scenario := range scenarios {
|
2021-01-28 18:37:56 +00:00
|
|
|
if scenario.testName == "" {
|
|
|
|
t.Fatalf("Missing testName in scenario %+v", scenario)
|
2018-01-02 22:21:50 +00:00
|
|
|
}
|
2021-01-28 18:37:56 +00:00
|
|
|
t.Run(scenario.testName, func(t *testing.T) {
|
|
|
|
mapper := MetricMapper{}
|
2021-02-07 00:22:29 +00:00
|
|
|
err := mapper.InitFromYAMLString(scenario.config)
|
2021-01-28 18:37:56 +00:00
|
|
|
if err != nil && !scenario.configBad {
|
|
|
|
t.Fatalf("%d. Config load error: %s %s", i, scenario.config, err)
|
|
|
|
}
|
|
|
|
if err == nil && scenario.configBad {
|
|
|
|
t.Fatalf("%d. Expected bad config, but loaded ok: %s", i, scenario.config)
|
|
|
|
}
|
2018-01-02 22:21:50 +00:00
|
|
|
|
2021-01-28 18:37:56 +00:00
|
|
|
if !scenario.configBad {
|
|
|
|
a := mapper.Mappings[0].Action
|
|
|
|
if scenario.expectedAction != a {
|
|
|
|
t.Fatalf("%d: Expected action %v, got %v", i, scenario.expectedAction, a)
|
|
|
|
}
|
2018-01-02 22:21:50 +00:00
|
|
|
}
|
2021-01-28 18:37:56 +00:00
|
|
|
})
|
2018-01-02 22:21:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-11 12:03:02 +00:00
|
|
|
|
|
|
|
// Test for https://github.com/prometheus/statsd_exporter/issues/273
|
|
|
|
// Corrupt cache for multiple names matching in fsm
|
|
|
|
func TestMultipleMatches(t *testing.T) {
|
|
|
|
config := `---
|
|
|
|
mappings:
|
|
|
|
- match: aa.bb.*.*
|
|
|
|
name: "aa_bb_${1}_total"
|
|
|
|
labels:
|
2021-02-07 03:59:41 +00:00
|
|
|
app: "$2"
|
2020-01-11 12:03:02 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
names := map[string]string{
|
|
|
|
"aa.bb.aa.myapp": "aa_bb_aa_total",
|
|
|
|
"aa.bb.bb.myapp": "aa_bb_bb_total",
|
|
|
|
"aa.bb.cc.myapp": "aa_bb_cc_total",
|
|
|
|
"aa.bb.dd.myapp": "aa_bb_dd_total",
|
|
|
|
}
|
|
|
|
|
2021-02-19 16:17:27 +00:00
|
|
|
scenarios := []string{"none", "lru"}
|
2020-01-11 12:03:02 +00:00
|
|
|
|
|
|
|
for i, scenario := range scenarios {
|
2021-02-19 16:17:27 +00:00
|
|
|
mapper := newTestMapperWithCache(scenario, 1000)
|
|
|
|
err := mapper.InitFromYAMLString(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("config load error: %s ", err)
|
|
|
|
}
|
2020-01-11 12:03:02 +00:00
|
|
|
|
|
|
|
// run multiple times to ensure cache works as expected
|
|
|
|
for j := 0; j < 10; j++ {
|
|
|
|
for name, expected := range names {
|
|
|
|
m, _, ok := mapper.GetMapping(name, MetricTypeCounter)
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("%d:%d Did not find match for %s", i, j, name)
|
|
|
|
}
|
|
|
|
if m.Name != expected {
|
|
|
|
t.Fatalf("%d:%d Expected name %s, got %s", i, j, expected, m.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 19:24:41 +00:00
|
|
|
}
|