Search in sources :

Example 6 with TraceMetadata

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);
}
Also used : IModelProvider(org.iobserve.model.provider.neo4j.IModelProvider) Logger(org.slf4j.Logger) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) AssemblyConnector(org.palladiosimulator.pcm.core.composition.AssemblyConnector) LoggerFactory(org.slf4j.LoggerFactory) Connector(org.palladiosimulator.pcm.core.composition.Connector) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) Collectors(java.util.stream.Collectors) Allocation(org.palladiosimulator.pcm.allocation.Allocation) List(java.util.List) AbstractConsumerStage(teetime.framework.AbstractConsumerStage) LinkingResource(org.palladiosimulator.pcm.resourceenvironment.LinkingResource) Optional(java.util.Optional) System(org.palladiosimulator.pcm.system.System) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) Allocation(org.palladiosimulator.pcm.allocation.Allocation) System(org.palladiosimulator.pcm.system.System)

Example 7 with TraceMetadata

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);
    }
}
Also used : ITraceRecord(kieker.common.record.flow.ITraceRecord) KiekerMetadataRecord(kieker.common.record.misc.KiekerMetadataRecord) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with TraceMetadata

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);
        }
    }
}
Also used : ITraceRecord(kieker.common.record.flow.ITraceRecord) KiekerMetadataRecord(kieker.common.record.misc.KiekerMetadataRecord) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata)

Example 9 with TraceMetadata

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();
    }
}
Also used : AfterOperationObjectEvent(kieker.common.record.flow.trace.operation.object.AfterOperationObjectEvent) AfterOperationFailedObjectEvent(kieker.common.record.flow.trace.operation.object.AfterOperationFailedObjectEvent) BeforeOperationObjectEvent(kieker.common.record.flow.trace.operation.object.BeforeOperationObjectEvent) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) AroundInvoke(javax.interceptor.AroundInvoke)

Example 10 with TraceMetadata

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) AfterOperationObjectEvent(kieker.common.record.flow.trace.operation.object.AfterOperationObjectEvent) AfterOperationFailedObjectEvent(kieker.common.record.flow.trace.operation.object.AfterOperationFailedObjectEvent) BeforeOperationObjectEvent(kieker.common.record.flow.trace.operation.object.BeforeOperationObjectEvent) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) ServletTraceHelper(org.iobserve.common.record.ServletTraceHelper)

Aggregations

TraceMetadata (kieker.common.record.flow.trace.TraceMetadata)12 BeforeOperationEvent (kieker.common.record.flow.trace.operation.BeforeOperationEvent)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ServletException (javax.servlet.ServletException)4 AfterOperationFailedEvent (kieker.common.record.flow.trace.operation.AfterOperationFailedEvent)4 ArrayList (java.util.ArrayList)3 AfterOperationEvent (kieker.common.record.flow.trace.operation.AfterOperationEvent)3 KiekerMetadataRecord (kieker.common.record.misc.KiekerMetadataRecord)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AroundInvoke (javax.interceptor.AroundInvoke)2 ITraceRecord (kieker.common.record.flow.ITraceRecord)2 AfterOperationFailedObjectEvent (kieker.common.record.flow.trace.operation.object.AfterOperationFailedObjectEvent)2 AfterOperationObjectEvent (kieker.common.record.flow.trace.operation.object.AfterOperationObjectEvent)2 BeforeOperationObjectEvent (kieker.common.record.flow.trace.operation.object.BeforeOperationObjectEvent)2 ExtendedAfterOperationEvent (org.iobserve.common.record.ExtendedAfterOperationEvent)2 CallInformation (org.iobserve.monitoring.probe.models.CallInformation)2 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 HashMap (java.util.HashMap)1 List (java.util.List)1