Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/acp 38937 #23

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"caseSensitive": false,
"words": [
//proper noun
"luacov",
"strftime",
"ncruces",
"satyrius",
Expand Down
59 changes: 58 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
build-alb:
name: Build alb
runs-on: ubuntu-22.04
outputs:
go-coverage: ${{ steps.alb-test.outputs.GO_COVERAGE }}
lua-coverage: ${{ steps.nginx-test.outputs.LUA_COVERAGE }}
strategy:
matrix:
platform:
Expand Down Expand Up @@ -91,20 +94,30 @@ jobs:
name: ${{ env.artifactName }}
path: ${{ env.artifactPath }}
- name: test alb go
id: alb-test
if: ${{ (matrix.platform == 'linux/amd64' ) && (!inputs.skip_test) }}
env:
MATRIX_PLATFORM: "${{ matrix.platform }}"
run: |
set -x
echo "FROM --platform=\${{ matrix.platform }} | $MATRIX_PLATFORM "
./scripts/run-like-github-actions.sh test-alb-go
go_cov=$(grep total ./coverage.report | awk '{print $3}' | awk -F% '{print $1}' )
echo "go_cov is |||$go_cov|||"
echo "GO_COVERAGE=$go_cov" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: test alb nginx
id: nginx-test
if: ${{ (matrix.platform == 'linux/amd64' ) && (!inputs.skip_test) }}
env:
MATRIX_PLATFORM: "${{matrix.platform }}"
run: |
set -x
./scripts/run-like-github-actions.sh test-alb-nginx
cat ./luacov.summary
line_cov=$(cat ./luacov.summary |grep Total|awk '{print $4}'|awk -F% '{print $1}')
echo "LUA_COVERAGE=$line_cov" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
release-alb:
name: Release alb
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -156,6 +169,8 @@ jobs:
run: |
echo "gen alb chart"
env
export branch=$(echo "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" | sed 's|/|-|g')
echo "$branch"
./scripts/run-like-github-actions.sh gen-chart-artifact
- uses: actions/upload-artifact@v4
with:
Expand All @@ -170,4 +185,46 @@ jobs:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
./scripts/run-like-github-actions.sh release-alb
./scripts/run-like-github-actions.sh release-alb
update-coverage:
name: update coverage
runs-on: ubuntu-22.04
needs: [build-alb,release-alb]
env:
GO_COVERAGE: ${{ needs.build-alb.outputs.go-coverage }}
LUA_COVERAGE: ${{ needs.build-alb.outputs.lua-coverage }}
steps:
- name: debug
run: |
env
set -x
echo "GO_COVERAGE=$GO_COVERAGE"
echo "LUA_COVERAGE=$LUA_COVERAGE"
- name: Checkout gh-pages
uses: actions/checkout@v3
with:
ref: gh-pages
- name: Create Badges
shell: bash
run: |
set -x
npm i -g badgen-cli
GO_COLOR=$(node -p '+process.env.GO_COVERAGE >= 95 ? `green` : `orange`')
LUA_COLOR=$(node -p '+process.env.LUA_COVERAGE >= 95 ? `green` : `orange`')
mkdir -p badges
badgen -j go-coverage -s "$GO_COVERAGE%" -c $GO_COLOR > badges/go-coverage.svg
badgen -j lua-coverage -s $LUA_COVERAGE% -c $LUA_COLOR > badges/lua-coverage.svg
- name: Deploy Badges
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Update badges [skip ci]"
branch: gh-pages
skip_fetch: true
skip_checkout: true
# Without this, will get Error:
# Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/coverage-badge-action/coverage-badge-action/action.yml'.
# Did you forget to run actions/checkout before running your local action?
- name: Checkout Back
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ template/nginx/lua/vendor/opentelemetry
*.kconf
docs/.obsidian
template/share/dhparam.pem
luacov-html/
luacov.stats.out
8 changes: 8 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
reporter = "html"
html = {}
include = {
".*/template/nginx/lua/.*"
}
exclude = {
".*/template/nginx/lua/vendor/.*",
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# ALB -- Another Load Balancer
[![go-cov](https://alauda.github.io/alb/badges/go-coverage.svg)](https://alauda.github.io/alb/badges/go-coverage.svg)
[![lua-cov](https://alauda.github.io/alb/badges/lua-coverage.svg)](https://alauda.github.io/alb/badges/lua-coverage.svg)

ALB (Another Load Balancer) is a Kubernetes Gateway powered by [OpenResty](https://github.com/openresty/) with years of production experience from Alauda.

Expand Down
4 changes: 2 additions & 2 deletions deploy/chart/alb/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: alauda-alb2
version: v3.19.0-beta.7.g6099cfbc
version: v3.19.0-beta.8.gf67be197
description: alauda loadbalancer version 2
apiVersion: v2
annotations:
release: alpha
branch: master
commit: 6099cfbceb4ab9806e8b2a8dd6b71ea9386e1998
commit: f67be197f2155851fce8140fc7cdba87c096d7a3
4 changes: 2 additions & 2 deletions deploy/chart/alb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ global:
code: gitlab-ce.alauda.cn/container-platform/alb2
support_arm: true
repository: acp/alb2
tag: v3.19.0-beta.7.g6099cfbc
tag: v3.19.0-beta.8.gf67be197
nginx:
code: gitlab-ce.alauda.cn/container-platform/alb2
support_arm: true
repository: acp/alb-nginx
tag: "v3.19.0-beta.7.g6099cfbc"
tag: "v3.19.0-beta.8.gf67be197"
resources:
alb:
limits:
Expand Down
1 change: 1 addition & 0 deletions scripts/run-like-ci-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ fi
platform=${MATRIX_PLATFORM:-linux/amd64}
echo "platform $platform"
docker run --user root --network=host --platform $platform -v $PWD:/acp-alb-test -t $image sh -c 'cd /acp-alb-test ;/acp-alb-test/scripts/nginx-test.sh'
# docker run --user root --network=host --platform $platform -v $PWD:/acp-alb-test -it $image sh
2 changes: 2 additions & 0 deletions scripts/run-like-github-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function alb-gh-test-alb-nginx() (
local image=$(docker images | grep theseedoaa/alb | head -1 | awk '{printf "%s:%s",$1,$2}')
echo "test nginx $image"
./scripts/run-like-ci-nginx.sh $image
ls
cat ./luacov.summary
)

function alb-gh-build-alb() (
Expand Down
15 changes: 12 additions & 3 deletions template/actions/alb-nginx-install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ openresty=$1
if [[ -n "$OPENRESTY_BUILD_TRARGRT_DIR" ]]; then
openresty=$OPENRESTY_BUILD_TRARGRT_DIR
fi
if [[ -z "$openresty" && -f "/usr/local/openresty" ]]; then

if [[ -z "$openresty" && -d "/usr/local/openresty" ]]; then
openresty="/usr/local/openresty"
echo "use default $openresty "
fi
if [[ -z "$openresty" && -f "/opt/openresty" ]]; then

if [[ -z "$openresty" && -d "/opt/openresty" ]]; then
openresty="/opt/openresty"
echo "use default $openresty "
fi
Expand All @@ -28,7 +30,13 @@ if [ -z "$openresty" ]; then
exit 1
fi

export PATH=$openresty/bin:$PATH
function alb-ng-install-test-deps() (
luarocks --lua-version 5.1 --tree $openresty/luajit install luacov
luarocks --lua-version 5.1 --tree $openresty/luajit install cluacov
luarocks --lua-version 5.1 install luacov
luarocks --lua-version 5.1 install luacov-console
luarocks --lua-version 5.1 install luacov-html
)

function alb-ng-install-deps() (
env
Expand Down Expand Up @@ -168,6 +176,7 @@ function install-lua-resty-http() (
rm -rf ./.$name
return
)

function install-opentelemetry-lua() (
# md5sum ./opentelemetry-lua-0.2.6.zip
# 77f4488e669c80d53c3d9977f35017ed ./opentelemetry-lua-0.2.6.zip
Expand Down
19 changes: 15 additions & 4 deletions template/actions/alb-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ if [[ -n "$CUR_ALB_BASE" ]]; then
fi

function alb-install-nginx-test-dependency() {
apk update && apk add luarocks luacheck lua perl-app-cpanminus wget curl make build-base perl-dev git neovim bash yq jq tree fd openssl
apk update && apk add luarocks luacheck lua-dev lua perl-app-cpanminus wget curl make build-base perl-dev git neovim bash yq jq tree fd openssl
mkdir /tmp && export TMP=/tmp # luarocks need this
cp /usr/bin/luarocks-5.1 /usr/bin/luarocks
cpanm --mirror-only --mirror https://mirrors.tuna.tsinghua.edu.cn/CPAN/ -v --notest Test::Nginx IPC::Run YAML::PP
luarocks
(
source ./template/actions/alb-nginx-install-deps.sh
alb-ng-install-test-deps
)
}

function alb-install-nginx-test-dependency-ubuntu() {
Expand Down Expand Up @@ -41,8 +48,7 @@ fi

function alb-test-all-in-ci-nginx() {
# base image build-harbor.alauda.cn/3rdparty/alb-nginx:v3.9-57-gb40a7de

set -e # exit on err
set -ex # exit on err
echo alb is $ALB
export PATH=$PATH:/alb/tools/
which tweak_gen
Expand All @@ -54,12 +60,17 @@ function alb-test-all-in-ci-nginx() {
local end_install=$(date +"%Y %m %e %T.%6N")
# alb-lint-lua # TODO
local end_check=$(date +"%Y %m %e %T.%6N")
export LUACOV=true
test-nginx-in-ci
local end_test=$(date +"%Y %m %e %T.%6N")
echo "start " $start
echo "install " $end_install
echo "check" $end_check
echo "test" $end_test
pwd
luacov-console $PWD/template/nginx/lua/
luacov-console $PWD/template/nginx/lua/ -s
luacov-console $PWD/template/nginx/lua/ -s >./luacov.summary
}

function test-nginx-local() {
Expand Down Expand Up @@ -169,7 +180,7 @@ function configmap_to_file() {

function alb-nginx-watch-log() (
echo "watch log"
tail -F ./template/servroot/logs/error.http.log | python -u -c '
tail -F ./template/servroot/logs/error.log | python -u -c '
import sys
for line in sys.stdin:
if "keepalive connection" in line:
Expand Down
1 change: 1 addition & 0 deletions template/nginx/lua/balancer/balance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function _M.sync_backends()
local backends_data = shm.get_backends()
if not backends_data then
balancers = {}
ngx_log(ngx.ERR, "no backends data")
return
end

Expand Down
12 changes: 12 additions & 0 deletions template/nginx/lua/config/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ local ipc = {

function _M.init_l4()
local cache = _M
local ok, err = ev.configure {
shm = subsystem .. "_ipc_shared_dict", -- defined by "lua_shared_dict"
timeout = 5, -- life time of event data in shm
interval = 1, -- poll interval (seconds)

wait_interval = 0.010, -- wait before retry fetching event data
wait_max = 0.5 -- max wait time before discarding event
}
if not ok then
ngx.log(ngx.ERR, "failed to start event system: ", err)
return
end
cache.init_mlcache("rule_cache", subsystem .. "_alb_cache", {lru_size = 2000, ttl = 30, neg_ttl = 5, ipc = ipc})
end

Expand Down
3 changes: 3 additions & 0 deletions template/nginx/lua/config/policy_fetch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ function _M.update_policy(policy_raw, via)

local old_policy_raw = shm.get_policy_raw()
local old_policy_data = common.json_decode(old_policy_raw)
if old_policy_raw == policy_raw then
return
end

if common.table_equals(policy_data, old_policy_data) then
return
Expand Down
2 changes: 1 addition & 1 deletion template/nginx/lua/phase/init_worker_phase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local cache = require "config.cache"
if subsys.is_http_subsystem() then
cache.init_l7()
else
cache.init_l7()
cache.init_l4()
end

if ngx_worker.id() == 0 then
Expand Down
24 changes: 22 additions & 2 deletions template/t/AlaudaLib.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ our @EXPORT_OK = qw( gen_main_config gen_ngx_tmpl_via_block gen_http_only gen_lu

my $ALB_BASE = $ENV{'TEST_BASE'};

my $LUACOV = $ENV{'LUACOV'};


sub tgl_log(@msgs) {
warn "[tgl_log] @msgs\n";
}

tgl_log("lua cov $LUACOV");

sub gen_lua_test($block) {
my $lua_test_mode = "false";
my $lua_test_full = '';
Expand Down Expand Up @@ -95,11 +99,26 @@ sub write_file($policy,$p) {
}

sub gen_custom_init($block) {
my $init_worker = " init_worker_by_lua_file $ALB_BASE/nginx/lua/phase/init_worker_phase.lua; ";
my $init_worker = <<__END;
init_worker_by_lua_block {
require("mock_worker_init").init_worker()
}
__END

if (defined $block->disable_init_worker) {
$init_worker = "";
}
my $init = "";
if ($LUACOV eq "true") {
$init = <<__END;
init_by_lua_block {
if ngx.config.subsystem == "http" then
require 'luacov.tick'
jit.off()
end
}
__END
}

if (defined $block->enable_nyi) {
my $name = $block->enable_nyi;
Expand Down Expand Up @@ -245,7 +264,8 @@ sub gen_ngx_tmpl_via_block($block) {
my $mock_backend = gen_mock_backend($block->mock_backend // "");
my $http_config = $block->http_config // "";
my $lua_test_full = gen_lua_test($block);
my $lua_path= "/usr/local/lib/lua/?.lua;$ALB_BASE/nginx/lua/?.lua;$ALB_BASE/t/?.lua;$ALB_BASE/t/lib/?.lua;$ALB_BASE/nginx/lua/vendor/?.lua;;";
my $default_lua_path = "/usr/local/lib/lua/?.lua;$ALB_BASE/nginx/lua/?.lua;$ALB_BASE/nginx/lua/vendor/?.lua;";
my $lua_path= "$default_lua_path;$ALB_BASE/t/?.lua;$ALB_BASE/?.lua;$ALB_BASE/t/lib/?.lua;;";

my $default_ngx_cfg = gen_ngx_tmpl_conf($init_full,$stream_config,$lua_path,$mock_backend,$http_config,$lua_test_full);
$default_ngx_cfg = gen_https_port_config($block->alb_https_port // "",$default_ngx_cfg);
Expand Down
4 changes: 0 additions & 4 deletions template/t/e2e/error_page/error.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ _EOC_


log_level("info");
workers(4);
master_process_enabled("on");
no_shuffle();
no_root_location();
Expand All @@ -24,9 +23,6 @@ run_tests();
__DATA__
=== TEST 1: error page test
--- policy eval: ""
--- http_config eval: $::http_config
--- disable_init_worker
--- init_worker_eval: require("mock_worker_init").init_worker()
--- timeout: 9999999
--- lua_test_eval: require("e2e.error_page.error").test()
Loading
Loading