Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #38

Open
wants to merge 91 commits into
base: master
Choose a base branch
from
Open

test #38

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
47cd337
2.0.1: Add floating-point support; reflect pending release under inde…
charles-dyfis-net Nov 28, 2012
d459699
2.0.2: Allow histograms to be floating-point; add test coverage
charles-dyfis-net Nov 28, 2012
9007353
2.0.3: Add support for null or empty prefix values
charles-dyfis-net Nov 28, 2012
6378119
2.0.4: Format floating-point values more explicitly
charles-dyfis-net Dec 3, 2012
27e56ed
Move from Ant to Maven
charles-dyfis-net Dec 5, 2012
2eed16b
[maven-release-plugin] prepare release 2.0.5
charles-dyfis-net Dec 5, 2012
adb5d9f
[maven-release-plugin] prepare for next development iteration
charles-dyfis-net Dec 5, 2012
d01a2ea
Changed signature of all methods: argument 'String[] tags' replaced b…
ashofthedream Dec 21, 2012
22f8883
Merge pull request #1 from ashofthedream/master
charles-dyfis-net Jan 12, 2013
08ad391
Move README to point to 2.0.5 as last release
charles-dyfis-net Jan 12, 2013
18955c3
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.6
charles-dyfis-net Jan 12, 2013
898bf67
[maven-release-plugin] prepare for next development iteration
charles-dyfis-net Jan 12, 2013
c5a0ef4
Update README to reflect new usage; fix whitespace to conform with co…
charles-dyfis-net Jan 15, 2013
dcaed45
Constant tags; compatibility with non-datadog recordExecutionTime
charles-dyfis-net Feb 11, 2013
f2d16f6
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.7
charles-dyfis-net Feb 11, 2013
4c8bc1e
[maven-release-plugin] prepare for next development iteration
charles-dyfis-net Feb 11, 2013
4b23226
Update README to point to new release
charles-dyfis-net Feb 11, 2013
2807100
Pre-render constant tags
charles-dyfis-net Feb 18, 2013
af79a44
NonBlockingStatsDClient as a daemon thread.
anikiforovopensource Jun 12, 2013
d445d74
Fix for issues #3 and #4 with regression test for #3
kaufda Jul 22, 2013
6473169
Merge pull request #5 from domurtag/master
charles-dyfis-net Jul 22, 2013
104c781
Merge pull request #2 from lexn82/patch-1
charles-dyfis-net Jul 22, 2013
5adaed0
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.8
charles-dyfis-net Jul 22, 2013
0d5b521
[maven-release-plugin] prepare for next development iteration
charles-dyfis-net Jul 22, 2013
985b272
Normalize POM with other Indeed OSS projects
charles-dyfis-net Oct 8, 2013
88f4d4e
rely on library versions from parent pom
charles-dyfis-net Oct 8, 2013
73b4c5b
int -> long
ashofthedream Dec 14, 2013
5d34f15
performance improvements:
michaelsembwever Mar 7, 2014
3c94364
Merge pull request #7 from finn-no/feature/automatic-multi-metrics
camerondavison Apr 9, 2014
b99aab9
restores compatibility with vanilla statsd
michaelsembwever Mar 28, 2014
3aa86c2
Merging pull request #9 making api into longs
camerondavison Apr 30, 2014
701faca
Merge pull request #8 from finn-no/bugfix/vanilla-statsd-time-semantics
camerondavison Apr 30, 2014
3d2f31a
set parent.version to latest version of https://oss.sonatype.org/cont…
Jan 14, 2015
83024a6
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.9
indeedeng-release Jan 14, 2015
5723278
[maven-release-plugin] prepare for next development iteration
indeedeng-release Jan 14, 2015
6afa75c
COMMON-1195 : support posting events
Mar 2, 2015
6d7b5f9
Merge pull request #12 from indeedeng/events
ovesh Mar 4, 2015
48170f3
Merge branch 'from_public/master' into 'master'
Mar 5, 2015
2c04e5b
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.10
indeedeng-release Mar 5, 2015
337f61a
[maven-release-plugin] prepare for next development iteration
indeedeng-release Mar 5, 2015
fc8042f
Service check support
Jan 12, 2015
6c306b3
minor code improvements:
Apr 30, 2015
50388aa
Merge branch 'DataDog-yann/service-checks-support'
Apr 30, 2015
17b2c84
DEVOPS-198 : fix broken unit test.
May 3, 2015
932301e
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.11
indeedeng-release May 3, 2015
67181aa
[maven-release-plugin] prepare for next development iteration
indeedeng-release May 3, 2015
1011fea
DEVOPS-203 : specify a charset to String.getBytes()
Jun 2, 2015
783cefd
Merge branch 'jira/DEVOPS-203' into 'master'
Jun 3, 2015
8ef8047
DEVOPS-203 : specify charset for new String() in test code
Jun 7, 2015
1ea54f8
NOBUG : remove accidentally added .idea dir
Jun 7, 2015
c435262
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.12
indeedeng-release Jun 7, 2015
7872952
[maven-release-plugin] prepare for next development iteration
indeedeng-release Jun 7, 2015
918ce6b
update readme to reflect latest release
SupermanScott Jun 11, 2015
1ae749a
Merge pull request #14 from SupermanScott/master
ovesh Jun 11, 2015
b2205fe
Sets NaN symbol format
Aug 8, 2015
2aeb88d
DEVOPS-322 : fixed readme to reflect correct usage of recordExecution…
Aug 9, 2015
3fb52dd
Merge branch 'master' of github.com:mcpate/java-dogstatsd-client into…
Aug 9, 2015
ccfd0f8
DEVOPS-323 : defend against RuntimeException, and clean up tests
Aug 9, 2015
1e1ab9d
Merge branch 'jira/DEVOPS-323'
Aug 11, 2015
c3892d0
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.13
indeedeng-release Dec 22, 2015
ca218a2
[maven-release-plugin] prepare for next development iteration
indeedeng-release Dec 22, 2015
4f5f022
Don't cache DNS resolution forever
mdyer-atlassian Mar 14, 2016
1be1607
Externalise DNS resolution on the NonBlockingStatsDClient.
fakraemer Mar 18, 2016
242e346
Merge pull request #1 from fakraemer/master
matthewAURA Mar 22, 2016
5c1bf6a
DEVOPS-657 : minor style fixes
Mar 22, 2016
f66c48e
Merge branch 'jira/DEVOPS-657-2'
Mar 22, 2016
64359b5
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.14
indeedeng-release Mar 29, 2016
da8777b
[maven-release-plugin] prepare for next development iteration
indeedeng-release Mar 29, 2016
9030b1a
Add support for dogstatsd set values.
jonson Apr 1, 2016
eba2c74
Add link to dogstatsd sets extension.
jonson Apr 4, 2016
94a3ad3
NOBUG : minor style adjustments and added final modifiers
Apr 5, 2016
b542c26
Merge branch 'jira/DEVOPS-691'
Apr 5, 2016
0ed8d91
Wiring in a queueSize constructor parameter for NonBlockingStatsDClient.
cowboygneox Apr 12, 2016
7a90568
Merge pull request #29 from cowboygneox/queue-size
ovesh Apr 14, 2016
043086b
COMMON-2075 : escape newlines in event text
Apr 17, 2016
08c8a6c
COMMON-2075 : rename method to be more accurate
Apr 17, 2016
64c8add
Merge branch 'jira/COMMON-2075'
Apr 20, 2016
ff80858
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.15
indeedeng-release Apr 20, 2016
1f2ccb6
[maven-release-plugin] prepare for next development iteration
indeedeng-release Apr 20, 2016
6598b0d
DEVOPS-657 : fix broken compatibility by re-adding removed c'tors
Apr 20, 2016
9e6b4e6
[maven-release-plugin] prepare release java-dogstatsd-client-2.0.16
indeedeng-release Apr 20, 2016
549b810
[maven-release-plugin] prepare for next development iteration
indeedeng-release Apr 20, 2016
158a2f9
Minor corrections on capitalization of Datadog
irabinovitch Jun 13, 2016
aa15263
Merge pull request #31 from irabinovitch/patch-1
ovesh Jun 13, 2016
00d96f1
Update maven repository link in README
myliu Jun 24, 2016
4f11def
Fix syntax errors in example code.
bhamail Jun 30, 2016
cd16a42
Merge pull request #32 from myliu/master
ovesh Jun 30, 2016
cd1ce78
Merge pull request #33 from bhamail/doc-example-code-fixes
ovesh Jun 30, 2016
8fd18a9
Update readme to direct folks to new merged repo
irabinovitch Aug 17, 2016
1ec4010
new issue and PR templates
irabinovitch Aug 17, 2016
795fbcd
Merge pull request #34 from irabinovitch/patch-2
ovesh Aug 17, 2016
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
Prev Previous commit
Next Next commit
Constant tags; compatibility with non-datadog recordExecutionTime
- Add support for initialization-time constant tag list (similar use
  case to constant prefix).

