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());
}
}
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();
}
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);
}
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()));
}
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;
}
}
}
}
Aggregations