Using Goreplay

In this guide, we will use Goreplay to mirror the traffic to HyperTest. Goreplay will run as a systemctl service in your VM.

1. Download goreplay

mkdir /opt/hypertest_goreplay
cd /opt/hypertest_goreplay
wget -O gor.tar.gz https://github.com/buger/goreplay/releases/download/v0.16.1/gor_0.16.1_x64.tar.gz
tar xvf gor.tar.gz
sudo mv ./goreplay /usr/local/bin

To avoid typing in the absolute path to run the goreplay binary, copy it to /usr/local/bin for ubuntu and /usr/localfor linux VM. This document assumes the same.

You should run goreplay as a service using systemctl, monit, pm2 etc so that it restarts on boot or failures

2. Run goreplay as a service using systemctl

  1. Create a bash script goreplay-<SERVICE_NAME>.sh, copy the following into it. Update the script as specified in the script itself.

touch goreplay-<SERVICE_NAME>.sh
vi goreplay-<SERVICE_NAME>.sh
goreplay-{SERVICE_NAME}.sh
#! /bin/sh

# Change these variables according to your deployment
APPLICATION_PORT=8001
HT_VM_IP=<hypertest-vm-ip>
HT_LOGGER_PORT=<hypertest-logger-port>
HT_ENV=default-staging.example.com

process_count=$(pgrep -a -f -c ".--input-raw :$APPLICATION_PORT --output-http $HT_VM_IP:$HT_LOGGER_PORT")
process_names=$(pgrep -a -f ".--input-raw :$APPLICATION_PORT --output-http $HT_VM_IP:$HT_LOGGER_PORT")

if [ "$process_count" -gt 0 ]
  then
    echo "At least one instance of same goreplay mirror is already working. Please verify if the custom instance works or kill it and the run script again."
    for process in "$process_names"; do
      echo "$process"
    done
else
  echo "starting goreplay..."
  sudo goreplay --input-raw :$APPLICATION_PORT --output-http $HT_VM_IP:$HT_LOGGER_PORT --http-disallow-header "fromhypertest: y" --http-set-header "x-ht-env: $HT_ENV"
fi

Make the file executable by

chmod +x /opt/hypertest_goreplay/goreplay-<SERVICE_NAME>.sh

2. Create a file named /etc/systemd/system/goreplay-{SERVICE_NAME}.service

3. Copy the following content and paste it into the goreplay-{SERVICE_NAME} file created in above step. Add the absolute path of the bash script you created in step 1.

goreplay-{SERVICE_NAME}.service
[Unit]
Description=goreplay
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/opt/hypertest_goreplay/goreplay-<SERVICE_NAME>.sh

[Install]
WantedBy=multi-user.target

4. Save the file and run

systemctl daemon-reload
systemctl enable goreplay-{SERVICE_NAME} --now
systemctl start goreplay-{SERVICE_NAME}.service
systemctl status goreplay-{SERVICE_NAME}.service

Check the status of goreplay service and verify it is running.

To Verify the mirroring setup, hit any api on the application and check for request in "last mirrored requests" section or Session page in HyperTest.

Debug mirroring setup via Goreplay

To debug if goreplay is receiving the traffic from your application, we will output the incoming traffic to stdout, so we can see if Goreplay is receiving requests.

Steps:

goreplay --input-raw :<application_port> --output-stdout

Now hit any api on your application and verify if Goreplay is able to receive it.

Last updated