Skip to content

Commit

Permalink
Merge pull request #797 from 3scale/circleci-profiling
Browse files Browse the repository at this point in the history
[circleci] install native apicast for profiling
  • Loading branch information
mikz authored Jun 28, 2018
2 parents b21bdcc + 586a973 commit 7fc66dc
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 87 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ jobs:
path: tmp/benchmark
destination: benchmark

# Run profiling tasks
profile:
machine: true
steps:
- checkout
- run: sudo --preserve-env script/install/circleci.sh
- run: sudo --preserve-env script/install/utilities.sh
- run: script/install/apicast.sh
- run: bin/apicast --dev --test
- store_artifacts:
path: tmp/profile
destination: profile

build-tags: &build-tags
filters:
tags:
Expand All @@ -269,6 +282,8 @@ workflows:
context: org-global
build-test-deploy:
jobs:
- profile:
<<: *build-tags
- build-lua:
<<: *build-tags
- build-perl:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ dependencies: $(ROVER) $(S2I_CONTEXT)/Roverfile.lock
$(ROVER) install --roverfile=$(S2I_CONTEXT)/Roverfile

lua_modules/bin/rover:
@LUAROCKS_CONFIG=$(S2I_CONTEXT)/config-5.1.lua luarocks install --server=http://luarocks.org/dev lua-rover --tree lua_modules 1>&2
@LUAROCKS_CONFIG=$(S2I_CONTEXT)/config-5.1.lua luarocks install --server=http://luarocks.org/dev lua-rover --tree=lua_modules 1>&2

clean-containers: apicast-source
$(DOCKER_COMPOSE) down --volumes
Expand Down
92 changes: 6 additions & 86 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,94 +46,14 @@ Vagrant.configure("2") do |config|
rsync__exclude: %w[lua_modules .git .vagrant node_modules t/servroot t/servroot* ],
rsync__args: %w[--verbose --archive --delete -z --links ]

config.vm.provision "shell", path: 'script/install/centos.sh'
config.vm.provision "shell", path: 'script/install/utilities.sh'

