use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class RequestTracingService method endTrace.
/**
*/
public void endTrace() {
if (!isRequestTracingEnabled() || !isTraceInProgress()) {
return;
}
requestEventStore.endTrace();
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;
}
}
RequestTrace requestTrace = requestEventStore.getTrace();
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);
for (NotifierExecutionOptions notifierExecutionOptions : executionOptions.getNotifierExecutionOptionsList().values()) {
if (notifierExecutionOptions.isEnabled()) {
NotificationEventFactory notificationEventFactory = eventFactoryStore.get(notifierExecutionOptions.getNotifierType());
String subject = "Request execution time: " + elapsedTime + "(ms) exceeded the acceptable threshold";
NotificationEvent notificationEvent = notificationEventFactory.buildNotificationEvent(subject, requestTrace);
notificationService.notify(EventSource.REQUESTTRACING, notificationEvent);
}
}
}
requestEventStore.flushStore();
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class ClusteredRequestTraceStore method addTrace.
@Override
public RequestTrace addTrace(RequestTrace trace) {
store.put(instanceId, trace);
RequestTrace traceToRemove = strategy.getTraceForRemoval(getTraces(), maxStoreSize);
if (traceToRemove == null) {
return null;
}
store.remove(traceToRemove);
return traceToRemove;
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class LocalRequestTraceStore method addTrace.
@Override
public RequestTrace addTrace(RequestTrace trace) {
store.add(trace);
RequestTrace traceToRemove = strategy.getTraceForRemoval(getTraces(), maxStoreSize);
if (traceToRemove == null) {
return null;
}
store.remove(traceToRemove);
return traceToRemove;
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class RequestTraceStoreFactory method getStore.
/**
* Generates a request trace store.
*
* @param reservoirSamplingEnabled whether the store should remove items
* based on a reservoir sampling algorithm.
* @param historic whether the store is a historic store or not.
* @return a request trace store.
*/
public static RequestTraceStoreInterface getStore(Events events, boolean reservoirSamplingEnabled, boolean historic) {
// Get the hazelcast store name for if it's a clustered store.
String storeName;
if (historic) {
storeName = HISTORIC_REQUEST_TRACE_STORE;
} else {
storeName = REQUEST_TRACE_STORE;
}
// Determines a strategy for adding items to the store
TraceStorageStrategy strategy;
if (reservoirSamplingEnabled) {
strategy = new ReservoirTraceStorageStrategy();
} else {
strategy = new LongestTraceStorageStrategy();
}
// Get a clustered store if possible
ClusteredStore clusteredStore = Globals.getDefaultHabitat().getService(ClusteredStore.class);
if (clusteredStore != null && clusteredStore.isEnabled()) {
MultiMap<String, RequestTrace> store = (MultiMap) clusteredStore.getMultiMap(storeName);
return new ClusteredRequestTraceStore(store, clusteredStore.getInstanceId(), strategy);
}
// Otherwise get a local store
return new LocalRequestTraceStore(strategy);
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class RequestTraceTest method testGetElapsedTimeInitial.
/**
* Test of getElapsedTime method, of class RequestTrace.
*/
@Test
public void testGetElapsedTimeInitial() {
trace = new RequestTrace();
assertEquals(0, trace.getElapsedTime());
}
Aggregations