Search in sources :

Example 1 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class SessionAndTraceRegistrationPayloadFilterTest method testDoFilter.

/**
 * Test method for
 * {@link org.iobserve.monitoring.probe.servlet.SessionAndTraceRegistrationPayloadFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}.
 *
 * @throws InterruptedException
 *             during the sleep time of the thread
 */
// TODO Something goes occasionally wrong in this test. FixME!
// @Test
public void testDoFilter() throws InterruptedException {
    final ServletContext context = new TestServletContext();
    final ServletResponse response = new TestHttpServletResponse();
    final HttpSession session = new TestHttpSession(context);
    final TestHttpServletRequest request = new TestHttpServletRequest(context, session);
    final FilterConfig filterConfig = new TestFilterConfig(context);
    final SessionAndTraceRegistrationPayloadFilter filter = new SessionAndTraceRegistrationPayloadFilter();
    try {
        filter.init(filterConfig);
        filter.doFilter(request, response, this.createChain());
        MonitoringController.getInstance().terminateMonitoring();
        while (!MonitoringController.getInstance().isMonitoringTerminated()) {
            Thread.sleep(1000);
        }
        final List<IMonitoringRecord> storage = TestDumpWriter.getRecords();
        Assert.assertTrue("No records received", !storage.isEmpty());
        IMonitoringRecord record = storage.get(0);
        Assert.assertEquals("Should be KiekerMetadataRecord", KiekerMetadataRecord.class, record.getClass());
        record = storage.get(1);
        Assert.assertEquals("Should be TraceMetadata", TraceMetadata.class, record.getClass());
        record = storage.get(2);
        Assert.assertEquals("Should be EntryLevelBeforeOperationEvent", EntryLevelBeforeOperationEvent.class, record.getClass());
        if (record instanceof EntryLevelBeforeOperationEvent) {
            final EntryLevelBeforeOperationEvent beforeEvent = (EntryLevelBeforeOperationEvent) record;
            Assert.assertEquals("Class signature does not match", TestServletContext.CONTEXT_PATH, beforeEvent.getClassSignature());
            Assert.assertEquals("Operation signature does not match", TestHttpServletRequest.REQUEST_URI, beforeEvent.getOperationSignature());
            final Iterator<String> keys = request.getParameters().keySet().iterator();
            for (final String label : beforeEvent.getParameters()) {
                if (!keys.hasNext()) {
                    Assert.fail("Found more parameters than defined in the request.");
                } else {
                    Assert.assertEquals("Same parameter", keys.next(), label);
                }
            }
            final Iterator<String> values = request.getParameters().values().iterator();
            for (final String label : beforeEvent.getValues()) {
                if (!values.hasNext()) {
                    Assert.fail("Found more parameters than defined in the request.");
                } else {
                    Assert.assertEquals("Same parameter", values.next(), label);
                }
            }
        }
        record = storage.get(3);
        Assert.assertEquals("Should be AfterOperationEvent", AfterOperationEvent.class, record.getClass());
        Assert.assertEquals("Wrong number of records ", 4, storage.size());
    } catch (final ServletException e) {
        Assert.fail(e.getMessage());
    } catch (final IOException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ServletResponse(javax.servlet.ServletResponse) HttpSession(javax.servlet.http.HttpSession) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) EntryLevelBeforeOperationEvent(org.iobserve.common.record.EntryLevelBeforeOperationEvent) IMonitoringRecord(kieker.common.record.IMonitoringRecord) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig)

Example 2 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class EndSessionDetector method flushAllRecords.

private void flushAllRecords() {
    for (final IMonitoringRecord event : this.allRecords) {
        if (event instanceof ITraceRecord) {
            final ITraceRecord traceEvent = (ITraceRecord) event;
            final Pair firstLast = this.getFirstLast(traceEvent);
            this.outputPort.send(event);
            if (firstLast != null) {
                if (firstLast.getLast() == traceEvent) {
                    this.outputPort.send(new SessionEndEvent(firstLast.getLast().getLoggingTimestamp(), firstLast.getFirst().getHostname(), firstLast.getFirst().getSessionId()));
                }
            }
        } else {
            this.outputPort.send(event);
        }
    }
    this.allRecords.clear();
}
Also used : SessionEndEvent(org.iobserve.common.record.SessionEndEvent) ITraceRecord(kieker.common.record.flow.ITraceRecord) IMonitoringRecord(kieker.common.record.IMonitoringRecord)

Example 3 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class AbstractGeoLocationSampler method sample.

/**
 * Perform one measurement with potential multiple records.
 *
 * @param monitoringController
 *            The monitoring controller for this probe.
 *
 * @throws Exception
 *             depending on the concrete sampler different exceptions can be raised
 */
