Permalink
Browse files

Allow tag values in metric names.

  • Loading branch information...
1 parent 4d3e405 commit 87dc2e1d66430a1136e6456c0a944364dc9df592 @cosimo committed Jun 1, 2016
Showing with 38 additions and 3 deletions.
  1. +2 −2 dist.ini
  2. +2 −1 lib/Net/Statsd/Server.pm
  3. +34 −0 t/integration-tests/keys-with-tags.t
View
@@ -2,9 +2,9 @@ name = Net-Statsd-Server
author = Cosimo Streppone <cosimo@cpan.org>
license = Perl_5
copyright_holder = Cosimo Streppone
-copyright_year = 2015
+copyright_year = 2016
-version = 0.19
+version = 0.20
[@Basic]
[PkgVersion]
View
@@ -283,8 +283,9 @@ sub handle_client_packet {
my @bits = split(":", $m);
my $key = shift @bits;
+ # Keep [,=] to allow sending of tags. Handy for Influxdb integration.
$key =~ y{/ }{_-}s;
- $key =~ y{a-zA-Z0-9_\-\.}{}cd;
+ $key =~ y{a-zA-Z0-9_\-\.,=}{}cd;
# Not very clear here. Etsy's code was doing this differently
if ($must_count_keys) {
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+use 5.008;
+use strict;
+use warnings;
+
+use FindBin qw($Bin);
+use Test::Statsd;
+use Test::More;
+
+plan tests => 2;
+
+my $t = Test::Statsd->new({
+ binary => $ENV{STATSD_BINARY} || qq{$^X $Bin/../../bin/statsd},
+ config => $ENV{STATSD_CONFIG} || qq{$Bin/../config/testConfig.js},
+});
+
+$t->start_statsd();
+
+my $test_value = 100;
+my $counter = "a_test_value,category=web,severity=high";
+$t->send_udp(localhost=>40001, "${counter}:${test_value}|c");
+
+# Will wait until it receives the graphite flush
+my $stats = $t->wait_and_collect_flush_data();
+ok($stats, "Should receive some data");
+
+diag($stats);
+
+$t->stop_statsd();
+$stats = $t->hashify($stats);
+
+is($stats->{"stats.counters.${counter}.count"} => 100,
+ "Counter key name with tags is preserved correctly");

0 comments on commit 87dc2e1

Please sign in to comment.