From 84657e85ece67d5a8865e30a722590c3a8e6e9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Fern=C3=A1ndez=20Campo?= Date: Tue, 26 Nov 2019 09:56:14 +0100 Subject: [PATCH] Updated docs and added good/bad example yaml Signed-off-by: Joaquin Fernandez Campo --- CHANGELOG.md | 1 + README.md | 10 ++++++++++ pkg/mapper/mapper_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e616781..89ac723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## unreleased / ????-??-?? +* [ENHANCEMENT] Updated readme docs and added a test for invalid yaml ([#274](https://github.com/prometheus/statsd_exporter/issues/274)) * [ENHANCEMENT] Support sampling factors for all statsd metric types ([#264](https://github.com/prometheus/statsd_exporter/issues/250)) * [ENHANCEMENT] Support Librato and InfluxDB labeling formats ([#267](https://github.com/prometheus/statsd_exporter/pull/267)) diff --git a/README.md b/README.md index 5714bd3..d7e0076 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,16 @@ could be written as: ```yaml mappings: +- match: "test\\.(\\w+)\\.(\\w+)\\.counter" + match_type: regex + name: "${2}_total" + labels: + provider: "$1" +``` + +Be aware about yaml escape rules as a mapping like the following one will not work. +```yaml +mappings: - match: "test\.(\w+)\.(\w+)\.counter" match_type: regex name: "${2}_total" diff --git a/pkg/mapper/mapper_test.go b/pkg/mapper/mapper_test.go index 92bdd5f..93649c6 100644 --- a/pkg/mapper/mapper_test.go +++ b/pkg/mapper/mapper_test.go @@ -842,6 +842,31 @@ mappings: configBad: true, expectedAction: ActionTypeDrop, }, + { + // valid yaml example + config: `--- +mappings: +- match: "test\\.(\\w+)\\.(\\w+)\\.counter" + match_type: regex + name: "${2}_total" + labels: + provider: "$1" +`, + configBad: false, + expectedAction: ActionTypeMap, + }, + { + // invalid yaml example + config: `--- +mappings: +- match: "test\.(\w+)\.(\w+)\.counter" + match_type: regex + name: "${2}_total" + labels: + provider: "$1" +`, + configBad: true, + }, } for i, scenario := range scenarios {