Navigation Menu

Skip to content

Commit

Permalink
Swap over to new bytefrog instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
baffles committed Nov 10, 2017
1 parent a5abab6 commit dafbaad
Show file tree
Hide file tree
Showing 124 changed files with 770 additions and 912 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
.DS_Store
.java-version
.scala_dependencies
.settings/
.classpath
Expand Down
2 changes: 2 additions & 0 deletions .sbtrc
@@ -0,0 +1,2 @@
# load 'CodePulse' project by default
alias boot = ;reload ;project CodePulse ;iflast shell
Expand Up @@ -17,24 +17,26 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent;
package com.codedx.codepulse.agent;

import com.secdec.bytefrog.agent.control.Controller;
import com.secdec.bytefrog.agent.control.StateManager;
import com.secdec.bytefrog.agent.message.MessageSenderManager;
import com.secdec.bytefrog.common.config.RuntimeAgentConfigurationV1;
import com.secdec.bytefrog.common.config.StaticAgentConfiguration;
import com.codedx.bytefrog.instrumentation.id.*;
import com.codedx.codepulse.agent.control.Controller;
import com.codedx.codepulse.agent.control.StateManager;
import com.codedx.codepulse.agent.message.MessageSenderManager;
import com.codedx.codepulse.agent.common.config.RuntimeAgentConfigurationV1;
import com.codedx.codepulse.agent.common.config.StaticAgentConfiguration;
import com.codedx.codepulse.agent.trace.TraceDataCollector;

