Skip to content

Commit 12658cf

Browse files
committed
Update profiling tools
Including: * Use centos8-stream image * Refactor provision scripts
1 parent 348195a commit 12658cf

File tree

6 files changed

+130
-40
lines changed

6 files changed

+130
-40
lines changed

Vagrantfile

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Vagrant.configure("2") do |config|
55
# Every Vagrant development environment requires a box. You can search for
66
# boxes at https://atlas.hashicorp.com/search.
7-
config.vm.box = "fedora/26-cloud-base"
8-
config.vm.box_version = "20170705"
7+
config.vm.box = "centos/stream8"
8+
config.vm.box_url = "https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-Vagrant-8-latest.x86_64.vagrant-libvirt.box"
99

1010
# Create a forwarded port mapping which allows access to a specific port
1111
# within the machine from a port on the host machine. In the example below,
@@ -33,27 +33,28 @@ Vagrant.configure("2") do |config|
3333
# backing providers for Vagrant. These expose provider-specific options.
3434
# Example for VirtualBox:
3535
#
36-
config.vm.provider "virtualbox" do |vb|
37-
vb.memory = "1024"
38-
vb.cpus = 2
39-
end
36+
config.vm.provider "virtualbox" do |vb|
37+
vb.memory = "1024"
38+
vb.cpus = 2
39+
end
40+
41+
config.vm.provider "libvirt" do |vb|
42+
vb.memory = "1024"
43+
vb.cpus = 2
44+
end
45+
46+
# Disable default sync folder
47+
config.vm.synced_folder ".", "/vagrant", disabled: true
4048

4149
# View the documentation for the provider you are using for more
4250
# information on available options.
43-
config.vm.synced_folder ".", "/vagrant", type: 'virtualbox'
44-
45-
config.vm.synced_folder ".", "/home/vagrant/app", type: 'rsync',
46-
rsync__exclude: %w[lua_modules .git .vagrant node_modules t/servroot t/servroot* ],
51+
config.vm.synced_folder ".", "/opt/app-root", type: 'rsync',
52+
rsync__exclude: %w[lua_modules .git .vagrant node_modules t/servroot t/servroot* .cpanm],
4753
rsync__args: %w[--verbose --archive --delete -z --links ]
4854

4955
config.vm.provision "shell", path: 'script/install/centos.sh'
56+
config.vm.provision "shell", path: 'script/install/openresty.sh'
57+
config.vm.provision "shell", path: 'script/install/luarocks.sh'
5058
config.vm.provision "shell", path: 'script/install/utilities.sh'
51-
52-
config.vm.provision "shell", inline: <<~'SHELL'
53-
systemctl start redis
54-
systemctl disable openresty
55-
systemctl stop openresty
56-
SHELL
57-
58-
config.vm.provision "shell", privileged: false, name: "Install APIcast dependencies", path: 'script/install/apicast.sh', args: %w[app]
59+
5960
end

doc/profiling.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
# Profiling
22

3+
## Prerequisite
4+
* Vagrant
5+
* QEMU or virtualbox
6+
* At least 20GB of free space
7+
38
There is a Vagrantfile with performance inspection tools like SystemTap.
49

510
```shell
611
vagrant up
712
vagrant ssh
813
```
914

