use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class OpenTelemetryEmitterTest method testNoEmitNotServiceMetric.
// Check that we don't call "emitQueryTimeEvent" method for event that is not instance of ServiceMetricEvent
@Test
public void testNoEmitNotServiceMetric() {
final Event notServiceMetricEvent = new Event() {
@Override
public Map<String, Object> toMap() {
return Collections.emptyMap();
}
@Override
public String getFeed() {
return null;
}
};
emitter.emit(notServiceMetricEvent);
Assert.assertNull(noopExporter.spanDataCollection);
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class OpenTelemetryEmitterTest method testAttributes.
@Test
public void testAttributes() {
final Map<String, String> context = new HashMap<>();
final String expectedAttributeKey = "attribute";
final String expectedAttributeValue = "value";
context.put(expectedAttributeKey, expectedAttributeValue);
final ServiceMetricEvent queryTimeMetricWithAttributes = new ServiceMetricEvent.Builder().setDimension("context", context).build(TIMESTAMP, "query/time", 100).build("druid/broker", "host");
emitter.emit(queryTimeMetricWithAttributes);
SpanData actualSpanData = noopExporter.spanDataCollection.iterator().next();
Assert.assertEquals(1, actualSpanData.getAttributes().size());
Assert.assertEquals(expectedAttributeValue, actualSpanData.getAttributes().get(AttributeKey.stringKey(expectedAttributeKey)));
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class OpenTelemetryEmitterTest method testErrorStatus.
@Test
public void testErrorStatus() {
final ServiceMetricEvent queryTimeMetric = new ServiceMetricEvent.Builder().setDimension("success", "false").build(TIMESTAMP, "query/time", 100).build("druid/broker", "host");
emitter.emit(queryTimeMetric);
SpanData actualSpanData = noopExporter.spanDataCollection.iterator().next();
Assert.assertEquals(StatusCode.ERROR, actualSpanData.getStatus().getStatusCode());
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
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 druid-io.
the class WhiteListBasedConverterTest method testWhiteListedStringArrayDimension.
@Test
public void testWhiteListedStringArrayDimension() throws IOException {
File mapFile = File.createTempFile("testing-" + System.nanoTime(), ".json");
mapFile.deleteOnExit();
try (OutputStream outputStream = new FileOutputStream(mapFile)) {
IOUtils.copyLarge(getClass().getResourceAsStream("/testWhiteListedStringArrayDimension.json"), outputStream);
}
WhiteListBasedConverter converter = new WhiteListBasedConverter(prefix, false, false, false, mapFile.getAbsolutePath(), new DefaultObjectMapper());
ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("gcName", new String[] { "g1" }).build(createdTime, "jvm/gc/cpu", 10).build(serviceName, hostname);
GraphiteEvent graphiteEvent = converter.druidEventToGraphite(event);
Assert.assertNotNull(graphiteEvent);
Assert.assertEquals(defaultNamespace + ".g1.jvm/gc/cpu", graphiteEvent.getEventPath());
}
Aggregations