Search in sources :

Example 1 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class HistoricalMetricsMonitorTest method testSimple.

@Test
public void testSimple() {
    final long size = 5;
    final String dataSource = "dataSource";
    final DataSegment dataSegment = new DataSegment(dataSource, Intervals.of("2014/2015"), "version", ImmutableMap.of(), ImmutableList.of(), ImmutableList.of(), null, 1, size);
    final long maxSize = 10;
    final int priority = 111;
    final String tier = "tier";
    EasyMock.expect(druidServerConfig.getMaxSize()).andReturn(maxSize).once();
    EasyMock.expect(segmentLoadDropMgr.getPendingDeleteSnapshot()).andReturn(ImmutableList.of(dataSegment)).once();
    EasyMock.expect(druidServerConfig.getTier()).andReturn(tier).once();
    EasyMock.expect(druidServerConfig.getPriority()).andReturn(priority).once();
    EasyMock.expect(segmentManager.getDataSourceSizes()).andReturn(ImmutableMap.of(dataSource, size));
    EasyMock.expect(druidServerConfig.getTier()).andReturn(tier).once();
    EasyMock.expect(druidServerConfig.getPriority()).andReturn(priority).once();
    EasyMock.expect(druidServerConfig.getMaxSize()).andReturn(maxSize).times(2);
    EasyMock.expect(segmentManager.getDataSourceCounts()).andReturn(ImmutableMap.of(dataSource, 1L));
    EasyMock.expect(druidServerConfig.getTier()).andReturn(tier).once();
    EasyMock.expect(druidServerConfig.getPriority()).andReturn(priority).once();
    final HistoricalMetricsMonitor monitor = new HistoricalMetricsMonitor(druidServerConfig, segmentManager, segmentLoadDropMgr);
    final Capture<ServiceEventBuilder<ServiceMetricEvent>> eventCapture = EasyMock.newCapture(CaptureType.ALL);
    serviceEmitter.emit(EasyMock.capture(eventCapture));
    EasyMock.expectLastCall().times(5);
    EasyMock.replay(druidServerConfig, segmentManager, segmentLoadDropMgr, serviceEmitter);
    monitor.doMonitor(serviceEmitter);
    EasyMock.verify(druidServerConfig, segmentManager, segmentLoadDropMgr, serviceEmitter);
    final String host = "host";
    final String service = "service";
    Assert.assertTrue(eventCapture.hasCaptured());
    final List<Map<String, Object>> events = Lists.transform(eventCapture.getValues(), new Function<ServiceEventBuilder<ServiceMetricEvent>, Map<String, Object>>() {

        @Nullable
        @Override
        public Map<String, Object> apply(@Nullable ServiceEventBuilder<ServiceMetricEvent> input) {
            final HashMap<String, Object> map = new HashMap<>(input.build(service, host).toMap());
            Assert.assertNotNull(map.remove("feed"));
            Assert.assertNotNull(map.remove("timestamp"));
            Assert.assertNotNull(map.remove("service"));
            Assert.assertNotNull(map.remove("host"));
            return map;
        }
    });
    Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/max", "value", maxSize), events.get(0));
    Assert.assertEquals(ImmutableMap.<String, Object>of("dataSource", dataSource, "metric", "segment/pendingDelete", "priority", String.valueOf(priority), "tier", tier, "value", dataSegment.getSize()), events.get(1));
    Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/used", "value", dataSegment.getSize(), "tier", tier, "priority", String.valueOf(priority), "dataSource", dataSource), events.get(2));
    Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/usedPercent", "value", dataSegment.getSize() * 1.0D / maxSize, "tier", tier, "priority", String.valueOf(priority), "dataSource", dataSource), events.get(3));
    Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/count", "value", 1L, "tier", tier, "priority", String.valueOf(priority), "dataSource", dataSource), events.get(4));
}
Also used : ServiceEventBuilder(org.apache.druid.java.util.emitter.service.ServiceEventBuilder) HashMap(java.util.HashMap) DataSegment(org.apache.druid.timeline.DataSegment) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 2 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class ShuffleMonitorTest method testDoMonitor.

@Test
public void testDoMonitor() {
    final ShuffleMetrics shuffleMetrics = Mockito.mock(ShuffleMetrics.class);
    final PerDatasourceShuffleMetrics perDatasourceShuffleMetrics = new PerDatasourceShuffleMetrics();
    perDatasourceShuffleMetrics.accumulate(100);
    perDatasourceShuffleMetrics.accumulate(200);
    perDatasourceShuffleMetrics.accumulate(10);
    Mockito.when(shuffleMetrics.snapshotAndReset()).thenReturn(ImmutableMap.of("supervisor", perDatasourceShuffleMetrics));
    final StubServiceEmitter emitter = new StubServiceEmitter("service", "host");
    final ShuffleMonitor monitor = new ShuffleMonitor();
    monitor.setShuffleMetrics(shuffleMetrics);
    Assert.assertTrue(monitor.doMonitor(emitter));
    final List<Event> events = emitter.getEvents();
    Assert.assertEquals(2, events.size());
    Assert.assertSame(ServiceMetricEvent.class, events.get(0).getClass());
    ServiceMetricEvent event = (ServiceMetricEvent) events.get(0);
    Assert.assertEquals(ShuffleMonitor.SHUFFLE_BYTES_KEY, event.getMetric());
    Assert.assertEquals(310L, event.getValue());
    Assert.assertEquals(ImmutableMap.of(ShuffleMonitor.SUPERVISOR_TASK_ID_DIMENSION, "supervisor"), event.getUserDims());
    Assert.assertSame(ServiceMetricEvent.class, events.get(1).getClass());
    event = (ServiceMetricEvent) events.get(1);
    Assert.assertEquals(ShuffleMonitor.SHUFFLE_REQUESTS_KEY, event.getMetric());
    Assert.assertEquals(3, event.getValue());
    Assert.assertEquals(ImmutableMap.of(ShuffleMonitor.SUPERVISOR_TASK_ID_DIMENSION, "supervisor"), event.getUserDims());
}
Also used : StubServiceEmitter(org.apache.druid.java.util.metrics.StubServiceEmitter) PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Event(org.apache.druid.java.util.emitter.core.Event) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics) Test(org.junit.Test)

Example 3 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class WhiteListBasedDruidToTimelineEventConverterTest method testDefaultIsInWhiteList.

@Test
@Parameters({ "query/time, true", "query/node/ttfb, true", "query/segmentAndCache/time, true", "query/time/balaba, true", "query/tim, false", "segment/added/bytes, true", "segment/count, true", "segment/size, true", "segment/cost/raw, false", "coordinator/TIER_1 /cost/raw, false", "segment/Kost/raw, false", ", false", "word, false", "coordinator, false", "server/, false", "ingest/persists/time, true", "jvm/mem/init, true", "jvm/gc/count, true" })
public void testDefaultIsInWhiteList(String key, boolean expectedValue) {
    ServiceMetricEvent event = ServiceMetricEvent.builder().setFeed("metrics").build(createdTime, key, 10).build(serviceName, hostname);
    boolean isIn = defaultWhiteListBasedDruidToTimelineEventConverter.druidEventToTimelineMetric(event) != null;
    Assert.assertEquals(expectedValue, isIn);
}
Also used : ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 4 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

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

Example 5 with ServiceMetricEvent

use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class WhiteListBasedConverterTest method testDefaultIsInWhiteList.

@Test
@Parameters({ "query/time, true", "query/node/ttfb, true", "query/segmentAndCache/time, true", "query/time/balaba, true", "query/tim, false", "segment/added/bytes, false", "segment/count, true", "segment/size, true", "segment/cost/raw, false", "coordinator/TIER_1 /cost/raw, false", "segment/Kost/raw, false", ", false", "word, false", "coordinator, false", "server/, false", "ingest/persists/time, true", "jvm/mem/init, true", "jvm/gc/count, true" })
public void testDefaultIsInWhiteList(String key, boolean expectedValue) {
    ServiceMetricEvent event = ServiceMetricEvent.builder().build(createdTime, key, 10).build(serviceName, hostname);
    boolean isIn = defaultWhiteListBasedConverter.druidEventToGraphite(event) != null;
    Assert.assertEquals(expectedValue, isIn);
}
Also used : ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)30 Test (org.junit.Test)26 DateTime (org.joda.time.DateTime)9 HashMap (java.util.HashMap)7 Emitter (org.apache.druid.java.util.emitter.core.Emitter)6 Event (org.apache.druid.java.util.emitter.core.Event)6 SpanData (io.opentelemetry.sdk.trace.data.SpanData)5 ServiceEventBuilder (org.apache.druid.java.util.emitter.service.ServiceEventBuilder)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Parameters (junitparams.Parameters)2 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)2 AlertEvent (org.apache.druid.java.util.emitter.service.AlertEvent)2 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)2 ImmutableList (com.google.common.collect.ImmutableList)1