use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class RequestTracingService method processTraceEnd.
private void processTraceEnd() {
Long thresholdValueInNanos = getThresholdValueInNanos();
long elapsedTime = requestEventStore.getElapsedTime();
long elapsedTimeInNanos = TimeUnit.NANOSECONDS.convert(elapsedTime, TimeUnit.MILLISECONDS);
if (elapsedTimeInNanos - thresholdValueInNanos > 0) {
// Determine whether to sample the request, if sampleRateFirstEnabled is false
if (!executionOptions.getSampleRateFirstEnabled()) {
if (!sampleFilter.sample()) {
requestEventStore.flushStore();
return;
}
}
// collect any trace exceeding the threshold
if (uncollectedTraces.size() >= 50) {
// avoid queue creating a memory leak by accumulating entries in case no consumer polls them
uncollectedTraces.poll();
}
RequestTrace requestTrace = requestEventStore.getTrace();
uncollectedTraces.add(requestTrace);
Runnable addTask = () -> {
RequestTrace removedTrace = requestTraceStore.addTrace(requestTrace);
// Store the trace in the historic trace store if it's enabled, avoiding recalculation
if (executionOptions.isHistoricTraceStoreEnabled()) {
historicRequestTraceStore.addTrace(requestTrace, removedTrace);
}
if (removedTrace != null) {
if (hazelcast.isEnabled()) {
eventBus.publish(EVENT_BUS_LISTENER_NAME, new ClusterMessage(RequestTracingEvents.STORE_FULL.toString()));
} else {
events.send(new EventListener.Event(RequestTracingEvents.STORE_FULL));
}
}
};
payaraExecutorService.submit(addTask);
Collection<String> enabledNotifiers = getExecutionOptions().getEnabledNotifiers();
PayaraNotification notification = notificationFactory.newBuilder().whitelist(enabledNotifiers.toArray(new String[0])).subject("Request execution time: " + elapsedTime + "(ms) exceeded the acceptable threshold").message(requestTrace.toString()).data(new RequestTracingNotificationData(requestTrace)).build();
notificationEventBus.publish(notification);
}
requestEventStore.flushStore();
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class ListRequestTraces method generateReport.
private void generateReport(ActionReport actionReport) {
RequestTracingExecutionOptions executionOptions = service.getExecutionOptions();
if (first == null) {
first = executionOptions.getTraceStoreSize();
}
RequestTraceStoreInterface eventStore;
if (historicTraces == null || historicTraces) {
eventStore = service.getHistoricRequestTraceStore();
} else {
eventStore = service.getRequestTraceStore();
}
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
Properties extrasProps = new Properties();
List<Map<String, String>> tracesList = new ArrayList<>();
Collection<RequestTrace> traces = eventStore.getTraces(first);
for (RequestTrace requestTrace : traces) {
Map<String, String> messages = new LinkedHashMap<>();
Object[] values = new Object[3];
values[0] = requestTrace.getStartTime();
values[1] = requestTrace.getElapsedTime();
values[2] = requestTrace.toString();
messages.put("occuringTime", values[0].toString());
messages.put("elapsedTime", values[1].toString());
messages.put("message", (String) values[2]);
tracesList.add(messages);
columnFormatter.addRow(values);
}
actionReport.setMessage(columnFormatter.toString());
extrasProps.put("traces", tracesList);
actionReport.setExtraProperties(extrasProps);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class RequestTraceTest method testAddEventWithoutStarting.
/**
* Test of addEvent method, of class RequestTrace.
*/
@Test
public void testAddEventWithoutStarting() {
trace = new RequestTrace();
RequestTraceSpan re = new RequestTraceSpan("TestEvent");
trace.addEvent(re);
assertFalse(trace.isStarted());
assertFalse(trace.getTraceSpans().contains(this));
assertEquals(0, trace.getTraceSpans().size());
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class RequestEventStoreTest method testStoreEventMultipleThreads.
/**
* Test of storeEvent method utilising multiple threads ensuring traces are separate
*/
@Test
public void testStoreEventMultipleThreads() throws InterruptedException {
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
long threadID = Thread.currentThread().getId();
RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "Start" + threadID);
eventStore.storeEvent(re);
for (int i = 0; i < 100; i++) {
re = new RequestTraceSpan("Event-" + i + "-" + threadID);
eventStore.storeEvent(re);
}
eventStore.endTrace();
tracesbyThreadId.put(threadID, eventStore.getTrace());
}
});
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
long threadID = Thread.currentThread().getId();
RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "Start" + threadID);
eventStore.storeEvent(re);
for (int i = 0; i < 200; i++) {
re = new RequestTraceSpan("Event-" + i + "-" + threadID);
eventStore.storeEvent(re);
}
eventStore.endTrace();
tracesbyThreadId.put(threadID, eventStore.getTrace());
}
});
thread1.start();
thread2.start();
thread1.join();
thread2.join();
RequestTrace trace1 = tracesbyThreadId.get(thread1.getId());
RequestTrace trace2 = tracesbyThreadId.get(thread2.getId());
// make sure we have something of the correct length in each trace
assertNotNull(trace2);
assertNotNull(trace1);
assertEquals(201, trace2.getTraceSpans().size());
assertEquals(101, trace1.getTraceSpans().size());
// ensure they are different classes
assertNotSame(trace2, trace1);
// assert last names are correct
assertEquals("Event-99-" + thread1.getId(), trace1.getTraceSpans().getLast().getEventName());
assertEquals("Event-199-" + thread2.getId(), trace2.getTraceSpans().getLast().getEventName());
// assert start names are correct
assertEquals("Start" + thread1.getId(), trace1.getTraceSpans().getFirst().getEventName());
assertEquals("Start" + thread2.getId(), trace2.getTraceSpans().getFirst().getEventName());
// assert all conversation IDs are correct trace 1
UUID convID = trace1.getTraceSpans().getFirst().getTraceId();
for (RequestTraceSpan re : trace1.getTraceSpans()) {
assertEquals(convID, re.getTraceId());
}
// assert all conversation IDs are correct trace 2
UUID convID2 = trace2.getTraceSpans().getFirst().getTraceId();
for (RequestTraceSpan re : trace2.getTraceSpans()) {
assertEquals(convID2, re.getTraceId());
}
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class AbstractStorageStrategyTest method traceIsRemovedAboveMaxSize.
@Test
public void traceIsRemovedAboveMaxSize() {
int maxSize = 10;
int loops = 30;
List<RequestTrace> traces = new ArrayList<>();
for (int i = 0; i < maxSize; i++) {
traces.add(createTrace());
}
for (int i = maxSize; i < loops + maxSize; i++) {
traces.add(createTrace());
RequestTrace traceForRemoval = strategy.getTraceForRemoval(traces, maxSize, null);
assertNotNull(traceForRemoval);
for (int j = 0; j < traces.size(); j++) {
RequestTrace traceToRemove = traces.get(j);
assertSame(traceToRemove, strategy.getTraceForRemoval(traces, maxSize, traceToRemove));
}
traces.remove(traceForRemoval);
assertTrue(traces.size() <= maxSize);
}
}
Aggregations