use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class EventConverterTest method testConvertWithNamespacePrefix.
@Test
public void testConvertWithNamespacePrefix() {
DateTime dateTime = DateTimes.nowUtc();
ServiceMetricEvent configuredEvent = new ServiceMetricEvent.Builder().setDimension("dataSource", "foo:bar").setDimension("type", "groupBy").build(dateTime, "query/time", 10).build("druid:broker", "127.0.0.1:8080");
Map<String, Object> expectedTags = new HashMap<>();
expectedTags.put("service", "druid_broker");
expectedTags.put("host", "127.0.0.1_8080");
expectedTags.put("dataSource", "foo_bar");
expectedTags.put("type", "groupBy");
OpentsdbEvent opentsdbEvent = converterWithNamespacePrefix.convert(configuredEvent);
Assert.assertEquals("druid.query.time", opentsdbEvent.getMetric());
Assert.assertEquals(dateTime.getMillis() / 1000L, opentsdbEvent.getTimestamp());
Assert.assertEquals(10, opentsdbEvent.getValue());
Assert.assertEquals(expectedTags, opentsdbEvent.getTags());
ServiceMetricEvent notConfiguredEvent = new ServiceMetricEvent.Builder().setDimension("dataSource", "data-source").setDimension("type", "groupBy").build(dateTime, "foo/bar", 10).build("broker", "brokerHost1");
Assert.assertNull(converterWithNamespacePrefix.convert(notConfiguredEvent));
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class DimensionConverterTest method testConvert.
@Test
public void testConvert() {
DimensionConverter dimensionConverter = new DimensionConverter(new ObjectMapper(), null);
ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("dataSource", "data-source").setDimension("type", "groupBy").setDimension("interval", "2013/2015").setDimension("some_random_dim1", "random_dim_value1").setDimension("some_random_dim2", "random_dim_value2").setDimension("hasFilters", "no").setDimension("duration", "P1D").setDimension("remoteAddress", "194.0.90.2").setDimension("id", "ID").setDimension("context", "{context}").build(DateTimes.nowUtc(), "query/time", 10).build("broker", "brokerHost1");
ImmutableMap.Builder<String, String> actual = new ImmutableMap.Builder<>();
StatsDMetric statsDMetric = dimensionConverter.addFilteredUserDims(event.getService(), event.getMetric(), event.getUserDims(), actual);
Assert.assertEquals("correct StatsDMetric.Type", StatsDMetric.Type.timer, statsDMetric.type);
ImmutableMap.Builder<String, String> expected = new ImmutableMap.Builder<>();
expected.put("dataSource", "data-source");
expected.put("type", "groupBy");
Assert.assertEquals("correct Dimensions", expected.build(), actual.build());
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class DropwizardEmitter method emit.
@Override
public void emit(Event event) {
synchronized (started) {
if (!started.get()) {
throw new RejectedExecutionException("Dropwizard emitter Service not started.");
}
}
if (event instanceof ServiceMetricEvent) {
ServiceMetricEvent metricEvent = (ServiceMetricEvent) event;
String host = metricEvent.getHost();
String service = metricEvent.getService();
String metric = metricEvent.getMetric();
Map<String, Object> userDims = metricEvent.getUserDims();
Number value = metricEvent.getValue();
ImmutableList.Builder<String> nameBuilder = new ImmutableList.Builder<>();
LinkedHashMap<String, String> dims = new LinkedHashMap<>();
final DropwizardMetricSpec metricSpec = converter.addFilteredUserDims(service, metric, userDims, dims);
if (metricSpec != null) {
if (config.getPrefix() != null) {
nameBuilder.add(config.getPrefix());
}
nameBuilder.add(StringUtils.format("metric=%s", metric));
nameBuilder.add(StringUtils.format("service=%s", service));
if (config.getIncludeHost()) {
nameBuilder.add(StringUtils.format("hostname=%s", host));
}
dims.forEach((key, value1) -> nameBuilder.add(StringUtils.format("%s=%s", key, value1)));
String fullName = StringUtils.replaceChar(Joiner.on(",").join(nameBuilder.build()), '/', ".");
updateMetric(fullName, value, metricSpec);
} else {
log.debug("Service=[%s], Metric=[%s] has no mapping", service, metric);
}
} else if (event instanceof AlertEvent) {
for (Emitter emitter : alertEmitters) {
emitter.emit(event);
}
} else {
throw new ISE("unknown event type [%s]", event.getClass());
}
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class InfluxdbEmitterTest method testMetricIsInDimensionWhitelist.
@Test
public void testMetricIsInDimensionWhitelist() {
DateTime date = new DateTime(2017, 10, 30, 10, 00, // 10:00am on 30/10/2017 = 1509357600000000000 in epoch nanoseconds
DateTimeZone.UTC);
String metric = "metric/time";
Number value = 1234;
ImmutableMap<String, String> serviceDims = ImmutableMap.of("service", "druid/historical", "host", "localhost", "version", "0.10.0");
ServiceMetricEvent.Builder builder = ServiceMetricEvent.builder();
ServiceEventBuilder eventBuilder = builder.build(date, metric, value);
builder.setDimension("dataSource", "wikipedia");
builder.setDimension("taskType", "index");
ServiceMetricEvent event = (ServiceMetricEvent) eventBuilder.build(serviceDims);
InfluxdbEmitterConfig config = new InfluxdbEmitterConfig("localhost", 8086, null, null, null, null, "dbname", 10000, 15000, 30000, "adam", "password", ImmutableSet.of("dataSource"));
InfluxdbEmitter influxdbEmitter = new InfluxdbEmitter(config);
String expected = "druid_metric,service=druid/historical,hostname=localhost,dataSource=wikipedia druid_time=1234 1509357600000000000" + "\n";
String actual = influxdbEmitter.transformForInfluxSystems(event);
Assert.assertEquals(expected, actual);
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class InfluxdbEmitterTest method testTransformForInfluxWithShortMetric.
@Test
public void testTransformForInfluxWithShortMetric() {
DateTime date = new DateTime(2017, 10, 30, 10, 00, // 10:00am on 30/10/2017 = 1509357600000000000 in epoch nanoseconds
DateTimeZone.UTC);
String metric = "metric/time";
Number value = 1234;
ImmutableMap<String, String> serviceDims = ImmutableMap.of("service", "druid/historical", "host", "localhost", "version", "0.10.0");
ServiceMetricEvent.Builder builder = ServiceMetricEvent.builder();
ServiceEventBuilder eventBuilder = builder.build(date, metric, value);
ServiceMetricEvent event = (ServiceMetricEvent) eventBuilder.build(serviceDims);
InfluxdbEmitterConfig config = new InfluxdbEmitterConfig("localhost", 8086, null, null, null, null, "dbname", 10000, 15000, 30000, "adam", "password", null);
InfluxdbEmitter influxdbEmitter = new InfluxdbEmitter(config);
String expected = "druid_metric,service=druid/historical,hostname=localhost druid_time=1234 1509357600000000000" + "\n";
String actual = influxdbEmitter.transformForInfluxSystems(event);
Assert.assertEquals(expected, actual);
}
Aggregations