config.vm.provision "shell", inline: <<~'SHELL'
set -x -e
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://openresty.org/package/fedora/openresty.repo
yum -y install rsync
yum -y install openresty-resty openresty-debug openresty-debug-debuginfo openresty-pcre-debuginfo
yum -y install systemtap git httpd-tools
yum -y install luarocks
yum -y install perl-local-lib perl-App-cpanminus redis perl-open expect
yum -y groupinstall 'Development Tools'
yum -y install openssl-devel libev-devel
dnf debuginfo-install -y kernel-core-$(uname -r)
# Clone various utilities
git clone https://github.com/openresty/stapxx.git /usr/local/stapxx || (cd /usr/local/stapxx && git pull)
git clone https://github.com/brendangregg/FlameGraph.git /usr/local/flamegraph || (cd /usr/local/flamegraph && git pull)
git clone https://github.com/openresty/openresty-systemtap-toolkit.git /usr/local/openresty-systemtap-toolkit || (cd /usr/local/openresty-systemtap-toolkit && git pull)
curl -L https://github.com/tsenart/vegeta/releases/download/v6.1.1/vegeta-v6.1.1-linux-amd64.tar.gz | tar -xz --overwrite -C /usr/local/bin/
git clone https://github.com/wg/wrk.git /usr/local/wrk || (cd /usr/local/wrk && git pull)
( cd /usr/local/wrk && make && mv wrk /usr/local/bin/ )
git clone https://github.com/lighttpd/weighttp.git /usr/local/weighttp || (cd /usr/local/weighttp && git pull)
( cd /usr/local/weighttp && gcc -O2 -DPACKAGE_VERSION='"0.4"' src/*.c -o weighttp -lev -lpthread && ln -sf $(pwd)/weighttp /usr/local/bin/ )
# Utility to resolve builtin functions
echo '#!/usr/bin/env luajit' > /usr/local/bin/ljff
curl -L https://raw.githubusercontent.com/openresty/openresty-devel-utils/master/ljff.lua >> /usr/local/bin/ljff
chmod +x /usr/local/bin/ljff
# Create stap++ executable always pointing to its proper location
echo '#!/bin/sh' > /usr/local/bin/stap++
echo 'exec /usr/local/stapxx/stap++ -I /usr/local/stapxx/tapset "$@"' >> /usr/local/bin/stap++
chmod +x /usr/local/bin/stap++
echo 'pathmunge lua_modules/bin' > /etc/profile.d/rover.sh
chmod +x /etc/profile.d/rover.sh
echo 'eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)' > /etc/profile.d/perl.sh
chmod +x /etc/profile.d/perl.sh
mkdir -p /usr/share/lua/5.{1,3}/luarocks/
curl -L https://raw.githubusercontent.com/3scale/s2i-openresty/ffb1c55533be866a97466915d7ef31c12bae688c/site_config.lua > /usr/share/lua/5.1/luarocks/site_config.lua
ln -sf /usr/share/lua/5.{1,3}/luarocks/site_config.lua
# Install APIcast dependencies
yum -y install python2-pip
# Add various utilites to the PATH
ln -sf /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit
ln -sf /usr/local/flamegraph/*.pl /usr/local/bin/
ln -sf /usr/local/stapxx/samples/*.sxx /usr/local/bin/
ln -sf `find -O0 /usr/local/openresty-systemtap-toolkit/ -maxdepth 1 -type f -executable -print` /usr/local/bin/
# Allow vagrant user to use systemtap
usermod -a -G stapusr,stapdev vagrant
# Raise opened files limit for vagrant user
echo -e 'vagrant\t\t\t-\tnofile\t\t1000000' > /etc/security/limits.d/90-nofile.conf
echo 'kernel.perf_event_paranoid = -1' > /etc/sysctl.d/perf.conf
echo -1 > /proc/sys/kernel/perf_event_paranoid
# Start redis needed for tests
systemctl start redis
systemctl start redis
systemctl disable openresty
systemctl stop openresty
SHELL

config.vm.provision 'shell', privileged: false, name: "Install APIcast dependencies", inline: <<~'SHELL'
set -x -e
pip install --user hererocks
pushd app
hererocks lua_modules -r^ -l 5.1 --no-readline
curl -L https://raw.githubusercontent.com/3scale/s2i-openresty/ffb1c55533be866a97466915d7ef31c12bae688c/site_config.lua -o lua_modules/share/lua/5.1/luarocks/site_config.lua
make dependencies cpan
SHELL

mkdir -p ~/.systemtap
# needed for complete backtraces
# increase this if you start seeing stacks collapsed in impossible ways
# also try https://github.com/openresty/stapxx/commit/59ba231efba8725a510cd8d1d585aedf94670404
# to avoid MAXACTTION problems
cat <<- EOF > ~/.systemtap/rc
-D MAXSTRINGLEN=1024
EOF
SHELL
config.vm.provision "shell", privileged: false, name: "Install APIcast dependencies", path: 'script/install/apicast.sh', args: %w[app]
end
21 changes: 21 additions & 0 deletions script/install/apicast.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

set -x -e
pip install --user hererocks

if [ -n "$1" ]; then
cd "$1"
fi

"$HOME/.local/bin/hererocks" lua_modules -r^ -l 5.1 --no-readline
curl -L https://raw.githubusercontent.com/3scale/s2i-openresty/ffb1c55533be866a97466915d7ef31c12bae688c/site_config.lua -o lua_modules/share/lua/5.1/luarocks/site_config.lua
make dependencies cpan

mkdir -p ~/.systemtap
# needed for complete backtraces
# increase this if you start seeing stacks collapsed in impossible ways
# also try https://github.com/openresty/stapxx/commit/59ba231efba8725a510cd8d1d585aedf94670404
# to avoid MAXACTTION problems
cat <<- EOF > ~/.systemtap/rc
-D MAXSTRINGLEN=1024
EOF
20 changes: 20 additions & 0 deletions script/install/centos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

set -x -e

dnf -y install dnf-plugins-core

dnf config-manager --add-repo https://openresty.org/package/fedora/openresty.repo

yum -y install rsync
yum -y install openresty-resty openresty-debug openresty-debug-debuginfo openresty-pcre-debuginfo
yum -y install systemtap git httpd-tools
yum -y install luarocks
yum -y install perl-local-lib perl-App-cpanminus redis perl-open expect

yum -y groupinstall 'Development Tools'
yum -y install openssl-devel libev-devel

dnf debuginfo-install -y "kernel-core-$(uname -r)"

yum -y install python2-pip
29 changes: 29 additions & 0 deletions script/install/circleci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
set -x -e

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECDCAD72428D7C01
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C8CAB6595FDFF622

codename=$(lsb_release -sc)
tee /etc/apt/sources.list.d/ddebs.list << EOF
deb http://ddebs.ubuntu.com/ ${codename} main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-security main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-proposed main restricted universe multiverse
EOF

wget -qO - https://openresty.org/package/pubkey.gpg | apt-key add -
add-apt-repository -y "deb http://openresty.org/package/ubuntu ${codename} main"
add-apt-repository -y ppa:niedbalski/systemtap-backports

apt update

echo manual > /etc/init/openresty.override

apt install -y cpanminus liblocal-lib-perl libev-dev luarocks python-pip systemtap
apt install -y openresty openresty-debug-dbgsym openresty-openssl-debug-dbgsym openresty-pcre-dbgsym openresty-zlib-dbgsym

kernel=$(uname -r)
apt install -y "linux-headers-${kernel}" "linux-image-${kernel}-dbgsym"

service openresty stop
64 changes: 64 additions & 0 deletions script/install/utilities.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh
set -x -e -u

user=${SUDO_USER:-${CIRCLECI_USER:-vagrant}}

# CircleCI forces use of SSH protocol everywhere, we need to reset it.
export HOME="/tmp"

# Clone various utilities
git clone https://github.com/openresty/stapxx.git /usr/local/stapxx || (cd /usr/local/stapxx && git pull)
git clone https://github.com/brendangregg/FlameGraph.git /usr/local/flamegraph || (cd /usr/local/flamegraph && git pull)
git clone https://github.com/openresty/openresty-systemtap-toolkit.git /usr/local/openresty-systemtap-toolkit || (cd /usr/local/openresty-systemtap-toolkit && git pull)
curl -L https://github.com/tsenart/vegeta/releases/download/v6.1.1/vegeta-v6.1.1-linux-amd64.tar.gz | tar -xz --overwrite -C /usr/local/bin/

git clone https://github.com/wg/wrk.git /usr/local/wrk || (cd /usr/local/wrk && git pull)
( cd /usr/local/wrk && make && mv wrk /usr/local/bin/ )

git clone https://github.com/lighttpd/weighttp.git /usr/local/weighttp || (cd /usr/local/weighttp && git pull)
( cd /usr/local/weighttp && gcc -O2 -DPACKAGE_VERSION='"0.4"' src/*.c -o weighttp -lev -lpthread && ln -sf "$(pwd)/weighttp" /usr/local/bin/ )

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

# Create stap++ executable always pointing to its proper location
echo '#!/bin/sh' > /usr/local/bin/stap++
echo 'exec /usr/local/stapxx/stap++ -I /usr/local/stapxx/tapset "$@"' >> /usr/local/bin/stap++
chmod +x /usr/local/bin/stap++

# shellcheck disable=SC2016
echo 'export PATH="lua_modules/bin:${PATH}"' > /etc/profile.d/rover.sh
chmod +x /etc/profile.d/rover.sh

# shellcheck disable=SC2016
echo 'eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)' > /etc/profile.d/perl.sh
chmod +x /etc/profile.d/perl.sh

if [ -n "${CIRCLE_SHELL_ENV:-}" ]; then
cat /etc/profile.d/rover.sh >> "${CIRCLE_SHELL_ENV}"
cat /etc/profile.d/perl.sh >> "${CIRCLE_SHELL_ENV}"
fi

mkdir -p /usr/share/lua/5.1/luarocks/ /usr/share/lua/5.3/luarocks/
curl -L https://raw.githubusercontent.com/3scale/s2i-openresty/ffb1c55533be866a97466915d7ef31c12bae688c/site_config.lua > /usr/share/lua/5.1/luarocks/site_config.lua
ln -sf /usr/share/lua/5.1/luarocks/site_config.lua /usr/share/lua/5.3/luarocks/site_config.lua

# Add various utilites to the PATH
ln -sf /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit
ln -sf /usr/local/flamegraph/*.pl /usr/local/bin/
ln -sf /usr/local/stapxx/samples/*.sxx /usr/local/bin/
# shellcheck disable=SC2046
ln -sf $(find /usr/local/openresty-systemtap-toolkit/ -maxdepth 1 -type f -executable -print) /usr/local/bin/

# Allow vagrant user to use systemtap
usermod -a -G stapusr,stapdev "${user}"

# Raise opened files limit for vagrant user
# shellcheck disable=SC1117
printf "%b${user}\t\t\t-\tnofile\t\t1000000" > /etc/security/limits.d/90-nofile.conf

echo 'kernel.perf_event_paranoid = -1' > /etc/sysctl.d/perf.conf
# shellcheck disable=SC2039
echo "-1" > /proc/sys/kernel/perf_event_paranoid

0 comments on commit 7fc66dc

Please sign in to comment.