Commit 1992ab7d authored by Sören Henning's avatar Sören Henning

improved kieker adapter

parent 00197a58
......@@ -12,10 +12,10 @@ import kieker.common.record.flow.trace.operation.AfterOperationEvent;
import kieker.common.record.flow.trace.operation.AfterOperationFailedEvent;
import kieker.common.record.flow.trace.operation.BeforeOperationEvent;
import anomalydetection.measurement.Measurement;
import anomalydetection.kieker.MonitoringRecord;
import teetime.stage.basic.AbstractTransformation;
public class KiekerAdapterStage extends AbstractTransformation<IFlowRecord, Measurement> {
public class KiekerAdapterStage extends AbstractTransformation<IFlowRecord, MonitoringRecord> {
private final Map<Long, Trace> traces = new HashMap<>();
......@@ -36,73 +36,85 @@ public class KiekerAdapterStage extends AbstractTransformation<IFlowRecord, Meas
this.traces.put(traceID, trace);
}
private void handleOperationEventRecord(final AbstractOperationEvent record) {
private void handleOperationEventRecord(final AbstractOperationEvent event) {
// Check whether there was an incoming trace meta data record before
if (this.traces.get(record.getTraceId()) != null) {
if (record instanceof BeforeOperationEvent) {
this.handleBeforeOperationEventRecord((BeforeOperationEvent) record);
} else if (record instanceof AfterOperationEvent) {
this.handleAfterOperationEventRecord((AfterOperationEvent) record);
if (this.traces.get(event.getTraceId()) != null) {
if (event instanceof BeforeOperationEvent) {
this.handleBeforeOperationEventRecord((BeforeOperationEvent) event);
} else if (event instanceof AfterOperationEvent) {
this.handleAfterOperationEventRecord((AfterOperationEvent) event);
}
} else {
// TODO how to handle this?
}
}
private void handleBeforeOperationEventRecord(final BeforeOperationEvent record) {
this.traces.get(record.getTraceId()).push(record);
private void handleBeforeOperationEventRecord(final BeforeOperationEvent event) {
this.traces.get(event.getTraceId()).pushEvent(event);
}
private void handleAfterOperationEventRecord(final AfterOperationEvent record) {
final Trace trace = this.traces.get(record.getTraceId());
final BeforeOperationEvent beforeEvent = trace.pop();
private void handleAfterOperationEventRecord(final AfterOperationEvent event) {
final Trace trace = this.traces.get(event.getTraceId());
if (record instanceof AfterOperationFailedEvent) {
// TODO
final BeforeOperationEvent beforeEvent = trace.popEvent();
if (trace.isEmpty()) {
this.traces.remove(event.getTraceId());
}
// record.getOperationSignature();
// record.getClassSignature();
// long startTime = beforeEvent.getTimestamp();
// long endTime = record.getTimestamp();
// String hostname = trace.getHostname();
if (event instanceof AfterOperationFailedEvent) {
// TODO
}
// Additional log checks
// if (TraceReconstructor.this.activateAdditionalLogChecks) {
// if (!beforeEvent.getOperationSignature().equals(record.getOperationSignature())) {
// TraceReconstructor.this.faultyTraceBuffers.add(this);
// TraceReconstructor.this.traceBuffers.remove(this.traceID);
// }
// }
MonitoringRecord record = new MonitoringRecord();
record.setOperationSignature(event.getOperationSignature());
record.setClassSignature(event.getClassSignature());
record.setHostname(trace.getHostname());
record.setSessionId(trace.getSessionId());
record.setThreadId(trace.getThreadId());
record.setTimestamp(beforeEvent.getTimestamp());
record.setDuration(event.getTimestamp() - beforeEvent.getTimestamp());
// this.outputPort.send(element);
this.outputPort.send(record);
if (traces.isEmpty()) {
this.traces.remove(record.getTraceId());
}
}
private class Trace {
private final Deque<BeforeOperationEvent> buffer = new ArrayDeque<>();
private final String hostname;
private final String sessionId;
private final long threadId;
public Trace(final TraceMetadata record) {
this.hostname = record.getHostname();
this.sessionId = record.getSessionId();
this.threadId = record.getThreadId();
}
public void push(final BeforeOperationEvent event) {
public void pushEvent(final BeforeOperationEvent event) {
this.buffer.push(event);
}
public BeforeOperationEvent pop() {
public BeforeOperationEvent popEvent() {
return this.buffer.pop();
}
public boolean isEmpty() {
return this.buffer.isEmpty();
}
public String getHostname() {
return hostname;
}
public String getSessionId() {
return sessionId;
}
public long getThreadId() {
return threadId;
}
}
}
package anomalydetection.kieker;
public class MonitoringRecord {
private String operationSignature;
private String classSignature;
private String hostname;
private String sessionId;
private long threadId;
private long timestamp; // Instant could be more useful
private long duration; // Duration could be more useful
public MonitoringRecord() {}
public MonitoringRecord(final String operationSignature, final String classSignature, final String hostname, final String sessionId, final long threadId,
final long timestamp, final long duration) {
this.operationSignature = operationSignature;
this.classSignature = classSignature;
this.hostname = hostname;
this.sessionId = sessionId;
this.threadId = threadId;
this.timestamp = timestamp;
this.duration = duration;
}
public String getOperationSignature() {
return operationSignature;
}
public void setOperationSignature(final String operationSignature) {
this.operationSignature = operationSignature;
}
public String getClassSignature() {
return classSignature;
}
public void setClassSignature(final String classSignature) {
this.classSignature = classSignature;
}
public String getHostname() {
return hostname;
}
public void setHostname(final String hostname) {
this.hostname = hostname;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(final String sessionId) {
this.sessionId = sessionId;
}
public long getThreadId() {
return threadId;
}
public void setThreadId(final long threadId) {
this.threadId = threadId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(final long timestamp) {
this.timestamp = timestamp;
}
public long getDuration() {
return duration;
}
public void setDuration(final long duration) {
this.duration = duration;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment