use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class JettyServerModuleTest method testJettyServerModule.
@Test
public void testJettyServerModule() {
List<Event> events = new ArrayList<>();
ServiceEmitter serviceEmitter = new ServiceEmitter("service", "host", Mockito.mock(Emitter.class)) {
@Override
public void emit(Event event) {
events.add(event);
}
};
QueuedThreadPool jettyServerThreadPool = Mockito.mock(QueuedThreadPool.class);
JettyServerModule.setJettyServerThreadPool(jettyServerThreadPool);
Mockito.when(jettyServerThreadPool.getThreads()).thenReturn(100);
Mockito.when(jettyServerThreadPool.getIdleThreads()).thenReturn(40);
Mockito.when(jettyServerThreadPool.isLowOnThreads()).thenReturn(true);
Mockito.when(jettyServerThreadPool.getMinThreads()).thenReturn(30);
Mockito.when(jettyServerThreadPool.getMaxThreads()).thenReturn(100);
Mockito.when(jettyServerThreadPool.getQueueSize()).thenReturn(50);
Mockito.when(jettyServerThreadPool.getBusyThreads()).thenReturn(60);
JettyServerModule.JettyMonitor jettyMonitor = new JettyServerModule.JettyMonitor("ds", "t0");
jettyMonitor.doMonitor(serviceEmitter);
Assert.assertEquals(8, events.size());
List<Pair<String, Number>> expectedEvents = Arrays.asList(new Pair<>("jetty/numOpenConnections", 0), new Pair<>("jetty/threadPool/total", 100), new Pair<>("jetty/threadPool/idle", 40), new Pair<>("jetty/threadPool/isLowOnThreads", 1), new Pair<>("jetty/threadPool/min", 30), new Pair<>("jetty/threadPool/max", 100), new Pair<>("jetty/threadPool/queueSize", 50), new Pair<>("jetty/threadPool/busy", 60));
for (int i = 0; i < expectedEvents.size(); i++) {
Pair<String, Number> expected = expectedEvents.get(i);
ServiceMetricEvent actual = (ServiceMetricEvent) (events.get(i));
Assert.assertEquals(expected.lhs, actual.getMetric());
Assert.assertEquals(expected.rhs, actual.getValue());
}
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class MetricsEmittingQueryProcessingPoolTest method testPrioritizedExecutorDelegate.
@Test
public void testPrioritizedExecutorDelegate() {
PrioritizedExecutorService service = Mockito.mock(PrioritizedExecutorService.class);
Mockito.when(service.getQueueSize()).thenReturn(10);
ExecutorServiceMonitor monitor = new ExecutorServiceMonitor();
List<Event> events = new ArrayList<>();
MetricsEmittingQueryProcessingPool processingPool = new MetricsEmittingQueryProcessingPool(service, monitor);
Assert.assertSame(service, processingPool.delegate());
ServiceEmitter serviceEmitter = new ServiceEmitter("service", "host", Mockito.mock(Emitter.class)) {
@Override
public void emit(Event event) {
events.add(event);
}
};
monitor.doMonitor(serviceEmitter);
Assert.assertEquals(1, events.size());
Assert.assertEquals(((ServiceMetricEvent) (events.get(0))).getMetric(), "segment/scan/pending");
Assert.assertEquals(((ServiceMetricEvent) (events.get(0))).getValue(), 10);
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class EmitClusterStatsAndMetricsTest method testRunEmitStatsForCompactionWhenHaveCompactSegmentDuty.
@Test
public void testRunEmitStatsForCompactionWhenHaveCompactSegmentDuty() {
String groupName = "blah";
ArgumentCaptor<ServiceEventBuilder> argumentCaptor = ArgumentCaptor.forClass(ServiceEventBuilder.class);
Mockito.when(mockDruidCoordinatorRuntimeParams.getEmitter()).thenReturn(mockServiceEmitter);
Mockito.when(mockDruidCoordinatorRuntimeParams.getCoordinatorStats()).thenReturn(mockCoordinatorStats);
Mockito.when(mockDruidCoordinatorRuntimeParams.getDruidCluster()).thenReturn(mockDruidCluster);
CoordinatorDuty duty = new EmitClusterStatsAndMetrics(mockDruidCoordinator, groupName, true);
duty.run(mockDruidCoordinatorRuntimeParams);
Mockito.verify(mockServiceEmitter, Mockito.atLeastOnce()).emit(argumentCaptor.capture());
List<ServiceEventBuilder> emittedEvents = argumentCaptor.getAllValues();
boolean foundCompactMetric = false;
boolean foundHistoricalDutyMetric = false;
for (ServiceEventBuilder eventBuilder : emittedEvents) {
ServiceMetricEvent serviceMetricEvent = ((ServiceMetricEvent) eventBuilder.build("x", "x"));
String metric = serviceMetricEvent.getMetric();
if ("segment/overShadowed/count".equals(metric)) {
foundHistoricalDutyMetric = true;
} else if ("compact/task/count".equals(metric)) {
foundCompactMetric = true;
}
String dutyGroup = (String) serviceMetricEvent.getUserDims().get("dutyGroup");
Assert.assertNotNull(dutyGroup);
Assert.assertEquals(groupName, dutyGroup);
}
Assert.assertFalse(foundHistoricalDutyMetric);
Assert.assertTrue(foundCompactMetric);
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
the class OpenTelemetryEmitter method emitQueryTimeEvent.
private void emitQueryTimeEvent(ServiceMetricEvent event) {
Context opentelemetryContext = propagator.extract(Context.current(), event, DRUID_CONTEXT_TEXT_MAP_GETTER);
try (Scope scope = opentelemetryContext.makeCurrent()) {
DateTime endTime = event.getCreatedTime();
DateTime startTime = endTime.minusMillis(event.getValue().intValue());
Span span = tracer.spanBuilder(event.getService()).setStartTimestamp(startTime.getMillis(), TimeUnit.MILLISECONDS).startSpan();
getContext(event).entrySet().stream().filter(entry -> entry.getValue() != null).filter(entry -> !TRACEPARENT_PROPAGATION_FIELDS.contains(entry.getKey())).forEach(entry -> span.setAttribute(entry.getKey(), entry.getValue().toString()));
Object status = event.getUserDims().get("success");
if (status == null) {
span.setStatus(StatusCode.UNSET);
} else if (status.toString().equals("true")) {
span.setStatus(StatusCode.OK);
} else {
span.setStatus(StatusCode.ERROR);
}
span.end(endTime.getMillis(), TimeUnit.MILLISECONDS);
}
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by apache.
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)));
}
Aggregations