/**
* Interface for Agent implementations.
*
*
* @author RobertF
*/
public interface TraceAgent
{
/**
* Connect to HQ
*
*
* @param timeout the amount of time to try to connect to HQ for, in
* seconds. A value of zero (0) will disable the timeout
* @return true if connection was successful before the timeout, false
Expand All @@ -52,6 +54,12 @@ public interface TraceAgent
*/
RuntimeAgentConfigurationV1 getConfig();

/** Returns the active class identifier. */
ClassIdentifier getClassIdentifier();

/** Returns the active method identifier. */
MethodIdentifier getMethodIdentifier();

/**
* Returns the active trace data collector.
*/
Expand Down Expand Up @@ -84,7 +92,7 @@ public interface TraceAgent

/**
* Immediately sends error message and halts tracing.
*
*
* @param errorMessage error that caused tracing to be stopped
*/
void killTrace(String errorMessage);
Expand All @@ -96,7 +104,7 @@ public interface TraceAgent

/**
* Sends shutdown message and blocks until all queued data is sent.
*
*
* @throws InterruptedException
*/
void shutdownAndWait() throws InterruptedException;
Expand Down
Expand Up @@ -17,40 +17,45 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.agent;
package com.codedx.codepulse.agent.agent;

import java.io.File;
import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.Semaphore;

import com.secdec.bytefrog.agent.TraceAgent;
import com.secdec.bytefrog.agent.TraceDataCollector;
import com.secdec.bytefrog.agent.control.ConfigurationHandler;
import com.secdec.bytefrog.agent.control.Controller;
import com.secdec.bytefrog.agent.control.HeartbeatInformer;
import com.secdec.bytefrog.agent.control.ModeChangeListener;
import com.secdec.bytefrog.agent.control.StateManager;
import com.secdec.bytefrog.agent.data.MessageDealerTraceDataCollector;
import com.secdec.bytefrog.agent.errors.AgentErrorListener;
import com.secdec.bytefrog.agent.errors.ErrorHandler;
import com.secdec.bytefrog.agent.errors.LogListener;
import com.secdec.bytefrog.agent.message.BufferService;
import com.secdec.bytefrog.agent.message.MessageDealer;
import com.secdec.bytefrog.agent.message.MessageSenderManager;
import com.secdec.bytefrog.agent.message.PooledBufferService;
import com.secdec.bytefrog.agent.protocol.ProtocolVersion;
import com.secdec.bytefrog.agent.protocol.ProtocolVersion1;
import com.secdec.bytefrog.agent.util.ShutdownHook;
import com.secdec.bytefrog.agent.util.SocketFactory;
import com.secdec.bytefrog.common.config.RuntimeAgentConfigurationV1;
import com.secdec.bytefrog.common.config.StaticAgentConfiguration;
import com.secdec.bytefrog.common.connect.SocketConnection;
import com.secdec.bytefrog.common.message.AgentOperationMode;
import com.secdec.bytefrog.common.queue.BufferPool;
import com.codedx.codepulse.agent.TraceAgent;
import com.codedx.codepulse.agent.control.ConfigurationHandler;
import com.codedx.codepulse.agent.control.Controller;
import com.codedx.codepulse.agent.control.HeartbeatInformer;
import com.codedx.codepulse.agent.control.ModeChangeListener;
import com.codedx.codepulse.agent.control.StateManager;
import com.codedx.codepulse.agent.data.MessageDealerTraceDataCollector;
import com.codedx.codepulse.agent.errors.AgentErrorListener;
import com.codedx.codepulse.agent.errors.ErrorHandler;
import com.codedx.codepulse.agent.errors.MinlogListener;
import com.codedx.codepulse.agent.message.BufferService;
import com.codedx.codepulse.agent.message.MessageDealer;
import com.codedx.codepulse.agent.message.MessageSenderManager;
import com.codedx.codepulse.agent.message.PooledBufferService;
import com.codedx.codepulse.agent.protocol.ProtocolVersion;
import com.codedx.codepulse.agent.protocol.ProtocolVersion1;
import com.codedx.codepulse.agent.trace.TraceDataCollector;
import com.codedx.codepulse.agent.util.ShutdownHook;
import com.codedx.codepulse.agent.util.SocketFactory;
import com.codedx.codepulse.agent.common.config.RuntimeAgentConfigurationV1;
import com.codedx.codepulse.agent.common.config.StaticAgentConfiguration;
import com.codedx.codepulse.agent.common.connect.SocketConnection;
import com.codedx.codepulse.agent.common.message.AgentOperationMode;
import com.codedx.codepulse.agent.common.queue.BufferPool;

import com.codedx.bytefrog.instrumentation.id.*;
import com.codedx.bytefrog.util.Logger;
import com.codedx.bytefrog.thirdparty.minlog.Log;

/**
* Concrete Agent implementation, manages the entire trace.
*
*
* @author RobertF
*/
public class DefaultTraceAgent implements TraceAgent
Expand All @@ -63,7 +68,9 @@ public class DefaultTraceAgent implements TraceAgent

private final Semaphore startMutex = new Semaphore(0);
private final ProtocolVersion protocol = new ProtocolVersion1();
private LogListener logger = null;
private MinlogListener logger = null;
private ClassIdentifier classIdentifier = new ClassIdentifier();
private MethodIdentifier methodIdentifier = new MethodIdentifier();
private TraceDataCollector dataCollector;
private StateManager stateManager;
private Controller controller;
Expand All @@ -74,6 +81,9 @@ public class DefaultTraceAgent implements TraceAgent
private boolean isStarted = false;
private boolean isKilled = false;

public ClassIdentifier getClassIdentifier() { return classIdentifier; }
public MethodIdentifier getMethodIdentifier() { return methodIdentifier; }

public DefaultTraceAgent(StaticAgentConfiguration staticConfig)
{
this.staticConfig = staticConfig;
Expand All @@ -83,8 +93,13 @@ public DefaultTraceAgent(StaticAgentConfiguration staticConfig)
{
// add a log listener now. Wait until initialization is done to add
// the Agent listener
logger = new LogListener(staticConfig.getLogFilename());
ErrorHandler.addListener(logger);
String logFilename = staticConfig.getLogFilename();
File logFile = logFilename != null ? new File(logFilename) : null;
if (logFile != null) {
Log.setLogger(new Logger(logFile));
logger = new MinlogListener();
ErrorHandler.addListener(logger);
}

error = "Failed to initialize state manager";

Expand Down Expand Up @@ -279,7 +294,7 @@ private void initializeSender()
// set up the queue/message factory
bufferPool = new BufferPool(numBuffers, bufferLength);
bufferService = new PooledBufferService(bufferPool, config.getQueueRetryCount());
messageFactory = new MessageDealer(protocol.getMessageProtocol(), bufferService);
messageFactory = new MessageDealer(protocol.getMessageProtocol(), bufferService, classIdentifier, methodIdentifier);
dataCollector = new MessageDealerTraceDataCollector(messageFactory);

senderManager = new MessageSenderManager(socketFactory,
Expand Down
Expand Up @@ -17,9 +17,9 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

import com.secdec.bytefrog.common.config.RuntimeAgentConfigurationV1;
import com.codedx.codepulse.agent.common.config.RuntimeAgentConfigurationV1;

/**
* Takes action on incoming replacement configurations.
Expand Down
Expand Up @@ -17,12 +17,12 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

import java.io.DataInputStream;
import java.io.IOException;

import com.secdec.bytefrog.common.config.RuntimeAgentConfigurationV1;
import com.codedx.codepulse.agent.common.config.RuntimeAgentConfigurationV1;

/**
* Configuration reader
Expand Down
Expand Up @@ -17,19 +17,21 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

import com.secdec.bytefrog.agent.errors.ErrorHandler;
import com.secdec.bytefrog.common.config.RuntimeAgentConfigurationV1;
import com.codedx.codepulse.agent.errors.ErrorHandler;
import com.codedx.codepulse.agent.common.config.RuntimeAgentConfigurationV1;

/**
* Reads incoming configuration packets (version 1)
*
*
* @author robertf
*/
public class ConfigurationReaderV1 implements ConfigurationReader
Expand All @@ -44,7 +46,7 @@ public RuntimeAgentConfigurationV1 readConfiguration(DataInputStream stream) thr
byte[] configBuffer = new byte[configLen];
stream.read(configBuffer, 0, configLen);

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(configBuffer));
ConfigurationInputStream in = new ConfigurationInputStream(new ByteArrayInputStream(configBuffer));
try
{
return (RuntimeAgentConfigurationV1) in.readObject();
Expand All @@ -55,4 +57,24 @@ public RuntimeAgentConfigurationV1 readConfiguration(DataInputStream stream) thr
return null;
}
}

protected class ConfigurationInputStream extends ObjectInputStream
{
public ConfigurationInputStream(InputStream in) throws IOException {
super(in);
enableResolveObject(true);
}

@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException
{
ObjectStreamClass clazz = super.readClassDescriptor();

// com.secdec.bytefrog.common -> com.codedx.codepulse.agent.common
if (clazz.getName().startsWith("com.secdec.bytefrog.common."))
return ObjectStreamClass.lookup(Class.forName(clazz.getName().replace("com.secdec.bytefrog.common.", "com.codedx.codepulse.agent.common.")));

return clazz;
}
}
}
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

/**
* Takes action on incoming control messages.
Expand Down
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

import java.io.DataInputStream;
import java.io.IOException;
Expand Down
Expand Up @@ -17,13 +17,13 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

import java.io.DataInputStream;
import java.io.IOException;

import com.secdec.bytefrog.agent.errors.ErrorHandler;
import com.secdec.bytefrog.common.message.MessageConstantsV1;
import com.codedx.codepulse.agent.errors.ErrorHandler;
import com.codedx.codepulse.agent.common.message.MessageConstantsV1;

/**
* Processes incoming control messages (protocol version 1)
Expand Down
Expand Up @@ -17,22 +17,22 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.SocketException;
import java.net.SocketTimeoutException;

import com.secdec.bytefrog.agent.errors.ErrorHandler;
import com.secdec.bytefrog.agent.protocol.ProtocolVersion;
import com.secdec.bytefrog.common.connect.SocketConnection;
import com.secdec.bytefrog.common.message.AgentOperationMode;
import com.codedx.codepulse.agent.errors.ErrorHandler;
import com.codedx.codepulse.agent.protocol.ProtocolVersion;
import com.codedx.codepulse.agent.common.connect.SocketConnection;
import com.codedx.codepulse.agent.common.message.AgentOperationMode;

/**
* Control Controller - responsible for managing control connection
*
*
* @author RobertF
*/
public class Controller extends Thread
Expand Down
Expand Up @@ -17,9 +17,9 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

import com.secdec.bytefrog.common.message.AgentOperationMode;
import com.codedx.codepulse.agent.common.message.AgentOperationMode;

/**
* Answers queries for heartbeat information
Expand Down
Expand Up @@ -17,9 +17,9 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

import com.secdec.bytefrog.common.message.AgentOperationMode;
import com.codedx.codepulse.agent.common.message.AgentOperationMode;

/**
* Base class for tracing state change listeners.
Expand Down
Expand Up @@ -17,12 +17,12 @@
* limitations under the License.
*/

package com.secdec.bytefrog.agent.control;
package com.codedx.codepulse.agent.control;

import java.util.LinkedList;

import com.secdec.bytefrog.agent.errors.ErrorHandler;
import com.secdec.bytefrog.common.message.AgentOperationMode;
import com.codedx.codepulse.agent.errors.ErrorHandler;
import com.codedx.codepulse.agent.common.message.AgentOperationMode;

/**
* Manages execution state and provides heartbeat information
Expand Down

0 comments on commit dafbaad

Please sign in to comment.