10-
APIcast is mounted into `/home/vagrant/app` so you can start it by:
15+
Install [vagrant-libvirt](https://github.com/vagrant-libvirt/vagrant-libvirt) plugin if using `libvirt`
16+
17+
```
18+
vagrant plugin install vagrant-libvirt
19+
vagrant up --provider=libvirt
20+
vagrant ssh
21+
```
22+
23+
APIcast is mounted into `/opt/app-src` so you can start it by:
1124

1225
```shell
13-
cd app
26+
cd /opt/app-src
1427
bin/apicast
1528
```
1629

script/install/centos.sh

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

33
set -x -e
44

5-
dnf -y install dnf-plugins-core
5+
# Old Centos packages are moved to vault.centos.org
6+
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Stream-*
7+
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
68

7-
dnf config-manager --add-repo https://openresty.org/package/fedora/openresty.repo
9+
yum install -y yum-utils
10+
yum-config-manager --enable "powertools"
811

9-
yum -y install rsync
10-
yum -y install openresty-resty openresty-debug openresty-debug-debuginfo openresty-pcre-debuginfo
11-
yum -y install systemtap git httpd-tools
12-
yum -y install luarocks
13-
yum -y install perl-local-lib perl-App-cpanminus redis perl-open expect
12+
# Remove lua 5.3
13+
yum remove -y lua
1414

15-
yum -y groupinstall 'Development Tools'
16-
yum -y install openssl-devel libev-devel
15+
# install build and runtime dependencies
16+
yum -y install gcc gcc-c++ make m4 git which iputils bind-utils expat-devel m4\
17+
wget tar unzip libyaml libyaml-devel \
18+
perl-local-lib perl-App-cpanminus \
19+
openssl-devel libev-devel \
20+
kernel-headers kernel-devel kernel-debug \
21+
redis systemtap \
22+
python2-pip elfutils-devel
1723

18-
dnf debuginfo-install -y "kernel-core-$(uname -r)"
19-
20-
yum -y install python2-pip
24+
dnf --enablerepo="debuginfo" debuginfo-install -y "kernel-core-$(uname -r)"

script/install/luarocks.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
set -x -e
2+
3+
LUAROCKS_VER="3.8.0"
4+
OPENRESTY_PREFIX="/usr/local/openresty"
5+
WITH_LUA_OPT="--with-lua=${OPENRESTY_PREFIX}/luajit"
6+
APP_ROOT=/opt/app-root
7+
8+
export PATH=$PATH:/usr/local/bin
9+
10+
wget -q https://github.com/luarocks/luarocks/archive/v"$LUAROCKS_VER".tar.gz
11+
tar -xf v"$LUAROCKS_VER".tar.gz
12+
cd luarocks-"$LUAROCKS_VER" || exit
13+
./configure $WITH_LUA_OPT
14+
15+
make && make install
16+
cd ..
17+
rm -rf luarocks-"$LUAROCKS_VER"
18+
rm -f v"$LUAROCKS_VER".tar.gz
19+
20+
cp ${APP_ROOT}/site_config.lua /usr/local/share/lua/5.1/luarocks/site_config.lua
21+
cp ${APP_ROOT}/config-*.lua /usr/local/openresty/config-5.1.lua
22+
23+
luarocks install luaossl 20200709 --tree ${APP_ROOT}/lua_modules CFLAGS="-O2 -fPIC -DHAVE_EVP_KDF_CTX=1"
24+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/pintsized/lua-resty-http-0.17.1-0.src.rock
25+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/kikito/router-2.1-0.src.rock
26+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/kikito/inspect-3.1.1-0.src.rock
27+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/cdbattags/lua-resty-jwt-0.2.0-0.src.rock
28+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/3scale/lua-resty-url-0.3.5-1.src.rock
29+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/3scale/lua-resty-env-0.4.0-1.src.rock
30+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/3scale/liquid-0.2.0-2.src.rock
31+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/tieske/date-2.2-2.src.rock
32+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/tieske/penlight-1.13.1-1.src.rock
33+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/mpeterv/argparse-0.6.0-1.src.rock
34+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/3scale/lua-resty-execvp-0.1.1-1.src.rock
35+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/hisham/luafilesystem-1.8.0-1.src.rock
36+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/3scale/lua-resty-jit-uuid-0.0.7-1.src.rock
37+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/knyar/nginx-lua-prometheus-0.20181120-2.src.rock
38+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/hamish/lua-resty-iputils-0.3.0-1.src.rock
39+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/golgote/net-url-0.9-1.src.rock
40+
luarocks install --deps-mode=none --tree /usr/local https://luarocks.org/manifests/membphis/lua-resty-ipmatcher-0.6.1-0.src.rock

script/install/openresty.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
set -x -e
2+
3+
OPENRESTY_YUM_REPO="https://openresty.org/package/centos/openresty.repo"
4+
THREESCALE_YUM_REPO="http://packages.dev.3sca.net/dev_packages_3sca_net.repo"
5+
OPENRESTY_RPM_VERSION="1.21.4-1.el8"
6+
JAEGERTRACING_CPP_CLIENT_RPM_VERSION="0.3.1-13.el8"
7+
8+
APP_ROOT=/opt/app-root
9+
HOME=/opt/app-root/src
10+
PATH=/opt/app-root/src/bin:/opt/app-root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
11+
12+
## add openresty and 3scale rpm repo
13+
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
14+
yum-config-manager --add-repo http://packages.dev.3sca.net/dev_packages_3sca_net.repo
15+
16+
yum -y install \
17+
openresty-${OPENRESTY_RPM_VERSION} \
18+
openresty-resty-${OPENRESTY_RPM_VERSION} \
19+
openresty-debuginfo-${OPENRESTY_RPM_VERSION} \
20+
openresty-debugsource-${OPENRESTY_RPM_VERSION} \
21+
openresty-opentelemetry-${OPENRESTY_RPM_VERSION} \
22+
openresty-opentracing-${OPENRESTY_RPM_VERSION} \
23+
opentracing-cpp-devel-1.3.0 \
24+
libopentracing-cpp1-1.3.0 \
25+
jaegertracing-cpp-client-${JAEGERTRACING_CPP_CLIENT_RPM_VERSION}\
26+
27+
export PATH="./lua_modules/bin:/usr/local/openresty/luajit/bin/:${PATH}"
28+
export LUA_PATH="./lua_modules/share/lua/5.1/?.lua;./lua_modules/share/lua/5.1/?/init.lua;/usr/lib64/lua/5.1/?.lua;/usr/share/lua/5.1/?.lua;/opt/app-root/lua_modules/share/lua/5.1/?.lua;/opt/app-root/lua_modules/share/lua/5.1/?/?.lua"
29+
export LUA_CPATH="./lua_modules/lib/lua/5.1/?.so;/opt/app-root/lua_modules/lib64/lua/5.1/?.so;/opt/app-root/lua_modules/lib64/lua/5.1/?/?.so;;"
30+
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/app-root/lib"
31+
32+
ln -sf /dev/stdout /usr/local/openresty/nginx/logs/access.log
33+
ln -sf /dev/stderr /usr/local/openresty/nginx/logs/error.log
34+
mkdir -p /usr/local/openresty/nginx/client_body_temp/
35+
chmod 777 /usr/local/openresty/nginx/client_body_temp/

script/install/utilities.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ user=${SUDO_USER:-${CIRCLECI_USER:-vagrant}}
55

66
# CircleCI forces use of SSH protocol everywhere, we need to reset it.
77
export HOME="/tmp"
8+
export PATH=$PATH:/usr/local/bin
89

910
# Clone various utilities
1011
git clone https://github.com/openresty/stapxx.git /usr/local/stapxx || (cd /usr/local/stapxx && git pull)
@@ -19,9 +20,9 @@ git clone https://github.com/lighttpd/weighttp.git /usr/local/weighttp || (cd /u
1920
( cd /usr/local/weighttp && gcc -O2 -DPACKAGE_VERSION='"0.4"' src/*.c -o weighttp -lev -lpthread && ln -sf "$(pwd)/weighttp" /usr/local/bin/ )
2021

2122
# Utility to resolve builtin functions
22-
echo '#!/usr/bin/env luajit' > /usr/local/bin/ljff
23-
curl -L https://raw.githubusercontent.com/openresty/openresty-devel-utils/master/ljff.lua >> /usr/local/bin/ljff
24-
chmod +x /usr/local/bin/ljff
23+
# echo '#!/usr/bin/env luajit' > /usr/local/bin/ljff
24+
# curl -L https://raw.githubusercontent.com/openresty/openresty-devel-utils/master/ljff.lua >> /usr/local/bin/ljff
25+
# chmod +x /usr/local/bin/ljff
2526

2627
# Create stap++ executable always pointing to its proper location
2728
echo '#!/bin/sh' > /usr/local/bin/stap++
@@ -41,10 +42,6 @@ if [ -n "${CIRCLE_SHELL_ENV:-}" ]; then
4142
cat /etc/profile.d/perl.sh >> "${CIRCLE_SHELL_ENV}"
4243
fi
4344

44-
mkdir -p /usr/share/lua/5.1/luarocks/ /usr/share/lua/5.3/luarocks/
45-
curl -L https://raw.githubusercontent.com/3scale/s2i-openresty/ffb1c55533be866a97466915d7ef31c12bae688c/site_config.lua > /usr/share/lua/5.1/luarocks/site_config.lua
46-
ln -sf /usr/share/lua/5.1/luarocks/site_config.lua /usr/share/lua/5.3/luarocks/site_config.lua
47-
4845
# Add various utilites to the PATH
4946
ln -sf /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit
5047
ln -sf /usr/local/flamegraph/*.pl /usr/local/bin/
@@ -53,7 +50,7 @@ ln -sf /usr/local/stapxx/samples/*.sxx /usr/local/bin/
5350
ln -sf $(find /usr/local/openresty-systemtap-toolkit/ -maxdepth 1 -type f -executable -print) /usr/local/bin/
5451

5552
# Allow vagrant user to use systemtap
56-
usermod -a -G stapusr,stapdev "${user}"
53+
usermod -aG stapusr,stapdev "${user}"
5754

5855
# Raise opened files limit for vagrant user
5956
# shellcheck disable=SC1117

0 commit comments

Comments
 (0)