use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class EventConverterTest method testConvertWithoutNamespacePrefix.
@Test
public void testConvertWithoutNamespacePrefix() {
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 = converterWithoutNamespacePrefix.convert(configuredEvent);
Assert.assertEquals("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(converterWithoutNamespacePrefix.convert(notConfiguredEvent));
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class PrometheusEmitterTest method testEmitterPush.
@Test
public void testEmitterPush() throws IOException {
PrometheusEmitterConfig emitterConfig = new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.pushgateway, "namespace3", null, 0, "pushgateway");
PushGateway mockPushGateway = mock(PushGateway.class);
mockPushGateway.push(anyObject(Collector.class), anyString(), anyObject(ImmutableMap.class));
PrometheusEmitter emitter = new PrometheusEmitter(emitterConfig);
emitter.start();
emitter.setPushGateway(mockPushGateway);
ServiceMetricEvent build = ServiceMetricEvent.builder().setDimension("task", "index_parallel").build("task/run/time", 500).build(ImmutableMap.of("service", "peon"));
emitter.emit(build);
emitter.flush();
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class OpenTelemetryEmitter method emit.
@Override
public void emit(Event e) {
if (!(e instanceof ServiceMetricEvent)) {
return;
}
ServiceMetricEvent event = (ServiceMetricEvent) e;
// query/time
if (!event.getMetric().equals("query/time")) {
return;
}
emitQueryTimeEvent(event);
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class OpenTelemetryEmitterTest method testTraceparentId.
@Test
public void testTraceparentId() {
final String traceId = "00-54ef39243e3feb12072e0f8a74c1d55a-ad6d5b581d7c29c1-01";
final String expectedParentTraceId = "54ef39243e3feb12072e0f8a74c1d55a";
final String expectedParentSpanId = "ad6d5b581d7c29c1";
final Map<String, String> context = new HashMap<>();
context.put("traceparent", traceId);
final String serviceName = "druid/broker";
final DateTime createdTime = TIMESTAMP;
final long metricValue = 100;
final ServiceMetricEvent queryTimeMetric = new ServiceMetricEvent.Builder().setDimension("context", context).build(createdTime, "query/time", metricValue).build(serviceName, "host");
emitter.emit(queryTimeMetric);
Assert.assertEquals(1, noopExporter.spanDataCollection.size());
SpanData actualSpanData = noopExporter.spanDataCollection.iterator().next();
Assert.assertEquals(serviceName, actualSpanData.getName());
Assert.assertEquals((createdTime.getMillis() - metricValue) * 1_000_000, actualSpanData.getStartEpochNanos());
Assert.assertEquals(expectedParentTraceId, actualSpanData.getParentSpanContext().getTraceId());
Assert.assertEquals(expectedParentSpanId, actualSpanData.getParentSpanContext().getSpanId());
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
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);
}
Aggregations