@Override
public void sample(final IMonitoringController monitoringController) throws Exception {
    if (!monitoringController.isMonitoringEnabled()) {
        return;
    }
    final long timestamp = monitoringController.getTimeSource().getTime();
    final String hostname = monitoringController.getHostname();
    final ISOCountryCode countryCode = this.countryInvestigator.getServerGeoLocationCountry();
    final IMonitoringRecord geoLocationRecord = this.getGeoLocationRecord(timestamp, hostname, countryCode, monitoringController);
    monitoringController.newMonitoringRecord(geoLocationRecord);
}
Also used : ISOCountryCode(org.iobserve.common.record.ISOCountryCode) IMonitoringRecord(kieker.common.record.IMonitoringRecord)

Example 4 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class DynamicEventDispatcherTest method checkLogCounting.

/**
 * Test reporting elements of the record switch.
 */
@Test
public void checkLogCounting() {
    final DynamicEventDispatcher eventDispatcher = new DynamicEventDispatcher(this.kiekerMetadataMatcher, true, true, false);
    final List<IMonitoringRecord> thousandRecords = new ArrayList<>();
    for (int i = 0; i < 2000; i++) {
        thousandRecords.addAll(this.otherRecords);
    }
    StageTester.test(eventDispatcher).and().send(thousandRecords).to(eventDispatcher.getInputPort()).start();
    Assert.assertThat((int) eventDispatcher.getEventCount(), Is.is(thousandRecords.size()));
}
Also used : IMonitoringRecord(kieker.common.record.IMonitoringRecord) ArrayList(java.util.ArrayList) DynamicEventDispatcher(org.iobserve.stages.general.DynamicEventDispatcher) Test(org.junit.Test)

Example 5 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class HackedRecordFromBinaryFileCreator method deserializeRecord.

private IMonitoringRecord deserializeRecord(final ReaderRegistry<String> registry, final IValueDeserializer deserializer) throws IOException {
    final int clazzId = this.buffer.getInt();
    final String recordClassName = registry.get(clazzId);
    if (recordClassName == null) {
        HackedRecordFromBinaryFileCreator.LOGGER.error("Missing classname mapping for record type id '{}'", clazzId);
        // we can't easily recover on errors
        return null;
    }
    // identify logging timestamp
    if (this.buffer.remaining() < HackedRecordFromBinaryFileCreator.LONG_BYTES) {
        // incomplete record, move back
        this.buffer.reset();
        this.buffer.compact();
        return null;
    } else {
        final long loggingTimestamp = this.buffer.getLong();
        // identify record data
        final IRecordFactory<? extends IMonitoringRecord> recordFactory = this.recordFactories.get(recordClassName);
        if (this.buffer.remaining() < recordFactory.getRecordSizeInBytes()) {
            // incomplete record, move back
            this.buffer.reset();
            this.buffer.compact();
            return null;
        } else {
            try {
                final IMonitoringRecord record = recordFactory.create(deserializer);
                record.setLoggingTimestamp(loggingTimestamp);
                return record;
            } catch (final RecordInstantiationException ex) {
                // TODO this happens when dynamic
                // arrays are used and the buffer
                // does not hold the complete
                // record.
                HackedRecordFromBinaryFileCreator.LOGGER.warn("Failed to create: {} error {}", recordClassName, ex);
                // incomplete record, move back
                this.buffer.reset();
                this.buffer.compact();
                return null;
            } catch (final BufferUnderflowException ex) {
                HackedRecordFromBinaryFileCreator.LOGGER.warn("Failed to create: {} error {}", recordClassName, ex);
                // incomplete record, move back
                this.buffer.reset();
                this.buffer.compact();
                return null;
            }
        }
    }
}
Also used : IMonitoringRecord(kieker.common.record.IMonitoringRecord) RecordInstantiationException(kieker.common.exception.RecordInstantiationException) BufferUnderflowException(java.nio.BufferUnderflowException)

Aggregations

IMonitoringRecord (kieker.common.record.IMonitoringRecord)15 IOException (java.io.IOException)2 BufferUnderflowException (java.nio.BufferUnderflowException)2 ArrayList (java.util.ArrayList)2 FilterConfig (javax.servlet.FilterConfig)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 ServletResponse (javax.servlet.ServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 RecordInstantiationException (kieker.common.exception.RecordInstantiationException)2 IRecordReceivedListener (kieker.common.record.IRecordReceivedListener)2 ITraceRecord (kieker.common.record.flow.ITraceRecord)2 TraceMetadata (kieker.common.record.flow.trace.TraceMetadata)2 TextValueDeserializer (kieker.common.record.io.TextValueDeserializer)2 EntryLevelBeforeOperationEvent (org.iobserve.common.record.EntryLevelBeforeOperationEvent)2 ProbeControlFilter (org.iobserve.stages.tcp.ProbeControlFilter)2 Before (org.junit.Before)2 List (java.util.List)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 MappingException (kieker.analysisteetime.plugin.reader.filesystem.util.MappingException)1