1. Create extenstions folder
Copy mkdir .ebextensions
cd .ebextensions
vi hypertest-mirror.config
2. Copy the below content in hypertest-mirror.config
file
Copy option_settings:
- namespace: aws:elasticbeanstalk:application:environment
option_name: SVC_NAME
value: "<SERVICE_NAME>"
- namespace: aws:elasticbeanstalk:application:environment
option_name: APPLICATION_PORT
value: "<application-port>"
- namespace: aws:elasticbeanstalk:application:environment
option_name: HT_VM_IP
value: "<hypertest-vm-ip>"
- namespace: aws:elasticbeanstalk:application:environment
option_name: HT_LOGGER_PORT
value: "<hypertest-logger-port>"
- namespace: aws:elasticbeanstalk:application:environment
option_name: HT_ENV
value: "<env-name>"
commands:
01_install_goreplay:
command: |
mkdir -p /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
02_generate_goreplay_script_file:
command: |
export APPLICATION_PORT=$(/opt/elasticbeanstalk/bin/get-config environment -k APPLICATION_PORT)
export HT_VM_IP=$(/opt/elasticbeanstalk/bin/get-config environment -k HT_VM_IP)
export HT_LOGGER_PORT=$(/opt/elasticbeanstalk/bin/get-config environment -k HT_LOGGER_PORT)
export HT_ENV=$(/opt/elasticbeanstalk/bin/get-config environment -k HT_ENV)
export SVC_NAME=$(/opt/elasticbeanstalk/bin/get-config environment -k SVC_NAME)
echo '#! /bin/sh
# Change these variables according to your deployment
APPLICATION_PORT='"$APPLICATION_PORT"'
HT_VM_IP='"$HT_VM_IP"'
HT_LOGGER_PORT='"$HT_LOGGER_PORT"'
HT_ENV='"$HT_ENV"'
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 the same goreplay mirror is already working. Please verify if the custom instance works or kill it and then run the script again."
for process in "$process_names"; do
echo "$process"
done
else
echo "Starting goreplay..."
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' > /opt/hypertest_goreplay/goreplay-$SVC_NAME.sh
03_generate_goreplay_service:
command: |
export SVC_NAME=$(/opt/elasticbeanstalk/bin/get-config environment -k SVC_NAME)
echo '[Unit]
Description=goreplay
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/opt/hypertest_goreplay/goreplay-'"$SVC_NAME"'.sh
[Install]
WantedBy=multi-user.target' > /etc/systemd/system/goreplay-$SVC_NAME.service
04_start-goreplay-service:
command: |
export SVC_NAME=$(/opt/elasticbeanstalk/bin/get-config environment -k SVC_NAME)
chmod +x /opt/hypertest_goreplay/goreplay-$SVC_NAME.sh
systemctl daemon-reload
systemctl enable goreplay-$SVC_NAME --now
systemctl start goreplay-$SVC_NAME.service
systemctl restart goreplay-$SVC_NAME.service
Include the .ebextensions folder in your source code while you are deploying your application
Now hit any api on your application and verify if Goreplay is able to receive it.