Mirror Traffic
Mirror traffic to Hypertest
Mirror the traffic from your reverse proxy to Hypertest.

Update your application's Dockerfile as per the below example or create a new one
Dockerfile
FROM node:10-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
ENV HYPER_TEST_BRANCH candidate
EXPOSE 3001
#CMD ["npm", "start"]
## copy this ##
# add next line only for alpine-based images
RUN apk add --no-cache ca-certificates openssl
RUN wget https://github.com/buger/goreplay/releases/download/v0.16.1/gor_0.16.1_x64.tar.gz -O gor.tar.gz
RUN tar xzf gor.tar.gz
CMD [ "sh", "-c", "./goreplay --input-raw :<your-application-port> --output-http <hypertest-vm-ip>:<hypertest-logger-port> & npm start" ]
## to this

For NGINX (>= 1.13.4), add the following in you site configuration
Sample nginx.conf
## copy this ##
upstream hypertest-service-logger {
server <hypertest-vm-ip>:<hypertest-logger-port>;
}
## to this ##
server {
## listen 8000;
.
.
location / {
.
.
## copy from this ##
mirror /mirror;
mirror_request_body on;
## to this ##
.
.
## proxy_pass http://localhost:3000;
}
.
.
## copy this ##
location = /mirror {
internal;
if ($http_fromhypertest) {
return 400 'mirror loop';
}
proxy_connect_timeout 500ms;
proxy_read_timeout 500ms;
proxy_pass http://hypertest-service-logger$request_uri;
proxy_set_header x-real-host $http_host;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
}
## to this
.
.
}

Download 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. 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

  1. 1.
    Create a bash script goreplay-<SERVICE_NAME>.sh, copy the following into it. Update the script as specified in the script itself.
goreplay-{SERVICE_NAME}.sh
#! /bin/sh
# Change these variables according to your deployment
APPLICATION_PORT=8001
HT_VM_IP=localhost
HT_LOGGER_PORT=10005
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
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=<ABSOLUTE_PATH_OF_THE_BASH_SCRIPT>
[Install]
WantedBy=multi-user.target
4. Save the file and run
systemctl daemon-reload
systemctl enable goreplay-{SERVICE_NAME} --now

If you're receiving SSL traffic on apache, configure a new virtual host. Your original port would now be used to terminate SSL and forward traffic to the new virtual host. We can now mirror traffic from the new Virtual Host using goreplay.
If unencrypted traffic is being received, directly use goreplay.
Use the example below to create a new virtual host on NEW_NON_SSL_PORT, which you can use to mirror traffic to Hypertest.
Old Apache Config:
Listen OLD_SSL_PORT
<VirtualHost *:OLD_SSL_PORT>
## ssl related config ##
ProxyPreserveHost On
ProxyPass / http://localhost:OLD_APP_PORT>
ProxyPassReverse / http://localhost:OLD_APP_PORT>
</VirtualHost>
New Apache Config:
Listen OLD_SSL_PORT
Listen NEW_NON_SSL_PORT
<VirtualHost *:OLD_SSL_PORT>
## ssl related config ##
ProxyPreserveHost On
ProxyPass / http://localhost:NEW_NON_SSL_PORT>
ProxyPassReverse / http://localhost:NEW_NON_SSL_PORT>
</VirtualHost>
<VirtualHost *:NEW_NON_SSL_PORT>
ProxyPreserveHost On
ProxyPass / http://localhost:OLD_APP_PORT>
ProxyPassReverse / http://localhost:OLD_APP_PORT>
</VirtualHost>

Please refer this tutorial for mirroring traffic using HA Proxy

Please refer this tutorial for mirroring traffic using Envoy
Copy link
On this page
Using containers directly (via goreplay)
Using Nginx
Using GoReplay
Using Apache
Using HAproxy
Using Envoy