use of kieker.common.record.flow.trace.TraceMetadata in project iobserve-analysis by research-iobserve.
the class NetworkLink method execute.
/**
* Execute this filter.
*
* @param event
* event to use
*/
@Override
protected void execute(final TraceMetadata event) {
final ResourceEnvironment resourceEnvironment = this.resourceEnvironmentModelProvider.readRootComponent(ResourceEnvironment.class);
final System system = this.systemModelProvider.readOnlyRootComponent(System.class);
final Allocation allocation = this.allocationModelProvider.readOnlyRootComponent(Allocation.class);
NetworkLink.collectUnLinkedResourceContainer(resourceEnvironment).stream().forEach(unLinkedResCont -> {
NetworkLink.getAsmContextDeployedOnContainer(allocation, unLinkedResCont).stream().map(asmCtx -> NetworkLink.getConnectedAsmCtx(system, asmCtx)).map(listAsmCtxToConnect -> NetworkLink.collectResourceContainer(allocation, listAsmCtxToConnect)).map(listResContToConnectTo -> NetworkLink.getLinkingResources(resourceEnvironment, listResContToConnectTo)).flatMap(l -> l.stream()).collect(Collectors.toList()).stream().forEach(link -> link.getConnectedResourceContainers_LinkingResource().add(unLinkedResCont));
});
this.resourceEnvironmentModelProvider.updateComponent(ResourceEnvironment.class, resourceEnvironment);
}
use of kieker.common.record.flow.trace.TraceMetadata in project iobserve-analysis by research-iobserve.
the class PlainTraceMetadataRewriter method rewrite.
/**
* Trace data records use unique ids for their respective host. However, in a multi read stage
* these ids may be used on different hosts. Therefore, they have to be mapped.
*
* TODO fails in case of records appearing out of order, i.e., a ITraceRecord appearing before a
* TraceMetadata record.
*
* @param record
* @return
* @throws IOException
*/
@Override
public void rewrite(final Connection connection, final IMonitoringRecord record, final long loggingTimestamp, final OutputPort<IMonitoringRecord> outputPort) throws IOException {
// set logging time stamp
record.setLoggingTimestamp(loggingTimestamp);
if (record instanceof TraceMetadata) {
final TraceMetadata traceMetadata = (TraceMetadata) record;
traceMetadata.setTraceId(this.traceId);
Map<Long, TraceMetadata> map = this.metadatamap.get(traceMetadata.getHostname());
if (map == null) {
map = new HashMap<>();
this.metadatamap.put(traceMetadata.getHostname(), map);
}
map.put(traceMetadata.getTraceId(), traceMetadata);
this.traceId++;
outputPort.send(traceMetadata);
} else if (record instanceof ITraceRecord) {
final SocketAddress remoteAddress = connection.getChannel().getRemoteAddress();
final String ip = this.getIP(remoteAddress);
final long inputTraceId = ((ITraceRecord) record).getTraceId();
final Map<Long, TraceMetadata> map = this.metadatamap.get(ip);
if (map != null) {
final TraceMetadata metaData = map.get(inputTraceId);
((ITraceRecord) record).setTraceId(metaData.getTraceId());
outputPort.send(record);
}
} else if (record instanceof KiekerMetadataRecord) {
// NOCS ignore metadata record
/**
* ignore metadata record.
*/
} else {
/**
* pass all records unmodified, which are not trace records.
*/
outputPort.send(record);
}
}
use of kieker.common.record.flow.trace.TraceMetadata in project iobserve-analysis by research-iobserve.
the class Splitter method execute.
@Override
protected void execute(final IMonitoringRecord element) {
this.recordCount++;
if (element instanceof TraceMetadata) {
final TraceMetadata traceMetadata = (TraceMetadata) element;
this.traceRegisterMap.put(traceMetadata.getTraceId(), traceMetadata);
boolean send = false;
for (int i = 0; i < this.hostnames.length; i++) {
if (this.hostnames[i].equals(traceMetadata.getHostname())) {
this.outputPorts.get(i).send(element);
send = true;
}
}
if (!send) {
for (int i = 0; i < this.hostnames.length; i++) {
this.outputPorts.get(i).send(element);
}
}
} else if (element instanceof ITraceRecord) {
final TraceMetadata metadata = this.traceRegisterMap.get(((ITraceRecord) element).getTraceId());
boolean send = false;
for (int i = 0; i < this.hostnames.length; i++) {
if (this.hostnames[i].equals(metadata.getHostname())) {
this.outputPorts.get(i).send(element);
send = true;
}
}
if (!send) {
for (int i = 0; i < this.hostnames.length; i++) {
this.outputPorts.get(i).send(element);
}
}
} else if (element instanceof KiekerMetadataRecord) {
/**
* ignore.
*/
Splitter.LOGGER.debug("Metadata record {}.", element);
} else {
for (int i = 0; i < this.hostnames.length; i++) {
this.outputPorts.get(i).send(element);
}
}
}
use of kieker.common.record.flow.trace.TraceMetadata in project iobserve-analysis by research-iobserve.
the class TraceObjectInterceptor method interceptMethodCall.
/**
* Around advice configuration.
*
* @param context
* the invocation context of a bean call.
* @return the return value of the next method in the chain
* @throws Throwable
*/
@AroundInvoke
public Object interceptMethodCall(final InvocationContext context) throws Throwable {
// (IllegalThrowsCheck)
if (this.monitoringCtrl.isMonitoringEnabled()) {
final String signature = context.getMethod().toString();
if (this.monitoringCtrl.isProbeActivated(signature)) {
// common fields
TraceMetadata trace = TraceObjectInterceptor.TRACEREGISTRY.getTrace();
final boolean newTrace = trace == null;
if (newTrace) {
trace = TraceObjectInterceptor.TRACEREGISTRY.registerTrace();
this.monitoringCtrl.newMonitoringRecord(trace);
}
final long traceId = trace.getTraceId();
final String clazz = context.getTarget().getClass().getCanonicalName();
final int objectId = System.identityHashCode(context);
// measure before execution
this.monitoringCtrl.newMonitoringRecord(new BeforeOperationObjectEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, objectId));
// execution of the called method
try {
final Object retval = context.proceed();
// measure after successful execution
this.monitoringCtrl.newMonitoringRecord(new AfterOperationObjectEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, objectId));
return retval;
} catch (final Throwable th) {
// NOPMD NOCS (catch throw might
// ok here)
// measure after failed execution
this.monitoringCtrl.newMonitoringRecord(new AfterOperationFailedObjectEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, th.toString(), objectId));
throw th;
} finally {
if (newTrace) {
// close the trace
TraceObjectInterceptor.TRACEREGISTRY.unregisterTrace();
}
}
} else {
return context.proceed();
}
} else {
return context.proceed();
}
}
use of kieker.common.record.flow.trace.TraceMetadata in project iobserve-analysis by research-iobserve.
the class SessionAndTraceRegistrationObjectFilter method doFilter.
/**
* Register thread-local session and trace information, executes the given {@link FilterChain}
* and unregisters the session/trace information. If configured, the execution of this filter is
* also logged to the {@link IMonitoringController}. This method returns immediately if
* monitoring is not enabled.
*
* @param request
* The request.
* @param response
* The response.
* @param chain
* The filter chain to be used.
*
* @throws IOException
* on io errors
* @throws ServletException
* on servlet errors
*/
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
if (SessionAndTraceRegistrationObjectFilter.CTRLINST.isMonitoringEnabled()) {
// if (CTRLINST.isProbeActivated(this.filterOperationSignatureString)) {
final String operationSignature;
final String componentSignature;
final String method;
final String path;
final String sessionId;
String query;
if (request instanceof HttpServletRequest) {
final HttpServletRequest httpRequest = (HttpServletRequest) request;
method = httpRequest.getMethod();
path = httpRequest.getRequestURI().replace('/', '.').substring(1);
sessionId = httpRequest.getSession().getId();
query = httpRequest.getQueryString();
if (query == null) {
query = "";
}
} else {
method = "POST";
path = request.getServletContext().getContextPath().replace('/', '.').substring(1);
sessionId = "<no session>";
query = "";
}
componentSignature = path.replaceAll("\\.[A-Za-z0-9]*$", "");
TraceMetadata trace = SessionAndTraceRegistrationObjectFilter.TRACEREGISTRY.getTrace();
final boolean newTrace = trace == null;
if (newTrace) {
SessionRegistry.INSTANCE.storeThreadLocalSessionId(sessionId);
trace = SessionAndTraceRegistrationObjectFilter.TRACEREGISTRY.registerTrace();
SessionAndTraceRegistrationObjectFilter.CTRLINST.newMonitoringRecord(trace);
SessionAndTraceRegistrationObjectFilter.CTRLINST.newMonitoringRecord(new ServletTraceHelper(trace.getTraceId(), request.getRemoteHost(), request.getRemotePort(), path));
}
if ("GET".equals(method)) {
operationSignature = path + "(" + query.replace(';', ':') + ")";
} else if ("POST".equals(method)) {
operationSignature = path + "()";
} else {
chain.doFilter(request, response);
return;
}
final long traceId = trace.getTraceId();
Integer objectId = SessionAndTraceRegistrationObjectFilter.PATH_MAP.get(path);
if (objectId == null) {
SessionAndTraceRegistrationObjectFilter.idCounter++;
objectId = SessionAndTraceRegistrationObjectFilter.idCounter;
SessionAndTraceRegistrationObjectFilter.PATH_MAP.put(path, objectId);
}
try {
SessionAndTraceRegistrationObjectFilter.CTRLINST.newMonitoringRecord(new BeforeOperationObjectEvent(SessionAndTraceRegistrationObjectFilter.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature, objectId));
chain.doFilter(request, response);
SessionAndTraceRegistrationObjectFilter.CTRLINST.newMonitoringRecord(new AfterOperationObjectEvent(SessionAndTraceRegistrationObjectFilter.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature, objectId));
} catch (final Throwable th) {
// NOPMD NOCS (catch throw is ok here)
SessionAndTraceRegistrationObjectFilter.CTRLINST.newMonitoringRecord(new AfterOperationFailedObjectEvent(SessionAndTraceRegistrationObjectFilter.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature, th.toString(), objectId));
throw new ServletException(th);
} finally {
// is this correct?
SessionAndTraceRegistrationObjectFilter.SESSION_REGISTRY.unsetThreadLocalSessionId();
// Reset the thread-local trace information
if (newTrace) {
// close the trace
SessionAndTraceRegistrationObjectFilter.TRACEREGISTRY.unregisterTrace();
}
}
// } else {
// chain.doFilter(request, response);
// return;
// }
} else {
chain.doFilter(request, response);
}
}
Aggregations