Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ String tagString(final String[] tags) {
public void count(final String aspect, final long delta, final String... tags) {
send(new StringBuilder(prefix).append(aspect).append(":").append(delta).append("|c").append(tagString(tags)).toString());
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -809,7 +809,7 @@ public void count(final String aspect, final double delta, final double sampleRa
public void incrementCounter(final String aspect, final String... tags) {
count(aspect, 1, tags);
}

/**
* {@inheritDoc}
*/
Expand All @@ -825,7 +825,7 @@ public void incrementCounter(final String aspect, final double sampleRate, final
public void increment(final String aspect, final String... tags) {
incrementCounter(aspect, tags);
}

/**
* {@inheritDoc}
*/
Expand All @@ -848,7 +848,7 @@ public void increment(final String aspect, final double sampleRate, final String
public void decrementCounter(final String aspect, final String... tags) {
count(aspect, -1, tags);
}

/**
* {@inheritDoc}
*/
Expand All @@ -864,7 +864,7 @@ public void decrementCounter(String aspect, final double sampleRate, final Strin
public void decrement(final String aspect, final String... tags) {
decrementCounter(aspect, tags);
}

/**
* {@inheritDoc}
*/
Expand All @@ -891,7 +891,7 @@ public void recordGaugeValue(final String aspect, final double value, final Stri
* padding with extra 0s to represent precision */
send(new StringBuilder(prefix).append(aspect).append(":").append(NUMBER_FORMATTERS.get().format(value)).append("|g").append(tagString(tags)).toString());
}

/**
* {@inheritDoc}
*/
Expand All @@ -910,7 +910,7 @@ public void recordGaugeValue(final String aspect, final double value, final doub
public void gauge(final String aspect, final double value, final String... tags) {
recordGaugeValue(aspect, value, tags);
}

/**
* {@inheritDoc}
*/
Expand All @@ -936,7 +936,7 @@ public void gauge(final String aspect, final double value, final double sampleRa
public void recordGaugeValue(final String aspect, final long value, final String... tags) {
send(new StringBuilder(prefix).append(aspect).append(":").append(value).append("|g").append(tagString(tags)).toString());
}

/**
* {@inheritDoc}
*/
Expand All @@ -955,7 +955,7 @@ public void recordGaugeValue(final String aspect, final long value, final double
public void gauge(final String aspect, final long value, final String... tags) {
recordGaugeValue(aspect, value, tags);
}

/**
* {@inheritDoc}
*/
Expand All @@ -980,7 +980,7 @@ public void gauge(final String aspect, final long value, final double sampleRate
public void recordExecutionTime(final String aspect, final long timeInMs, final String... tags) {
send(new StringBuilder(prefix).append(aspect).append(":").append(timeInMs).append("|ms").append(tagString(tags)).toString());
}

/**
* {@inheritDoc}
*/
Expand All @@ -999,7 +999,7 @@ 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}
*/
Expand All @@ -1026,7 +1026,7 @@ public void recordHistogramValue(final String aspect, final double value, final
* padding with extra 0s to represent precision */
send(new StringBuilder(prefix).append(aspect).append(":").append(NUMBER_FORMATTERS.get().format(value)).append("|h").append(tagString(tags)).toString());
}

/**
* {@inheritDoc}
*/
Expand All @@ -1047,7 +1047,7 @@ 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}
*/
Expand All @@ -1072,7 +1072,7 @@ public void histogram(final String aspect, final double value, final double samp
public void recordHistogramValue(final String aspect, final long value, final String... tags) {
send(new StringBuilder(prefix).append(aspect).append(":").append(value).append("|h").append(tagString(tags)).toString());
}

/**
* {@inheritDoc}
*/
Expand All @@ -1091,7 +1091,7 @@ public void recordHistogramValue(final String aspect, final long value, final do
public void histogram(final String aspect, final long value, final String... tags) {
recordHistogramValue(aspect, value, tags);
}

/**
* {@inheritDoc}
*/
Expand All @@ -1104,7 +1104,7 @@ public void histogram(final String aspect, final long value, final double sample
* Records a value for the specified named distribution.
*
* <p>This method is non-blocking and is guaranteed not to throw an exception.</p>
*
*
* <p>This is a beta feature and must be enabled specifically for your organization.</p>
*
* @param aspect
Expand All @@ -1120,7 +1120,7 @@ public void recordDistributionValue(final String aspect, final double value, fin
* padding with extra 0s to represent precision */
send(new StringBuilder(prefix).append(aspect).append(":").append(NUMBER_FORMATTERS.get().format(value)).append("|d").append(tagString(tags)).toString());
}

/**
* {@inheritDoc}
*/
Expand All @@ -1141,7 +1141,7 @@ public void recordDistributionValue(final String aspect, final double value, fin
public void distribution(final String aspect, final double value, final String... tags) {
recordDistributionValue(aspect, value, tags);
}

/**
* {@inheritDoc}
*/
Expand All @@ -1153,7 +1153,7 @@ public void distribution(final String aspect, final double value, final double s
* Records a value for the specified named distribution.
*
* <p>This method is non-blocking and is guaranteed not to throw an exception.</p>
*
*
* <p>This is a beta feature and must be enabled specifically for your organization.</p>
*
* @param aspect
Expand All @@ -1167,7 +1167,7 @@ public void distribution(final String aspect, final double value, final double s
public void recordDistributionValue(final String aspect, final long value, final String... tags) {
send(new StringBuilder(prefix).append(aspect).append(":").append(value).append("|d").append(tagString(tags)).toString());
}

/**
* {@inheritDoc}
*/
Expand All @@ -1186,7 +1186,7 @@ public void recordDistributionValue(final String aspect, final long value, final
public void distribution(final String aspect, final long value, final String... tags) {
recordDistributionValue(aspect, value, tags);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -1288,7 +1288,8 @@ private String[] updateTagsWithEntityID(String[] tags, String entityID) {
tags = new String[]{entityTag};
} else {
tags = Arrays.copyOf(tags, tags.length+1);
tags[tags.length] = entityTag;
// Now that tags is one element longer, tags.length has changed...
tags[tags.length - 1] = entityTag;
}
}
return tags;
Expand Down Expand Up @@ -1385,7 +1386,7 @@ public void recordSetValue(final String aspect, final String value, final String
private void send(final String message) {
statsDSender.send(message);
}

private boolean isInvalidSample(double sampleRate) {
return sampleRate != 1 && ThreadLocalRandom.current().nextDouble() > sampleRate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,18 @@ public void sends_gauge_entityID_from_env() throws Exception {
assertThat(server.messagesReceived(), contains("my.prefix.value:423|g|#dd.internal.entity_id:foo-entity"));
}

@Test(timeout = 5000L)
public void sends_gauge_entityID_from_env_and_constant_tags() throws Exception {
final String entity_value = "foo-entity";
environmentVariables.set(NonBlockingStatsDClient.DD_ENTITY_ID_ENV_VAR, entity_value);
final String constantTags = "arbitraryTag:arbitraryValue";
final NonBlockingStatsDClient client = new NonBlockingStatsDClient("my.prefix", "localhost", STATSD_SERVER_PORT, constantTags);
client.gauge("value", 423);
server.waitForMessage();

assertThat(server.messagesReceived(), contains("my.prefix.value:423|g|#dd.internal.entity_id:foo-entity," + constantTags));
}

@Test(timeout = 5000L)
public void sends_gauge_entityID_from_args() throws Exception {
final String entity_value = "foo-entity";
Expand Down