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
COMMON-1195 : support posting events
  • Loading branch information
Avishai Weissberg committed Mar 2, 2015
commit 6afa75cc1e6993f815ce544c8739cd32ab5acb9e
166 changes: 166 additions & 0 deletions src/main/java/com/timgroup/statsd/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package com.timgroup.statsd;

import java.util.Date;

/**
* An event to send
* @see <a href="http://docs.datadoghq.com/guides/dogstatsd/#events">http://docs.datadoghq.com/guides/dogstatsd/#events</a>
*/
public class Event {
private String title;
private String text;
private long millisSinceEpoch = -1;
private String hostname;
private String aggregationKey;
private String priority;
private String sourceTypeName;
private String alertType;

public String getTitle() {
return title;
}

public String getText() {
return text;
}

/**
* @return -1 if not set
*/
public long getMillisSinceEpoch() {
return millisSinceEpoch;
}

public String getHostname() {
return hostname;
}

public String getAggregationKey() {
return aggregationKey;
}

public String getPriority() {
return priority;
}

public String getSourceTypeName() {
return sourceTypeName;
}

public String getAlertType() {
return alertType;
}

public static Builder builder() {
return new Builder();
}

private Event(){}

public enum Priority {
LOW, NORMAL
}

public enum AlertType {
ERROR, WARNING, INFO, SUCCESS
}

@SuppressWarnings({"AccessingNonPublicFieldOfAnotherObject", "PrivateMemberAccessBetweenOuterAndInnerClass", "ParameterHidesMemberVariable"})
public static class Builder {
private final Event event = new Event();
private Builder() {}

public Event build() {
if ((event.title == null) || event.title.isEmpty()) {
throw new IllegalStateException("event title must be set");
}
if ((event.text == null) || event.text.isEmpty()) {
throw new IllegalStateException("event text must be set");
}
return event;
}

/**
* @param title
* Event title ; mandatory
*/
public Builder withTitle(final String title) {
event.title = title;
return this;
}

/**
* @param text
* Event text ; supports line breaks ; mandatory
*/
public Builder withText(final String text) {
event.text = text;
return this;
}

/**
* @param date
* Assign a timestamp to the event ; Default: none (Default is the current Unix epoch timestamp when not sent)
*/
public Builder withDate(final Date date) {
event.millisSinceEpoch = date.getTime();
return this;
}

/**
* @param millisSinceEpoch
* Assign a timestamp to the event ; Default: none (Default is the current Unix epoch timestamp when not sent)
*/
public Builder withDate(final long millisSinceEpoch) {
event.millisSinceEpoch = millisSinceEpoch;
return this;
}

/**
* @param hostname
* Assign a hostname to the event ; Default: none
*/
public Builder withHostname(final String hostname) {
event.hostname = hostname;
return this;
}

/**
* @param aggregationKey
* Assign an aggregation key to the event, to group it with some others ; Default: none
*/
public Builder withAggregationKey(final String aggregationKey) {
event.aggregationKey = aggregationKey;
return this;
}

/**
* @param priority
* Can be "normal" or "low" ; Default: "normal"
*/
public Builder withPriority(final Priority priority) {
//noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
event.priority = priority.name().toLowerCase();
return this;
}

/**
* @param sourceTypeName
* Assign a source type to the event ; Default: none
*/
public Builder withSourceTypeName(final String sourceTypeName) {
event.sourceTypeName = sourceTypeName;
return this;
}

/**
* @param alertType
* Can be "error", "warning", "info" or "success" ; Default: "info"
*/
public Builder withAlertType(final AlertType alertType) {
//noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
event.alertType = alertType.name().toLowerCase();
return this;
}
}
}
1 change: 1 addition & 0 deletions src/main/java/com/timgroup/statsd/NoOpStatsDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public final class NoOpStatsDClient implements StatsDClient {
@Override public void histogram(String aspect, double value, String... tags) { }
@Override public void recordHistogramValue(String aspect, long value, String... tags) { }
@Override public void histogram(String aspect, long value, String... tags) { }
@Override public void recordEvent(final Event event, final String... tags) { }
}
54 changes: 54 additions & 0 deletions src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* <li>{@link #recordGaugeValue} - records the latest fixed value for the specified named gauge</li>
* <li>{@link #recordExecutionTime} - records an execution time in milliseconds for the specified named operation</li>
* <li>{@link #recordHistogramValue} - records a value, to be tracked with average, maximum, and percentiles</li>
* <li>{@link #recordEvent} - records an event</li>
* </ul>
* From the perspective of the application, these methods are non-blocking, with the resulting
* IO operations being carried out in a separate thread. Furthermore, these methods are guaranteed
Expand Down Expand Up @@ -437,6 +438,59 @@ public void histogram(String aspect, long value, String... tags) {
recordHistogramValue(aspect, value, tags);
}

private String eventMap(final Event event) {
final StringBuilder res = new StringBuilder("");

final long millisSinceEpoch = event.getMillisSinceEpoch();
if (millisSinceEpoch != -1) {
res.append("|d:").append(millisSinceEpoch / 1000);
}

final String hostname = event.getHostname();
if (hostname != null) {
res.append("|h:").append(hostname);
}

final String aggregationKey = event.getAggregationKey();
if (aggregationKey != null) {
res.append("|k:").append(aggregationKey);
}

final String priority = event.getPriority();
if (priority != null) {
res.append("|p:").append(priority);
}

final String alertType = event.getAlertType();
if (alertType != null) {
res.append("|t:").append(alertType);
}

return res.toString();
}

/**
* Records an event
*
* <p>This method is a DataDog extension, and may not work with other servers.</p>
*
* <p>This method is non-blocking and is guaranteed not to throw an exception.</p>
*
* @param event
* The event to record
* @param tags
* array of tags to be added to the data
*
* @see <a href="http://docs.datadoghq.com/guides/dogstatsd/#events-1">http://docs.datadoghq.com/guides/dogstatsd/#events-1</a>
*/
@Override
public void recordEvent(final Event event, final String... tags) {
final String title = prefix + event.getTitle();
final String text = event.getText();
send(String.format("_e{%d,%d}:%s|%s%s%s",
title.length(), text.length(), title, text, eventMap(event), tagString(tags)));
}

private void send(String message) {
queue.offer(message);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/timgroup/statsd/StatsDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,19 @@ public interface StatsDClient {
*/
void histogram(String aspect, long value, String... tags);

/**
* Records an event
*
* <p>This method is a DataDog extension, and may not work with other servers.</p>
*
* <p>This method is non-blocking and is guaranteed not to throw an exception.</p>
*
* @param event
* The event to record
* @param tags
* array of tags to be added to the data
*
* @see <a href="http://docs.datadoghq.com/guides/dogstatsd/#events-1">http://docs.datadoghq.com/guides/dogstatsd/#events-1</a>
*/
void recordEvent(Event event, String... tags);
}
83 changes: 83 additions & 0 deletions src/test/java/com/timgroup/statsd/EventTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.timgroup.statsd;

import org.junit.Test;

import java.util.Date;

import static org.junit.Assert.assertEquals;

public class EventTest {
@Test
public void builds() {
final Event event = Event.builder()
.withTitle("title1")
.withText("text1")
.withDate(1234)
.withHostname("host1")
.withPriority(Event.Priority.LOW)
.withAggregationKey("key1")
.withAlertType(Event.AlertType.ERROR)
.build();

assertEquals("title1", event.getTitle());
assertEquals("text1", event.getText());
assertEquals(1234, event.getMillisSinceEpoch());
assertEquals("host1", event.getHostname());
assertEquals("low", event.getPriority());
assertEquals("key1", event.getAggregationKey());
assertEquals("error", event.getAlertType());
}

@Test
public void builds_with_defaults() {
final Event event = Event.builder()
.withTitle("title1")
.withText("text1")
.build();

assertEquals("title1", event.getTitle());
assertEquals("text1", event.getText());
assertEquals(-1, event.getMillisSinceEpoch());
assertEquals(null, event.getHostname());
assertEquals(null, event.getPriority());
assertEquals(null, event.getAggregationKey());
assertEquals(null, event.getAlertType());
}

@Test (expected = IllegalStateException.class)
public void fails_without_title() {
Event.builder().withText("text1")
.withDate(1234)
.withHostname("host1")
.withPriority(Event.Priority.LOW)
.withAggregationKey("key1")
.withAlertType(Event.AlertType.ERROR)
.build();
}

@Test (expected = IllegalStateException.class)
public void fails_without_text() {
Event.builder().withTitle("title1")
.withDate(1234)
.withHostname("host1")
.withPriority(Event.Priority.LOW)
.withAggregationKey("key1")
.withAlertType(Event.AlertType.ERROR)
.build();
}

@Test
public void builds_with_date() {
final long expectedMillis = 1234567000;
final Date date = new Date(expectedMillis);
final Event event = Event.builder()
.withTitle("title1")
.withText("text1")
.withDate(date)
.build();

assertEquals("title1", event.getTitle());
assertEquals("text1", event.getText());
assertEquals(expectedMillis, event.getMillisSinceEpoch());
}
}
Loading