Bump java-dogstatsd-client from 2.13.0 to 4.0.0 (#12353)

* Bump java-dogstatsd-client from 2.13.0 to 4.0.0
Bumps [java-dogstatsd-client](https://github.com/DataDog/java-dogstatsd-client) from 2.13.0 to 4.0.0.
- [Release notes](https://github.com/DataDog/java-dogstatsd-client/releases)
- [Changelog](https://github.com/DataDog/java-dogstatsd-client/blob/master/CHANGELOG.md)
- [Commits](https://github.com/DataDog/java-dogstatsd-client/compare/v2.13.0...v4.0.0)

* migrate statsd-emitter tests from easymock to mockito
* add simple init test to make diff coverage happy

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xavier Léauté <xvrl@apache.org>
This commit is contained in:
dependabot[bot] 2022-03-26 16:25:13 -07:00 committed by GitHub
parent ea51d8a16c
commit ee44fe45c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 44 deletions

View File

@ -41,7 +41,7 @@
<dependency> <dependency>
<groupId>com.datadoghq</groupId> <groupId>com.datadoghq</groupId>
<artifactId>java-dogstatsd-client</artifactId> <artifactId>java-dogstatsd-client</artifactId>
<version>2.13.0</version> <version>4.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.code.findbugs</groupId> <groupId>com.google.code.findbugs</groupId>
@ -84,8 +84,8 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.easymock</groupId> <groupId>org.mockito</groupId>
<artifactId>easymock</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.timgroup.statsd.Event.AlertType; import com.timgroup.statsd.Event.AlertType;
import com.timgroup.statsd.NonBlockingStatsDClient; import com.timgroup.statsd.NonBlockingStatsDClient;
import com.timgroup.statsd.NonBlockingStatsDClientBuilder;
import com.timgroup.statsd.StatsDClient; import com.timgroup.statsd.StatsDClient;
import com.timgroup.statsd.StatsDClientErrorHandler; import com.timgroup.statsd.StatsDClientErrorHandler;
import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.StringUtils;
@ -57,12 +58,12 @@ public class StatsDEmitter implements Emitter
static StatsDEmitter of(StatsDEmitterConfig config, ObjectMapper mapper) static StatsDEmitter of(StatsDEmitterConfig config, ObjectMapper mapper)
{ {
NonBlockingStatsDClient client = new NonBlockingStatsDClient( NonBlockingStatsDClient client = new NonBlockingStatsDClientBuilder()
config.getPrefix(), .prefix(config.getPrefix())
config.getHostname(), .hostname(config.getHostname())
config.getPort(), .port(config.getPort())
config.isDogstatsd() ? config.getDogstatsdConstantTags().toArray(new String[0]) : EMPTY_ARRAY, .constantTags(config.isDogstatsd() ? config.getDogstatsdConstantTags().toArray(new String[0]) : EMPTY_ARRAY)
new StatsDClientErrorHandler() .errorHandler(new StatsDClientErrorHandler()
{ {
private int exceptionCount = 0; private int exceptionCount = 0;
@ -74,8 +75,8 @@ public class StatsDEmitter implements Emitter
} }
exceptionCount += 1; exceptionCount += 1;
} }
} })
); .build();
return new StatsDEmitter(config, mapper, client); return new StatsDEmitter(config, mapper, client);
} }

View File

@ -20,6 +20,7 @@
package org.apache.druid.emitter.statsd; package org.apache.druid.emitter.statsd;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.timgroup.statsd.Event; import com.timgroup.statsd.Event;
import com.timgroup.statsd.StatsDClient; import com.timgroup.statsd.StatsDClient;
@ -27,62 +28,61 @@ import org.apache.druid.java.util.common.DateTimes;
import org.apache.druid.java.util.emitter.service.AlertBuilder; import org.apache.druid.java.util.emitter.service.AlertBuilder;
import org.apache.druid.java.util.emitter.service.AlertEvent; import org.apache.druid.java.util.emitter.service.AlertEvent;
import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
public class StatsDEmitterTest public class StatsDEmitterTest
{ {
@Test @Test
public void testConvertRange() public void testConvertRange()
{ {
StatsDClient client = EasyMock.createMock(StatsDClient.class); StatsDClient client = mock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter( StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, null, null, null, null), new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, null, null, null, null),
new ObjectMapper(), new ObjectMapper(),
client client
); );
client.gauge("broker.query.cache.total.hitRate", 54); client.gauge("broker.query.cache.total.hitRate", 54);
EasyMock.replay(client);
emitter.emit(new ServiceMetricEvent.Builder() emitter.emit(new ServiceMetricEvent.Builder()
.setDimension("dataSource", "data-source") .setDimension("dataSource", "data-source")
.build(DateTimes.nowUtc(), "query/cache/total/hitRate", 0.54) .build(DateTimes.nowUtc(), "query/cache/total/hitRate", 0.54)
.build("broker", "brokerHost1") .build("broker", "brokerHost1")
); );
EasyMock.verify(client);
} }
@Test @Test
public void testConvertRangeWithDogstatsd() public void testConvertRangeWithDogstatsd()
{ {
StatsDClient client = EasyMock.createMock(StatsDClient.class); StatsDClient client = mock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter( StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, true, null, null, null), new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, true, null, null, null),
new ObjectMapper(), new ObjectMapper(),
client client
); );
client.gauge("broker.query.cache.total.hitRate", 0.54); client.gauge("broker.query.cache.total.hitRate", 0.54);
EasyMock.replay(client);
emitter.emit(new ServiceMetricEvent.Builder() emitter.emit(new ServiceMetricEvent.Builder()
.setDimension("dataSource", "data-source") .setDimension("dataSource", "data-source")
.build(DateTimes.nowUtc(), "query/cache/total/hitRate", 0.54) .build(DateTimes.nowUtc(), "query/cache/total/hitRate", 0.54)
.build("broker", "brokerHost1") .build("broker", "brokerHost1")
); );
EasyMock.verify(client);
} }
@Test @Test
public void testNoConvertRange() public void testNoConvertRange()
{ {
StatsDClient client = EasyMock.createMock(StatsDClient.class); StatsDClient client = mock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter( StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, null, null, null, null), new StatsDEmitterConfig("localhost", 8888, null, null, null, null, null, null, null, null, null),
new ObjectMapper(), new ObjectMapper(),
client client
); );
client.time("broker.query.time.data-source.groupBy", 10); client.time("broker.query.time.data-source.groupBy", 10);
EasyMock.replay(client);
emitter.emit(new ServiceMetricEvent.Builder() emitter.emit(new ServiceMetricEvent.Builder()
.setDimension("dataSource", "data-source") .setDimension("dataSource", "data-source")
.setDimension("type", "groupBy") .setDimension("type", "groupBy")
@ -97,20 +97,18 @@ public class StatsDEmitterTest
.build(DateTimes.nowUtc(), "query/time", 10) .build(DateTimes.nowUtc(), "query/time", 10)
.build("broker", "brokerHost1") .build("broker", "brokerHost1")
); );
EasyMock.verify(client);
} }
@Test @Test
public void testConfigOptions() public void testConfigOptions()
{ {
StatsDClient client = EasyMock.createMock(StatsDClient.class); StatsDClient client = mock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter( StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, "#", true, null, null, null, null, null, null), new StatsDEmitterConfig("localhost", 8888, null, "#", true, null, null, null, null, null, null),
new ObjectMapper(), new ObjectMapper(),
client client
); );
client.time("brokerHost1#broker#query#time#data-source#groupBy", 10); client.time("brokerHost1#broker#query#time#data-source#groupBy", 10);
EasyMock.replay(client);
emitter.emit(new ServiceMetricEvent.Builder() emitter.emit(new ServiceMetricEvent.Builder()
.setDimension("dataSource", "data-source") .setDimension("dataSource", "data-source")
.setDimension("type", "groupBy") .setDimension("type", "groupBy")
@ -125,13 +123,12 @@ public class StatsDEmitterTest
.build(DateTimes.nowUtc(), "query/time", 10) .build(DateTimes.nowUtc(), "query/time", 10)
.build("broker", "brokerHost1") .build("broker", "brokerHost1")
); );
EasyMock.verify(client);
} }
@Test @Test
public void testDogstatsdEnabled() public void testDogstatsdEnabled()
{ {
StatsDClient client = EasyMock.createMock(StatsDClient.class); StatsDClient client = mock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter( StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, "#", true, null, null, true, null, null, null), new StatsDEmitterConfig("localhost", 8888, null, "#", true, null, null, true, null, null, null),
new ObjectMapper(), new ObjectMapper(),
@ -140,7 +137,6 @@ public class StatsDEmitterTest
client.time("broker#query#time", 10, client.time("broker#query#time", 10,
"dataSource:data-source", "type:groupBy", "hostname:brokerHost1" "dataSource:data-source", "type:groupBy", "hostname:brokerHost1"
); );
EasyMock.replay(client);
emitter.emit(new ServiceMetricEvent.Builder() emitter.emit(new ServiceMetricEvent.Builder()
.setDimension("dataSource", "data-source") .setDimension("dataSource", "data-source")
.setDimension("type", "groupBy") .setDimension("type", "groupBy")
@ -155,32 +151,29 @@ public class StatsDEmitterTest
.build(DateTimes.nowUtc(), "query/time", 10) .build(DateTimes.nowUtc(), "query/time", 10)
.build("broker", "brokerHost1") .build("broker", "brokerHost1")
); );
EasyMock.verify(client);
} }
@Test @Test
public void testBlankHolderOptions() public void testBlankHolderOptions()
{ {
StatsDClient client = EasyMock.createMock(StatsDClient.class); StatsDClient client = mock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter( StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, true, null, null, null, null, null, null), new StatsDEmitterConfig("localhost", 8888, null, null, true, null, null, null, null, null, null),
new ObjectMapper(), new ObjectMapper(),
client client
); );
client.count("brokerHost1.broker.jvm.gc.count.G1-GC", 1); client.count("brokerHost1.broker.jvm.gc.count.G1-GC", 1);
EasyMock.replay(client);
emitter.emit(new ServiceMetricEvent.Builder() emitter.emit(new ServiceMetricEvent.Builder()
.setDimension("gcName", "G1 GC") .setDimension("gcName", "G1 GC")
.build(DateTimes.nowUtc(), "jvm/gc/count", 1) .build(DateTimes.nowUtc(), "jvm/gc/count", 1)
.build("broker", "brokerHost1") .build("broker", "brokerHost1")
); );
EasyMock.verify(client);
} }
@Test @Test
public void testServiceAsTagOption() public void testServiceAsTagOption()
{ {
StatsDClient client = EasyMock.createMock(StatsDClient.class); StatsDClient client = mock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter( StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, true, null, null, true, null, true, null), new StatsDEmitterConfig("localhost", 8888, null, null, true, null, null, true, null, true, null),
new ObjectMapper(), new ObjectMapper(),
@ -189,20 +182,18 @@ public class StatsDEmitterTest
client.time("druid.query.time", 10, client.time("druid.query.time", 10,
"druid_service:druid/broker", "dataSource:data-source", "type:groupBy", "hostname:brokerHost1" "druid_service:druid/broker", "dataSource:data-source", "type:groupBy", "hostname:brokerHost1"
); );
EasyMock.replay(client);
emitter.emit(new ServiceMetricEvent.Builder() emitter.emit(new ServiceMetricEvent.Builder()
.setDimension("dataSource", "data-source") .setDimension("dataSource", "data-source")
.setDimension("type", "groupBy") .setDimension("type", "groupBy")
.build(DateTimes.nowUtc(), "query/time", 10) .build(DateTimes.nowUtc(), "query/time", 10)
.build("druid/broker", "brokerHost1") .build("druid/broker", "brokerHost1")
); );
EasyMock.verify(client);
} }
@Test @Test
public void testAlertEvent() public void testAlertEvent()
{ {
StatsDClient client = EasyMock.createMock(StatsDClient.class); StatsDClient client = mock(StatsDClient.class);
StatsDEmitter emitter = new StatsDEmitter( StatsDEmitter emitter = new StatsDEmitter(
new StatsDEmitterConfig("localhost", 8888, null, null, true, null, null, true, null, true, true), new StatsDEmitterConfig("localhost", 8888, null, null, true, null, null, true, null, true, true),
new ObjectMapper(), new ObjectMapper(),
@ -216,20 +207,20 @@ public class StatsDEmitterTest
.withText("{\"exception\":\"NPE\"}") .withText("{\"exception\":\"NPE\"}")
.build(); .build();
Capture<Event> eventCapture = EasyMock.newCapture();
client.recordEvent(
EasyMock.capture(eventCapture),
EasyMock.eq("feed:alerts"), EasyMock.eq("druid_service:druid/broker"),
EasyMock.eq("severity:anomaly"), EasyMock.eq("hostname:brokerHost1")
);
EasyMock.replay(client);
emitter.emit(AlertBuilder.create("something bad happened [%s]", "exception") emitter.emit(AlertBuilder.create("something bad happened [%s]", "exception")
.severity(AlertEvent.Severity.ANOMALY) .severity(AlertEvent.Severity.ANOMALY)
.addData(ImmutableMap.of("exception", "NPE")) .addData(ImmutableMap.of("exception", "NPE"))
.build("druid/broker", "brokerHost1") .build("druid/broker", "brokerHost1")
); );
EasyMock.verify(client);
Event actualEvent = eventCapture.getValue(); final ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(client).recordEvent(
eventArgumentCaptor.capture(),
eq("feed:alerts"), eq("druid_service:druid/broker"),
eq("severity:anomaly"), eq("hostname:brokerHost1")
);
Event actualEvent = eventArgumentCaptor.getValue();
Assert.assertTrue(actualEvent.getMillisSinceEpoch() > 0); Assert.assertTrue(actualEvent.getMillisSinceEpoch() > 0);
Assert.assertEquals(expectedEvent.getPriority(), actualEvent.getPriority()); Assert.assertEquals(expectedEvent.getPriority(), actualEvent.getPriority());
Assert.assertEquals(expectedEvent.getAlertType(), actualEvent.getAlertType()); Assert.assertEquals(expectedEvent.getAlertType(), actualEvent.getAlertType());
@ -237,6 +228,27 @@ public class StatsDEmitterTest
Assert.assertEquals(expectedEvent.getText(), actualEvent.getText()); Assert.assertEquals(expectedEvent.getText(), actualEvent.getText());
} }
@Test
public void testInitialization()
{
final StatsDEmitterConfig config = new StatsDEmitterConfig(
"localhost",
8888,
"druid",
"-",
true,
null,
null,
true,
ImmutableList.of("tag1", "value1"),
true,
true
);
try (StatsDEmitter emitter = StatsDEmitter.of(config, new ObjectMapper())) {
}
}
@Test @Test
public void testJacksonModules() public void testJacksonModules()
{ {