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

Changes from 2 commits
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
103 changes: 87 additions & 16 deletions src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.charset.Charset;
Expand All @@ -11,6 +12,7 @@
import java.text.NumberFormat;
import java.util.Locale;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
Expand Down Expand Up @@ -118,7 +120,7 @@ protected NumberFormat initialValue() {
* if the client could not be started
*/
public NonBlockingStatsDClient(String prefix, String hostname, int port) throws StatsDClientException {
this(prefix, hostname, port, null, NO_OP_HANDLER);
this(prefix, hostname, port, null, null);
}

/**
Expand All @@ -143,7 +145,7 @@ public NonBlockingStatsDClient(String prefix, String hostname, int port) throws
* 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);
this(prefix, hostname, port, constantTags, null);
}

/**
Expand All @@ -166,17 +168,48 @@ public NonBlockingStatsDClient(String prefix, String hostname, int port, String.
* @param constantTags
* tags to be added to all content sent
* @param errorHandler
* handler to use when an exception occurs during usage
* handler to use when an exception occurs during usage, may be null to indicate noop
* @throws StatsDClientException
* if the client could not be started
*/
public NonBlockingStatsDClient(String prefix, String hostname, int port, String[] constantTags, StatsDClientErrorHandler errorHandler) throws StatsDClientException {
public NonBlockingStatsDClient(String prefix, final String hostname, final int port, String[] constantTags, StatsDClientErrorHandler errorHandler) throws StatsDClientException {
this(prefix, constantTags, errorHandler, staticStatsDAddressResolution(hostname, port));
}

/**
* 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 passed to the specified
* handler and then 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 constantTags
* tags to be added to all content sent
* @param errorHandler
* handler to use when an exception occurs during usage, may be null to indicate noop
* @param addressLookup
* yields the IP address and socket of the StatsD server
* @throws StatsDClientException
* if the client could not be started
*/
public NonBlockingStatsDClient(String prefix, String[] constantTags, StatsDClientErrorHandler errorHandler, Callable<InetSocketAddress> addressLookup) throws StatsDClientException {
if(prefix != null && prefix.length() > 0) {
this.prefix = String.format("%s.", prefix);
} else {
this.prefix = "";
}
this.handler = errorHandler;
if(errorHandler == null) {
this.handler = NO_OP_HANDLER;
}
else {
this.handler = errorHandler;
}

/* Empty list should be null for faster comparison */
if(constantTags != null && constantTags.length == 0) {
Expand All @@ -194,7 +227,7 @@ public NonBlockingStatsDClient(String prefix, String hostname, int port, String[
} catch (Exception e) {
throw new StatsDClientException("Failed to start StatsD client", e);
}
this.executor.submit(new QueueConsumer(hostname,port));
this.executor.submit(new QueueConsumer(addressLookup));
}

/**
Expand Down Expand Up @@ -552,29 +585,28 @@ private void send(String message) {
private class QueueConsumer implements Runnable {
private final ByteBuffer sendBuffer = ByteBuffer.allocate(PACKET_SIZE_BYTES);

private String hostname;
private int port;
private final Callable<InetSocketAddress> addressLookup;

public QueueConsumer(String hostname, int port) {
this.hostname = hostname;
this.port = port;
public QueueConsumer(Callable<InetSocketAddress> addressLookup) {
this.addressLookup = addressLookup;
}

@Override public void run() {
while(!executor.isShutdown()) {
try {
String message = queue.poll(1, TimeUnit.SECONDS);
if(null != message) {
InetSocketAddress address = this.addressLookup.call();
byte[] data = message.getBytes(MESSAGE_CHARSET);
if(sendBuffer.remaining() < (data.length + 1)) {
blockingSend();
blockingSend(address);
}
if(sendBuffer.position() > 0) {
sendBuffer.put( (byte) '\n');
}
sendBuffer.put(data);
if(null == queue.peek()) {
blockingSend();
blockingSend(address);
}
}
} catch (Exception e) {
Expand All @@ -583,12 +615,10 @@ public QueueConsumer(String hostname, int port) {
}
}

private void blockingSend() throws IOException {
private void blockingSend(InetSocketAddress address) throws IOException {
int sizeOfBuffer = sendBuffer.position();
sendBuffer.flip();

InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(this.hostname),this.port);

int sentBytes = clientChannel.send(sendBuffer, address);
sendBuffer.limit(sendBuffer.capacity());
sendBuffer.rewind();
Expand All @@ -606,4 +636,45 @@ private void blockingSend() throws IOException {
}
}
}

/**
* Create dynamic lookup for the given host name and port.
*
* @param hostname the host name of the targeted StatsD server
* @param port the port of the targeted StatsD server
* @return a function to perform the lookup
* @see NonBlockingStatsDClient#NonBlockingStatsDClient(String, String[], StatsDClientErrorHandler, Callable)
*/
public static Callable<InetSocketAddress> volatileAddressResolution(final String hostname, final int port) {
return new Callable<InetSocketAddress>() {
@Override public InetSocketAddress call() throws Exception {
return new InetSocketAddress(InetAddress.getByName(hostname), port);
}
};
}

/**
* Lookup the address for the given host name and cache the result.
*
* @param hostname the host name of the targeted StatsD server
* @param port the port of the targeted StatsD server
* @return a function that cached the result of the lookup
* @throws Exception if the lookup fails, i.e. {@link UnknownHostException}
*/
public static Callable<InetSocketAddress> staticAddressResolution(String hostname, int port) throws Exception {
final InetSocketAddress address = volatileAddressResolution(hostname, port).call();
return new Callable<InetSocketAddress>() {
@Override public InetSocketAddress call() throws Exception {
return address;
}
};
}

private static Callable<InetSocketAddress> staticStatsDAddressResolution(String hostname, int port) throws StatsDClientException {
try {
return staticAddressResolution(hostname, port);
} catch (Exception e) {
throw new StatsDClientException("Failed to lookup StatsD host", e);
}
}
}