diff --git a/src/main/java/com/timgroup/statsd/NoOpStatsDClient.java b/src/main/java/com/timgroup/statsd/NoOpStatsDClient.java index 0c9ea457..b606ccbe 100644 --- a/src/main/java/com/timgroup/statsd/NoOpStatsDClient.java +++ b/src/main/java/com/timgroup/statsd/NoOpStatsDClient.java @@ -8,22 +8,37 @@ * */ public final class NoOpStatsDClient implements StatsDClient { - @Override public void stop() { } + @Override public void stop() { } @Override public void count(String aspect, long delta, String... tags) { } + @Override public void count(String aspect, long delta, double sampleRate, String... tags) { } @Override public void incrementCounter(String aspect, String... tags) { } + @Override public void incrementCounter(String aspect, double sampleRate, String... tags) { } @Override public void increment(String aspect, String... tags) { } + @Override public void increment(String aspect, double sampleRate, String...tags) { } @Override public void decrementCounter(String aspect, String... tags) { } + @Override public void decrementCounter(String aspect, double sampleRate, String... tags) { } @Override public void decrement(String aspect, String... tags) { } + @Override public void decrement(String aspect, double sampleRate, String... tags) { } @Override public void recordGaugeValue(String aspect, double value, String... tags) { } + @Override public void recordGaugeValue(String aspect, double value, double sampleRate, String... tags) { } @Override public void gauge(String aspect, double value, String... tags) { } + @Override public void gauge(String aspect, double value, double sampleRate, String... tags) { } @Override public void recordGaugeValue(String aspect, long value, String... tags) { } + @Override public void recordGaugeValue(String aspect, long value, double sampleRate, String... tags) { } @Override public void gauge(String aspect, long value, String... tags) { } + @Override public void gauge(String aspect, long value, double sampleRate, String... tags) { } @Override public void recordExecutionTime(String aspect, long timeInMs, String... tags) { } + @Override public void recordExecutionTime(String aspect, long timeInMs, double sampleRate, String... tags) { } @Override public void time(String aspect, long value, String... tags) { } + @Override public void time(String aspect, long value, double sampleRate, String... tags) { } @Override public void recordHistogramValue(String aspect, double value, String... tags) { } + @Override public void recordHistogramValue(String aspect, double value, double sampleRate, String... tags) { } @Override public void histogram(String aspect, double value, String... tags) { } + @Override public void histogram(String aspect, double value, double sampleRate, String... tags) { } @Override public void recordHistogramValue(String aspect, long value, String... tags) { } + @Override public void recordHistogramValue(String aspect, long value, double sampleRate, String... tags) { } @Override public void histogram(String aspect, long value, String... tags) { } + @Override public void histogram(String aspect, long value, double sampleRate, String... tags) { } @Override public void recordEvent(final Event event, final String... tags) { } @Override public void recordServiceCheckRun(ServiceCheck sc) { } @Override public void serviceCheck(ServiceCheck sc) { } diff --git a/src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java b/src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java index 7f192ca2..15969e97 100644 --- a/src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java +++ b/src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java @@ -19,6 +19,8 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; + + /** * A simple StatsD client implementation facilitating metrics recording. * @@ -393,6 +395,17 @@ String tagString(final String[] tags) { public void count(final String aspect, final long delta, final String... tags) { send(String.format("%s%s:%d|c%s", prefix, aspect, delta, tagString(tags))); } + + /** + * {@inheritDoc} + */ + @Override + public void count(final String aspect, final long delta, final double sampleRate, final String...tags) { + if(isInvalidSample(sampleRate)) { + return; + } + send(String.format("%s%s:%d|c|%f%s", prefix, aspect, delta, sampleRate, tagString(tags))); + } /** * Increments the specified counter by one. @@ -408,6 +421,14 @@ public void count(final String aspect, final long delta, final String... tags) { public void incrementCounter(final String aspect, final String... tags) { count(aspect, 1, tags); } + + /** + * {@inheritDoc} + */ + @Override + public void incrementCounter(final String aspect, final double sampleRate, final String... tags) { + count(aspect, 1, sampleRate, tags); + } /** * Convenience method equivalent to {@link #incrementCounter(String, String[])}. @@ -416,6 +437,14 @@ public void incrementCounter(final String aspect, final String... tags) { public void increment(final String aspect, final String... tags) { incrementCounter(aspect, tags); } + + /** + * {@inheritDoc} + */ + @Override + public void increment(final String aspect, final double sampleRate, final String...tags ) { + incrementCounter(aspect, sampleRate, tags); + } /** * Decrements the specified counter by one. @@ -431,6 +460,14 @@ public void increment(final String aspect, final String... tags) { public void decrementCounter(final String aspect, final String... tags) { count(aspect, -1, tags); } + + /** + * {@inheritDoc} + */ + @Override + public void decrementCounter(String aspect, final double sampleRate, final String... tags) { + count(aspect, -1, sampleRate, tags); + } /** * Convenience method equivalent to {@link #decrementCounter(String, String[])}. @@ -439,6 +476,14 @@ public void decrementCounter(final String aspect, final String... tags) { public void decrement(final String aspect, final String... tags) { decrementCounter(aspect, tags); } + + /** + * {@inheritDoc} + */ + @Override + public void decrement(final String aspect, final double sampleRate, final String... tags) { + decrementCounter(aspect, sampleRate, tags); + } /** * Records the latest fixed value for the specified named gauge. @@ -458,6 +503,17 @@ public void recordGaugeValue(final String aspect, final double value, final Stri * padding with extra 0s to represent precision */ send(String.format("%s%s:%s|g%s", prefix, aspect, NUMBER_FORMATTERS.get().format(value), tagString(tags))); } + + /** + * {@inheritDoc} + */ + @Override + public void recordGaugeValue(final String aspect, final double value, final double sampleRate, final String... tags) { + if(isInvalidSample(sampleRate)) { + return; + } + send(String.format("%s%s:%s|g|%f%s", prefix, aspect, NUMBER_FORMATTERS.get().format(value), sampleRate, tagString(tags))); + } /** * Convenience method equivalent to {@link #recordGaugeValue(String, double, String[])}. @@ -466,6 +522,14 @@ public void recordGaugeValue(final String aspect, final double value, final Stri public void gauge(final String aspect, final double value, final String... tags) { recordGaugeValue(aspect, value, tags); } + + /** + * {@inheritDoc} + */ + @Override + public void gauge(final String aspect, final double value, final double sampleRate, final String... tags) { + recordGaugeValue(aspect, value, sampleRate, tags); + } /** @@ -484,6 +548,17 @@ public void gauge(final String aspect, final double value, final String... tags) public void recordGaugeValue(final String aspect, final long value, final String... tags) { send(String.format("%s%s:%d|g%s", prefix, aspect, value, tagString(tags))); } + + /** + * {@inheritDoc} + */ + @Override + public void recordGaugeValue(final String aspect, final long value, final double sampleRate, final String... tags) { + if(isInvalidSample(sampleRate)) { + return; + } + send(String.format("%s%s:%d|g|%f%s", prefix, aspect, value, sampleRate, tagString(tags))); + } /** * Convenience method equivalent to {@link #recordGaugeValue(String, long, String[])}. @@ -492,6 +567,14 @@ public void recordGaugeValue(final String aspect, final long value, final String public void gauge(final String aspect, final long value, final String... tags) { recordGaugeValue(aspect, value, tags); } + + /** + * {@inheritDoc} + */ + @Override + public void gauge(final String aspect, final long value, final double sampleRate, final String... tags) { + recordGaugeValue(aspect, value, sampleRate, tags); + } /** * Records an execution time in milliseconds for the specified named operation. @@ -509,6 +592,17 @@ public void gauge(final String aspect, final long value, final String... tags) { public void recordExecutionTime(final String aspect, final long timeInMs, final String... tags) { send(String.format("%s%s:%d|ms%s", prefix, aspect, timeInMs, tagString(tags))); } + + /** + * {@inheritDoc} + */ + @Override + public void recordExecutionTime(final String aspect, final long timeInMs, final double sampleRate, final String... tags) { + if(isInvalidSample(sampleRate)) { + return; + } + send(String.format("%s%s:%d|ms|%f%s", prefix, aspect, timeInMs, sampleRate, tagString(tags))); + } /** * Convenience method equivalent to {@link #recordExecutionTime(String, long, String[])}. @@ -517,6 +611,14 @@ public void recordExecutionTime(final String aspect, final long timeInMs, final public void time(final String aspect, final long value, final String... tags) { recordExecutionTime(aspect, value, tags); } + + /** + * {@inheritDoc} + */ + @Override + public void time(final String aspect, final long value, final double sampleRate, final String... tags) { + recordExecutionTime(aspect, value, sampleRate, tags); + } /** * Records a value for the specified named histogram. @@ -536,6 +638,19 @@ public void recordHistogramValue(final String aspect, final double value, final * padding with extra 0s to represent precision */ send(String.format("%s%s:%s|h%s", prefix, aspect, NUMBER_FORMATTERS.get().format(value), tagString(tags))); } + + /** + * {@inheritDoc} + */ + @Override + public void recordHistogramValue(final String aspect, final double value, final double sampleRate, final String... tags) { + if(isInvalidSample(sampleRate)) { + return; + } + /* Intentionally using %s rather than %f here to avoid + * padding with extra 0s to represent precision */ + send(String.format("%s%s:%s|h|%f%s", prefix, aspect, NUMBER_FORMATTERS.get().format(value), sampleRate, tagString(tags))); + } /** * Convenience method equivalent to {@link #recordHistogramValue(String, double, String[])}. @@ -544,6 +659,14 @@ public void recordHistogramValue(final String aspect, final double value, final public void histogram(final String aspect, final double value, final String... tags) { recordHistogramValue(aspect, value, tags); } + + /** + * {@inheritDoc} + */ + @Override + public void histogram(final String aspect, final double value, final double sampleRate, final String... tags) { + recordHistogramValue(aspect, value, sampleRate, tags); + } /** * Records a value for the specified named histogram. @@ -561,6 +684,17 @@ public void histogram(final String aspect, final double value, final String... t public void recordHistogramValue(final String aspect, final long value, final String... tags) { send(String.format("%s%s:%d|h%s", prefix, aspect, value, tagString(tags))); } + + /** + * {@inheritDoc} + */ + @Override + public void recordHistogramValue(final String aspect, final long value, final double sampleRate, final String... tags) { + if(isInvalidSample(sampleRate)) { + return; + } + send(String.format("%s%s:%d|h|%f%s", prefix, aspect, value, sampleRate, tagString(tags))); + } /** * Convenience method equivalent to {@link #recordHistogramValue(String, long, String[])}. @@ -569,6 +703,14 @@ public void recordHistogramValue(final String aspect, final long value, final St public void histogram(final String aspect, final long value, final String... tags) { recordHistogramValue(aspect, value, tags); } + + /** + * {@inheritDoc} + */ + @Override + public void histogram(final String aspect, final long value, final double sampleRate, final String... tags) { + recordHistogramValue(aspect, value, sampleRate, tags); + } private String eventMap(final Event event) { final StringBuilder res = new StringBuilder(""); @@ -697,6 +839,10 @@ public void recordSetValue(final String aspect, final String value, final String private void send(final String message) { queue.offer(message); } + + private boolean isInvalidSample(double sampleRate) { + return sampleRate != 1 && Math.random() > sampleRate; + } public static final Charset MESSAGE_CHARSET = Charset.forName("UTF-8"); diff --git a/src/main/java/com/timgroup/statsd/StatsDClient.java b/src/main/java/com/timgroup/statsd/StatsDClient.java index 383f2166..20b00cec 100644 --- a/src/main/java/com/timgroup/statsd/StatsDClient.java +++ b/src/main/java/com/timgroup/statsd/StatsDClient.java @@ -39,6 +39,24 @@ public interface StatsDClient { */ void count(String aspect, long delta, String... tags); + /** + * Adjusts the specified counter by a given delta. + * + *

This method is a DataDog extension, and may not work with other servers.

+ * + *

This method is non-blocking and is guaranteed not to throw an exception.

+ * + * @param aspect + * the name of the counter to adjust + * @param delta + * the amount to adjust the counter by + * @param sampleRate + * percentage of time metric to be sent + * @param tags + * array of tags to be added to the data + */ + void count(String aspect, long delta, double sampleRate, String... tags); + /** * Increments the specified counter by one. * @@ -52,11 +70,32 @@ public interface StatsDClient { * array of tags to be added to the data */ void incrementCounter(String aspect, String... tags); + + /** + * Increments the specified counter by one. + * + *

This method is a DataDog extension, and may not work with other servers.

+ * + *

This method is non-blocking and is guaranteed not to throw an exception.

+ * + * @param aspect + * the name of the counter to increment + * @param sampleRate + * percentage of time metric to be sent + * @param tags + * array of tags to be added to the data + */ + void incrementCounter(String aspect, double sampleRate, String... tags); /** * Convenience method equivalent to {@link #incrementCounter(String, String[])}. */ void increment(String aspect, String... tags); + + /** + * Convenience method equivalent to {@link #incrementCounter(String, double, String[])}. + */ + void increment(String aspect, double sampleRate, String...tags); /** * Decrements the specified counter by one. @@ -71,11 +110,32 @@ public interface StatsDClient { * array of tags to be added to the data */ void decrementCounter(String aspect, String... tags); + + /** + * Decrements the specified counter by one. + * + *

This method is a DataDog extension, and may not work with other servers.

+ * + *

This method is non-blocking and is guaranteed not to throw an exception.

+ * + * @param aspect + * the name of the counter to decrement + * @param sampleRate + * percentage of time metric to be sent + * @param tags + * array of tags to be added to the data + */ + void decrementCounter(String aspect, double sampleRate, String... tags); /** * Convenience method equivalent to {@link #decrementCounter(String, String[])}. */ void decrement(String aspect, String... tags); + + /** + * Convenience method equivalent to {@link #decrementCounter(String, double, String[])}. + */ + void decrement(String aspect, double sampleRate, String... tags); /** * Records the latest fixed value for the specified named gauge. @@ -90,11 +150,32 @@ public interface StatsDClient { * the new reading of the gauge */ void recordGaugeValue(String aspect, double value, String... tags); + + /** + * Records the latest fixed value for the specified named gauge. + * + *

This method is a DataDog extension, and may not work with other servers.

+ * + *

This method is non-blocking and is guaranteed not to throw an exception.

+ * + * @param aspect + * the name of the gauge + * @param sampleRate + * percentage of time metric to be sent + * @param value + * the new reading of the gauge + */ + void recordGaugeValue(String aspect, double value, double sampleRate, String... tags); /** * Convenience method equivalent to {@link #recordGaugeValue(String, double, String[])}. */ void gauge(String aspect, double value, String... tags); + + /** + * Convenience method equivalent to {@link #recordGaugeValue(String, double, double, String[])}. + */ + void gauge(String aspect, double value, double sampleRate, String... tags); /** * Records the latest fixed value for the specified named gauge. @@ -109,11 +190,32 @@ public interface StatsDClient { * the new reading of the gauge */ void recordGaugeValue(String aspect, long value, String... tags); + + /** + * Records the latest fixed value for the specified named gauge. + * + *

This method is a DataDog extension, and may not work with other servers.

+ * + *

This method is non-blocking and is guaranteed not to throw an exception.

+ * + * @param aspect + * the name of the gauge + * @param sampleRate + * percentage of time metric to be sent + * @param value + * the new reading of the gauge + */ + void recordGaugeValue(String aspect, long value, double sampleRate, String... tags); /** * Convenience method equivalent to {@link #recordGaugeValue(String, long, String[])}. */ void gauge(String aspect, long value, String... tags); + + /** + * Convenience method equivalent to {@link #recordGaugeValue(String, long, double, String[])}. + */ + void gauge(String aspect, long value, double sampleRate, String... tags); /** * Records an execution time in milliseconds for the specified named operation. @@ -130,11 +232,34 @@ public interface StatsDClient { * array of tags to be added to the data */ void recordExecutionTime(String aspect, long timeInMs, String... tags); + + /** + * Records an execution time in milliseconds for the specified named operation. + * + *

This method is a DataDog extension, and may not work with other servers.

+ * + *

This method is non-blocking and is guaranteed not to throw an exception.

+ * + * @param aspect + * the name of the timed operation + * @param timeInMs + * the time in milliseconds + * @param sampleRate + * percentage of time metric to be sent + * @param tags + * array of tags to be added to the data + */ + void recordExecutionTime(String aspect, long timeInMs, double sampleRate, String... tags); /** * Convenience method equivalent to {@link #recordExecutionTime(String, long, String[])}. */ void time(String aspect, long value, String... tags); + + /** + * Convenience method equivalent to {@link #recordExecutionTime(String, long, double, String[])}. + */ + void time(String aspect, long value, double sampleRate, String... tags); /** * Records a value for the specified named histogram. @@ -151,12 +276,35 @@ public interface StatsDClient { * array of tags to be added to the data */ void recordHistogramValue(String aspect, double value, String... tags); + + /** + * Records a value for the specified named histogram. + * + *

This method is a DataDog extension, and may not work with other servers.

+ * + *

This method is non-blocking and is guaranteed not to throw an exception.

+ * + * @param aspect + * the name of the histogram + * @param value + * the value to be incorporated in the histogram + * @param sampleRate + * percentage of time metric to be sent + * @param tags + * array of tags to be added to the data + */ + void recordHistogramValue(String aspect, double value, double sampleRate, String... tags); /** * Convenience method equivalent to {@link #recordHistogramValue(String, double, String[])}. */ void histogram(String aspect, double value, String... tags); + /** + * Convenience method equivalent to {@link #recordHistogramValue(String, double, double, String[])}. + */ + void histogram(String aspect, double value, double sampleRate, String... tags); + /** * Records a value for the specified named histogram. * @@ -172,11 +320,34 @@ public interface StatsDClient { * array of tags to be added to the data */ void recordHistogramValue(String aspect, long value, String... tags); + + /** + * Records a value for the specified named histogram. + * + *

This method is a DataDog extension, and may not work with other servers.

+ * + *

This method is non-blocking and is guaranteed not to throw an exception.

+ * + * @param aspect + * the name of the histogram + * @param value + * the value to be incorporated in the histogram + * @param sampleRate + * percentage of time metric to be sent + * @param tags + * array of tags to be added to the data + */ + void recordHistogramValue(String aspect, long value, double sampleRate, String... tags); /** * Convenience method equivalent to {@link #recordHistogramValue(String, long, String[])}. */ void histogram(String aspect, long value, String... tags); + + /** + * Convenience method equivalent to {@link #recordHistogramValue(String, long, double, String[])}. + */ + void histogram(String aspect, long value, double sampleRate, String... tags); /** * Records an event diff --git a/src/test/java/com/timgroup/statsd/NonBlockingStatsDClientTest.java b/src/test/java/com/timgroup/statsd/NonBlockingStatsDClientTest.java index 95799d19..f288809b 100644 --- a/src/test/java/com/timgroup/statsd/NonBlockingStatsDClientTest.java +++ b/src/test/java/com/timgroup/statsd/NonBlockingStatsDClientTest.java @@ -37,6 +37,15 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.mycount:24|c")); } + + @Test(timeout=5000L) public void + sends_counter_value_with_sample_rate_to_statsd() throws Exception { + + client.count("mycount", 24, 1); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.mycount:24|c|1.000000")); + } @Test(timeout=5000L) public void sends_counter_value_to_statsd_with_null_tags() throws Exception { @@ -67,6 +76,17 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.mycount:24|c|#baz,foo:bar")); } + + @Test(timeout=5000L) public void + sends_counter_value_with_sample_rate_to_statsd_with_tags() throws Exception { + + + client.count("mycount", 24, 1, "foo:bar", "baz"); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.mycount:24|c|1.000000|#baz,foo:bar")); + } + @Test(timeout=5000L) public void sends_counter_increment_to_statsd() throws Exception { @@ -87,6 +107,16 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.myinc:1|c|#baz,foo:bar")); } + + @Test(timeout=5000L) public void + sends_counter_increment_with_sample_rate_to_statsd_with_tags() throws Exception { + + + client.incrementCounter("myinc", 1, "foo:bar", "baz"); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.myinc:1|c|1.000000|#baz,foo:bar")); + } @Test(timeout=5000L) public void sends_counter_decrement_to_statsd() throws Exception { @@ -107,6 +137,16 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.mydec:-1|c|#baz,foo:bar")); } + + @Test(timeout=5000L) public void + sends_counter_decrement_with_sample_rate_to_statsd_with_tags() throws Exception { + + + client.decrementCounter("mydec", 1, "foo:bar", "baz"); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.mydec:-1|c|1.000000|#baz,foo:bar")); + } @Test(timeout=5000L) public void sends_gauge_to_statsd() throws Exception { @@ -117,6 +157,16 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.mygauge:423|g")); } + + @Test(timeout=5000L) public void + sends_gauge_with_sample_rate_to_statsd() throws Exception { + + + client.recordGaugeValue("mygauge", 423, 1); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.mygauge:423|g|1.000000")); + } @Test(timeout=5000L) public void sends_large_double_gauge_to_statsd() throws Exception { @@ -157,6 +207,16 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.mygauge:423|g|#baz,foo:bar")); } + + @Test(timeout=5000L) public void + sends_gauge_with_sample_rate_to_statsd_with_tags() throws Exception { + + + client.recordGaugeValue("mygauge", 423, 1, "foo:bar", "baz"); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.mygauge:423|g|1.000000|#baz,foo:bar")); + } @Test(timeout=5000L) public void sends_double_gauge_to_statsd_with_tags() throws Exception { @@ -171,7 +231,6 @@ public void stop() throws Exception { @Test(timeout=5000L) public void sends_histogram_to_statsd() throws Exception { - client.recordHistogramValue("myhistogram", 423); server.waitForMessage(); @@ -197,6 +256,16 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.myhistogram:423|h|#baz,foo:bar")); } + + @Test(timeout=5000L) public void + sends_histogram_with_sample_rate_to_statsd_with_tags() throws Exception { + + + client.recordHistogramValue("myhistogram", 423, 1, "foo:bar", "baz"); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.myhistogram:423|h|1.000000|#baz,foo:bar")); + } @Test(timeout=5000L) public void sends_double_histogram_to_statsd_with_tags() throws Exception { @@ -207,6 +276,16 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.myhistogram:0.423|h|#baz,foo:bar")); } + + @Test(timeout=5000L) public void + sends_double_histogram_with_sample_rate_to_statsd_with_tags() throws Exception { + + + client.recordHistogramValue("myhistogram", 0.423, 1, "foo:bar", "baz"); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.myhistogram:0.423|h|1.000000|#baz,foo:bar")); + } @Test(timeout=5000L) public void sends_timer_to_statsd() throws Exception { @@ -253,6 +332,16 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.mytime:123|ms|#baz,foo:bar")); } + + @Test(timeout=5000L) public void + sends_timer_with_sample_rate_to_statsd_with_tags() throws Exception { + + + client.recordExecutionTime("mytime", 123, 1, "foo:bar", "baz"); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.mytime:123|ms|1.000000|#baz,foo:bar")); + } @Test(timeout=5000L) public void @@ -264,6 +353,16 @@ public void stop() throws Exception { assertThat(server.messagesReceived(), contains("my.prefix.value:423|g|#app:bar,instance:foo,baz")); } + + @Test(timeout=5000L) public void + sends_gauge_mixed_tags_with_sample_rate() throws Exception { + + final NonBlockingStatsDClient empty_prefix_client = new NonBlockingStatsDClient("my.prefix", "localhost", STATSD_SERVER_PORT, Integer.MAX_VALUE, "instance:foo", "app:bar"); + empty_prefix_client.gauge("value", 423,1, "baz"); + server.waitForMessage(); + + assertThat(server.messagesReceived(), contains("my.prefix.value:423|g|1.000000|#app:bar,instance:foo,baz")); + } @Test(timeout=5000L) public void sends_gauge_constant_tags_only() throws Exception {