Search in sources :

Example 21 with ServiceMetricEvent

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));
}
Also used : HashMap(java.util.HashMap) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 22 with ServiceMetricEvent

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();
}
Also used : Collector(io.prometheus.client.Collector) PushGateway(io.prometheus.client.exporter.PushGateway) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 23 with ServiceMetricEvent

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);
}
Also used : ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent)

Example 24 with ServiceMetricEvent

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());
}
Also used : SpanData(io.opentelemetry.sdk.trace.data.SpanData) HashMap(java.util.HashMap) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 25 with ServiceMetricEvent

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);
}
Also used : ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Event(org.apache.druid.java.util.emitter.core.Event) Test(org.junit.Test)

Aggregations

ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)64 Test (org.junit.Test)56 DateTime (org.joda.time.DateTime)18 HashMap (java.util.HashMap)14 ServiceEventBuilder (org.apache.druid.java.util.emitter.service.ServiceEventBuilder)14 Emitter (org.apache.druid.java.util.emitter.core.Emitter)12 Event (org.apache.druid.java.util.emitter.core.Event)12 SpanData (io.opentelemetry.sdk.trace.data.SpanData)10 ImmutableMap (com.google.common.collect.ImmutableMap)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 OutputStream (java.io.OutputStream)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Parameters (junitparams.Parameters)4 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)4 AlertEvent (org.apache.druid.java.util.emitter.service.AlertEvent)4 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)4 ImmutableList (com.google.common.collect.ImmutableList)2