diff --git a/README.md b/README.md index 4370a9a..042dff3 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,8 @@ starting at 1. Multiple matching definitions are separated by one or more empty lines. The first mapping rule that matches a StatsD metric wins. Metrics that don't match any mapping in the configuration file are translated -into Prometheus metrics without any labels and with certain characters escaped -(`_` -> `__`; `-` -> `__`; `.` -> `_`). +into Prometheus metrics without any labels and with any non-alphanumeric +characters, including periods, translated into underscores. In general, the different metric types are translated as follows: @@ -125,7 +125,7 @@ follows: => signup_events_total{provider="facebook", outcome="failure", job="foo_product_server"} test.web-server.foo.bar - => test_web__server_foo_bar{} + => test_web_server_foo_bar{} If the default metric help text is insufficient for your needs you may use the YAML diff --git a/exporter_test.go b/exporter_test.go index 7eeb4e1..9941f0e 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -153,3 +153,21 @@ func (ml *mockStatsDTCPListener) handlePacket(packet []byte, e chan<- Events) { } ml.handleConn(sc, e) } + +func TestEscapeMetricName(t *testing.T) { + scenarios := map[string]string{ + "clean": "clean", + "0starts_with_digit": "_0starts_with_digit", + "with_underscore": "with_underscore", + "with.dot": "with_dot", + "with😱emoji": "with_emoji", + "with.*.multiple": "with___multiple", + "test.web-server.foo.bar": "test_web_server_foo_bar", + } + + for in, want := range scenarios { + if got := escapeMetricName(in); want != got { + t.Errorf("expected `%s` to be escaped to `%s`, got `%s`", in, want, got) + } + } +}