- Convert millisecond times to floating-point histogram type for
  compatibility with upstream semantics.
  • Loading branch information
charles-dyfis-net committed Feb 11, 2013
commit dcaed45c36ef74ba370d806647a4a06b173a9566
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,26 @@ import com.timgroup.statsd.StatsDClient;
import com.timgroup.statsd.NonBlockingStatsDClient;

public class Foo {
private static final StatsDClient statsd = new NonBlockingStatsDClient("my.prefix", "statsd-host", 8125);

private static final StatsDClient statsd = new NonBlockingStatsDClient(
"my.prefix", /* prefix to any stats; may be null or empty string */
"statsd-host", /* common case: localhost */
8125, /* port */
new String[] {"tag:value"} /* DataDog extension: Constant tags, always applied */
);

public static final void main(String[] args) {
statsd.incrementCounter("foo");
statsd.recordGaugeValue("bar", 100);
statsd.recordGaugeValue("baz", 0.01); /* DataDog extension: support for floating-point gauges */
statsd.recordHistogram("qux", 15) /* DataDog extension: histograms */
statsd.recordHistogram("qux", 15.5) /* ...also floating-point */

/* Compatibility note: Unlike upstream statsd, DataDog expects execution times to be a
* floating-point value in seconds, not a millisecond value. This library
* does the conversion from ms to fractional seconds.
*/
statsd.recordExecutionTime("bag", 25, "cluster:foo"); /* DataDog extension: cluster tag */
statsd.recordHistogram("qux", 15) /* DataDog extension: histograms */
statsd.recordHistogram("qux", 15.5) /* ...also floating-point */
}
}
```
Expand Down
66 changes: 55 additions & 11 deletions src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public final class NonBlockingStatsDClient implements StatsDClient {
private final String prefix;
private final DatagramSocket clientSocket;
private final StatsDClientErrorHandler handler;
private final String[] constantTags;

private final ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
final ThreadFactory delegate = Executors.defaultThreadFactory();
Expand All @@ -71,7 +72,7 @@ public final class NonBlockingStatsDClient implements StatsDClient {
* be established. Once a client has been instantiated in this way, all
* exceptions thrown during subsequent usage are consumed, guaranteeing
* that failures in metrics will not affect normal code execution.
*
*
* @param prefix
* the prefix to apply to keys sent via this client
* @param hostname
Expand All @@ -82,9 +83,34 @@ public final class NonBlockingStatsDClient implements StatsDClient {
* if the client could not be started
*/
public NonBlockingStatsDClient(String prefix, String hostname, int port) throws StatsDClientException {
this(prefix, hostname, port, NO_OP_HANDLER);
this(prefix, hostname, port, null, NO_OP_HANDLER);
}

/**
* Create a new StatsD client communicating with a StatsD instance on the
* specified host and port. All messages send via this client will have
* their keys prefixed with the specified string. The new client will
* attempt to open a connection to the StatsD server immediately upon
* instantiation, and may throw an exception if that a connection cannot
* be established. Once a client has been instantiated in this way, all
* exceptions thrown during subsequent usage are consumed, guaranteeing
* that failures in metrics will not affect normal code execution.
*
* @param prefix
* the prefix to apply to keys sent via this client
* @param hostname
* the host name of the targeted StatsD server
* @param port
* the port of the targeted StatsD server
* @param constantTags
* tags to be added to all content sent
* @throws StatsDClientException
* if the client could not be started
*/
public NonBlockingStatsDClient(String prefix, String hostname, int port, String[] constantTags) throws StatsDClientException {
this(prefix, hostname, port, constantTags, NO_OP_HANDLER);
}

/**
* Create a new StatsD client communicating with a StatsD instance on the
* specified host and port. All messages send via this client will have
Expand All @@ -102,19 +128,25 @@ public NonBlockingStatsDClient(String prefix, String hostname, int port) throws
* the host name of the targeted StatsD server
* @param port
* the port of the targeted StatsD server
* @param constantTags
* tags to be added to all content sent
* @param errorHandler
* handler to use when an exception occurs during usage
* @throws StatsDClientException
* if the client could not be started
*/
public NonBlockingStatsDClient(String prefix, String hostname, int port, StatsDClientErrorHandler errorHandler) throws StatsDClientException {
public NonBlockingStatsDClient(String prefix, String hostname, int port, String[] constantTags, StatsDClientErrorHandler errorHandler) throws StatsDClientException {
if(prefix != null && prefix.length() > 0) {
this.prefix = String.format("%s.", prefix);
} else {
this.prefix = "";
}
this.handler = errorHandler;

if(constantTags != null && constantTags.length == 0) {
constantTags = null;
}
this.constantTags = constantTags;

try {
this.clientSocket = new DatagramSocket();
this.clientSocket.connect(new InetSocketAddress(hostname, port));
Expand Down Expand Up @@ -147,14 +179,26 @@ public void stop() {
* Generate a suffix conveying the given tag list to the client
*/
String tagString(String[] tags) {
if(tags == null || tags.length == 0) {
boolean have_call_tags = (tags != null && tags.length > 0);
boolean have_constant_tags = (constantTags != null && constantTags.length > 0);
if(!have_call_tags && !have_constant_tags) {
return "";
}
StringBuilder sb = new StringBuilder("|#");
for(int n=tags.length - 1; n>=0; n--) {
sb.append(tags[n]);
if(n > 0) {
sb.append(",");
if(have_constant_tags) {
for(int n=constantTags.length - 1; n>=0; n--) {
sb.append(constantTags[n]);
if(n > 0 || have_call_tags) {
sb.append(",");
}
}
}
if (have_call_tags) {
for(int n=tags.length - 1; n>=0; n--) {
sb.append(tags[n]);
if(n > 0) {
sb.append(",");
}
}
}
return sb.toString();
Expand Down Expand Up @@ -290,7 +334,7 @@ public void gauge(String aspect, int value, String... tags) {
*/
@Override
public void recordExecutionTime(String aspect, long timeInMs, String... tags) {
send(String.format("%s%s:%d|ms%s", prefix, aspect, timeInMs, tagString(tags)));
recordHistogramValue(aspect, (timeInMs * 0.001), tags);
}

/**
Expand Down
26 changes: 23 additions & 3 deletions src/test/java/com/timgroup/statsd/NonBlockingStatsDClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void stop() throws Exception {
sends_counter_value_to_statsd_with_null_tags() throws Exception {
final DummyStatsDServer server = new DummyStatsDServer(STATSD_SERVER_PORT);

client.count("mycount", 24, null);
client.count("mycount", 24, (java.lang.String[]) null);
server.waitForMessage();

assertThat(server.messagesReceived(), contains("my.prefix.mycount:24|c"));
Expand Down Expand Up @@ -209,7 +209,7 @@ public void stop() throws Exception {
client.recordExecutionTime("mytime", 123);
server.waitForMessage();

assertThat(server.messagesReceived(), contains("my.prefix.mytime:123|ms"));
assertThat(server.messagesReceived(), contains("my.prefix.mytime:0.123|h"));
}

@Test(timeout=5000L) public void
Expand All @@ -219,10 +219,30 @@ public void stop() throws Exception {
client.recordExecutionTime("mytime", 123, "foo:bar", "baz");
server.waitForMessage();

assertThat(server.messagesReceived(), contains("my.prefix.mytime:123|ms|#baz,foo:bar"));
assertThat(server.messagesReceived(), contains("my.prefix.mytime:0.123|h|#baz,foo:bar"));
}


@Test(timeout=5000L) public void
sends_gauge_mixed_tags() throws Exception {
final DummyStatsDServer server = new DummyStatsDServer(STATSD_SERVER_PORT);
final NonBlockingStatsDClient empty_prefix_client = new NonBlockingStatsDClient("my.prefix", "localhost", STATSD_SERVER_PORT, new String[] {"instance:foo", "app:bar"});
empty_prefix_client.gauge("value", 423, "baz");
server.waitForMessage();

assertThat(server.messagesReceived(), contains("my.prefix.value:423|g|#app:bar,instance:foo,baz"));
}

@Test(timeout=5000L) public void
sends_gauge_constant_tags_only() throws Exception {
final DummyStatsDServer server = new DummyStatsDServer(STATSD_SERVER_PORT);
final NonBlockingStatsDClient empty_prefix_client = new NonBlockingStatsDClient("my.prefix", "localhost", STATSD_SERVER_PORT, new String[] {"instance:foo", "app:bar"});
empty_prefix_client.gauge("value", 423);
server.waitForMessage();

assertThat(server.messagesReceived(), contains("my.prefix.value:423|g|#app:bar,instance:foo"));
}

@Test(timeout=5000L) public void
sends_gauge_empty_prefix() throws Exception {
final DummyStatsDServer server = new DummyStatsDServer(STATSD_SERVER_PORT);
Expand Down