diff --git a/.github/workflows/build_and_test_with_resty_events.yml b/.github/workflows/build_and_test_with_resty_events.yml new file mode 100644 index 00000000..cb7abf07 --- /dev/null +++ b/.github/workflows/build_and_test_with_resty_events.yml @@ -0,0 +1,150 @@ +name: Build and test - with resty_events + +concurrency: + # for PR's cancel the running task, if another commit is pushed + group: ${{ github.workflow }} ${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +on: + pull_request: {} + workflow_dispatch: {} + push: + branches: + - main + - master + - release/** + +jobs: + build: + name: CI using lua-resty-events + runs-on: ubuntu-20.04 + strategy: + matrix: + openresty-version: [1.19.9.1, 1.21.4.1] + + steps: + - name: Update and install OS dependencies + run: | + sudo apt-get update && sudo apt-get install -y libssl-dev ssl-cert + sudo systemctl disable nginx + sudo systemctl stop nginx + + + - name: Set environment variables + env: + OPENRESTY_VER: ${{ matrix.openresty-version }} + RESTY_EVENTS_VER: 0.1.2 + LUAROCKS_VER: 3.9.0 + OPENSSL_VER: 1.1.1q + PCRE_VER: 8.45 + run: | + echo "INSTALL_ROOT=/home/runner/work/cache/install-root" >> $GITHUB_ENV + echo "DOWNLOAD_ROOT=/home/runner/work/cache/download-root" >> $GITHUB_ENV + echo "OPENRESTY=$OPENRESTY_VER" >> $GITHUB_ENV + echo "LUAROCKS=$LUAROCKS_VER" >> $GITHUB_ENV + echo "OPENSSL=$OPENSSL_VER" >> $GITHUB_ENV + echo "PCRE=$PCRE_VER" >> $GITHUB_ENV + echo "RESTY_EVENTS=$RESTY_EVENTS_VER" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=$HOME/install-root/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV + + - name: Checkout lua-resty-healthcheck + uses: actions/checkout@v3 + + - name: Lookup build cache + uses: actions/cache@v3 + id: cache-deps + with: + path: | + /home/runner/work/cache/install-root + /home/runner/work/cache/download-root + key: ${{ runner.os }}-${{ hashFiles('**/.github/workflows/build_and_test_with_resty_events.yml') }}-${{ matrix.openresty-version }} + + - name: Add to Path + if: steps.cache-deps.outputs.cache-hit != 'true' + run: echo "$INSTALL_ROOT/bin:$INSTALL_ROOT/nginx/sbin:$INSTALL_ROOT/luajit/bin:/usr/bin" >> $GITHUB_PATH + + - name: Build and install OpenSSL + if: steps.cache-deps.outputs.cache-hit != 'true' + run: | + curl -sSLO https://www.openssl.org/source/openssl-$OPENSSL.tar.gz + tar -xzf openssl-$OPENSSL.tar.gz + cd openssl-$OPENSSL + ./config -g shared -DPURIFY no-threads --prefix=$INSTALL_ROOT --openssldir=$INSTALL_ROOT no-unit-test + make + make install_sw + + - name: Checkout lua-resty-events + uses: actions/checkout@v3 + if: steps.cache-deps.outputs.cache-hit != 'true' + with: + repository: Kong/lua-resty-events + ref: refs/tags/0.1.0 + path: lua-resty-events + + - name: Build and install OpenResty + if: steps.cache-deps.outputs.cache-hit != true + run: | + curl -sSLO https://openresty.org/download/openresty-$OPENRESTY.tar.gz + tar -xzf openresty-$OPENRESTY.tar.gz + cd openresty-$OPENRESTY + ./configure \ + --prefix=$INSTALL_ROOT \ + --with-cc-opt='-I$INSTALL_ROOT/include' \ + --with-ld-opt='-L$INSTALL_ROOT/lib -Wl,-rpath,$INSTALL_ROOT/lib' \ + --with-pcre-jit \ + --with-http_ssl_module \ + --with-http_realip_module \ + --with-http_stub_status_module \ + --with-http_v2_module \ + --without-http_encrypted_session_module \ + --with-stream_realip_module \ + --with-stream_ssl_preread_module \ + --add-module=../lua-resty-events \ + --with-pcre + make + make install + make install LUA_LIBDIR=$INSTALL_ROOT/lualib + + - name: Install LuaRocks + if: steps.cache-deps.outputs.cache-hit != 'true' + run: | + curl -sSLO https://luarocks.org/releases/luarocks-$LUAROCKS.tar.gz + tar -xzf luarocks-$LUAROCKS.tar.gz + cd luarocks-$LUAROCKS + ./configure \ + --prefix=$INSTALL_ROOT \ + --lua-suffix=jit \ + --with-lua=$INSTALL_ROOT/luajit \ + --with-lua-include=$INSTALL_ROOT/luajit/include/luajit-2.1 + make build + make install + + - name: Install manual dependencies + if: steps.cache-deps.outputs.cache-hit != 'true' + run: | + luarocks install luacheck + + - name: Install Test::NGINX + if: steps.cache-deps.outputs.cache-hit != 'true' + run: | + sudo apt-get install cpanminus + cpanm --notest --local-lib=$HOME/perl5 local::lib && eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) + cpanm --notest Test::Nginx + + - name: Install lua-resty-events + if: steps.cache-deps.outputs.cache-hit != 'true' + run: | + cd lua-resty-events + OPENRESTY_PREFIX=$INSTALL_ROOT PREFIX=$INSTALL_ROOT LUA_LIB_DIR=$INSTALL_ROOT/lualib make install + + - name: Install lua-resty-healthcheck + run: luarocks make + + - name: Run tests + env: + PATH: ${{ env.INSTALL_ROOT }}/bin:${{ env.INSTALL_ROOT }}/nginx/sbin:${{ env.INSTALL_ROOT }}/luajit/bin:/usr/bin + TEST_NGINX_BINARY: ${{ env.INSTALL_ROOT }}/nginx/sbin/nginx + run: | + eval `luarocks path` + eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) + TEST_NGINX_RANDOMIZE=1 prove -I. -r t/with_resty-events diff --git a/.github/workflows/build_and_test_with_worker_events.yml b/.github/workflows/build_and_test_with_worker_events.yml new file mode 100644 index 00000000..581c9265 --- /dev/null +++ b/.github/workflows/build_and_test_with_worker_events.yml @@ -0,0 +1,75 @@ +name: Build and test - with worker_events + +concurrency: + # for PR's cancel the running task, if another commit is pushed + group: ${{ github.workflow }} ${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +on: + pull_request: {} + workflow_dispatch: {} + push: + branches: + - main + - master + +jobs: + build: + name: CI using lua-resty-worker-events + runs-on: ubuntu-20.04 + strategy: + matrix: + openresty-version: [1.19.9.1, 1.21.4.1] + + steps: + - name: Update and install OS dependencies + run: | + sudo apt-get update && sudo apt-get install -y libssl-dev ssl-cert + sudo systemctl disable nginx + sudo systemctl stop nginx + + + - name: Set environment variables + env: + OPENRESTY_VER: ${{ matrix.openresty-version }} + run: | + echo "/usr/local/openresty/nginx/sbin" >> $GITHUB_PATH + + - name: Checkout lua-resty-healthcheck + uses: actions/checkout@v3 + + - name: Install OpenResty ${{ matrix.openresty-version }} + env: + OPENRESTY_VER: ${{ matrix.openresty-version }} + run: | + sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates + wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add - + echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/openresty.list + sudo apt-get update + sudo apt-get -y install openresty=$OPENRESTY_VER-1~focal1 + + - name: Install LuaRocks + run: sudo apt-get install -y luarocks + + - name: Install manual dependencies + run: | + sudo luarocks install luacheck + sudo luarocks install lua-resty-worker-events 1.0.0 + + - name: Install Test::NGINX + run: | + sudo apt-get install cpanminus + cpanm --notest --local-lib=$HOME/perl5 local::lib && eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) + cpanm --notest Test::Nginx + + - name: Checkout lua-resty-healthcheck + uses: actions/checkout@v3 + + - name: Install lua-resty-healthcheck + run: sudo luarocks make + + - name: Run tests + run: | + eval `luarocks path` + eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) + TEST_NGINX_RANDOMIZE=1 prove -I. -r t/with_worker-events diff --git a/.github/workflows/latest_os.yml b/.github/workflows/latest_os.yml deleted file mode 100644 index b4e5e5e4..00000000 --- a/.github/workflows/latest_os.yml +++ /dev/null @@ -1,189 +0,0 @@ -name: Build and test for Ubuntu latest - -on: [push, pull_request] - -jobs: - build: - name: Build and install dependencies - runs-on: ubuntu-latest - strategy: - matrix: - openresty-version: [1.21.4.1, 1.19.9.1] - luarocks-version: [3.8.0] - - steps: - - name: Update and install OS dependencies - run: sudo apt-get update && sudo apt-get install -y libssl-dev ssl-cert - - - name: Set environment variables - env: - LUAROCKS_VER: ${{ matrix.luarocks-version }} - OPENRESTY_VER: ${{ matrix.openresty-version }} - run: | - echo "DOWNLOAD_PATH=$HOME/download-root" >> $GITHUB_ENV - export DOWNLOAD_PATH=$HOME/download-root - echo "INSTALL_PATH=$HOME/install-root" >> $GITHUB_ENV - export INSTALL_PATH=$HOME/install-root - echo "LUAROCKS_VER=$LUAROCKS_VER" >> $GITHUB_ENV - echo "OPENRESTY_VER=$OPENRESTY_VER" >> $GITHUB_ENV - export LUAROCKS_PREFIX=$INSTALL_PATH/luarocks-$LUAROCKS_VER - echo "LUAROCKS_PREFIX=$LUAROCKS_PREFIX" >> $GITHUB_ENV - export OPENRESTY_PREFIX=$INSTALL_PATH/openresty-$OPENRESTY_VER - echo "OPENRESTY_PREFIX=$OPENRESTY_PREFIX" >> $GITHUB_ENV - echo "PATH=$DOWNLOAD_PATH:$LUAROCKS_PREFIX/bin:$OPENRESTY_PREFIX/nginx/sbin:$DOWNLOAD_PATH/cpanm:$PATH" >> $GITHUB_ENV - - - name: Checkout lua-resty-healthcheck - uses: actions/checkout@v2 - - - name: Lookup build cache - uses: actions/cache@v2 - id: cache-deps - with: - path: | - ${{ env.INSTALL_PATH }} - ~/perl5 - key: ${{ runner.os }}-${{ matrix.openresty-version }}-${{ hashFiles('.github/workflows/latest_os.yml') }} - - - name: Create needed paths - if: steps.cache-deps.outputs.cache-hit != 'true' - run: | - mkdir -p $DOWNLOAD_PATH - mkdir -p $INSTALL_PATH - - - name: Build and install OpenResty ${{ matrix.openresty-version }} - if: steps.cache-deps.outputs.cache-hit != 'true' - run: | - if [ ! -d $INSTALL_PATH/openresty-$OPENRESTY_VER ]; - then - pushd $DOWNLOAD_PATH - echo "Downloading from http://openresty.org/download/openresty-$OPENRESTY_VER.tar.gz" - wget -O $DOWNLOAD_PATH/openresty-$OPENRESTY_VER.tar.gz http://openresty.org/download/openresty-$OPENRESTY_VER.tar.gz - echo "tar -zxf $DOWNLOAD_PATH/openresty-$OPENRESTY_VER.tar.gz" - tar -zxf $DOWNLOAD_PATH/openresty-$OPENRESTY_VER.tar.gz - echo "result: $?" - pushd openresty-$OPENRESTY_VER - ./configure --prefix=$OPENRESTY_PREFIX - make - make install - popd - popd - fi - - - name: Build and install LuaRocks ${{ matrix.luarocks-version }} - if: steps.cache-deps.outputs.cache-hit != 'true' - run: | - if [ ! -d $INSTALL_PATH/luarocks-$LUAROCKS_VER ]; - then - pushd $DOWNLOAD_PATH - echo "Downloading from https://luarocks.github.io/luarocks/releases/luarocks-$LUAROCKS_VER.tar.gz" - wget -O $DOWNLOAD_PATH/luarocks-$LUAROCKS_VER.tar.gz https://luarocks.github.io/luarocks/releases/luarocks-$LUAROCKS_VER.tar.gz - tar -zxf $DOWNLOAD_PATH/luarocks-$LUAROCKS_VER.tar.gz - pushd luarocks-$LUAROCKS_VER - ./configure --prefix=$LUAROCKS_PREFIX --with-lua=$OPENRESTY_PREFIX/luajit --with-lua-include=$OPENRESTY_PREFIX/luajit/include/luajit-2.1 --lua-suffix=jit - make build - make install - popd - luarocks install luacheck - popd - fi - - - name: Install Test::NGINX - if: steps.cache-deps.outputs.cache-hit != 'true' - run: | - if [ ! -f $DOWNLOAD_PATH/cpanm ]; - then - wget -O $DOWNLOAD_PATH/cpanm https://cpanmin.us/ - chmod +x $DOWNLOAD_PATH/cpanm - cpanm --notest --local-lib=$HOME/perl5 local::lib && eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) - cpanm --notest Test::Nginx - fi - - lint: - name: Static code analysis - runs-on: ubuntu-latest - needs: build - strategy: - matrix: - openresty-version: [1.21.4.1, 1.19.9.1] - luarocks-version: [3.8.0] - steps: - - name: Checkout lua-resty-healthcheck - uses: actions/checkout@v2 - - - name: Set environment variables - env: - LUAROCKS_VER: ${{ matrix.luarocks-version }} - OPENRESTY_VER: ${{ matrix.openresty-version }} - run: | - echo "DOWNLOAD_PATH=$HOME/download-root" >> $GITHUB_ENV - export DOWNLOAD_PATH=$HOME/download-root - echo "INSTALL_PATH=$HOME/install-root" >> $GITHUB_ENV - export INSTALL_PATH=$HOME/install-root - echo "LUAROCKS_VER=$LUAROCKS_VER" >> $GITHUB_ENV - echo "OPENRESTY_VER=$OPENRESTY_VER" >> $GITHUB_ENV - export LUAROCKS_PREFIX=$INSTALL_PATH/luarocks-$LUAROCKS_VER - echo "LUAROCKS_PREFIX=$LUAROCKS_PREFIX" >> $GITHUB_ENV - export OPENRESTY_PREFIX=$INSTALL_PATH/openresty-$OPENRESTY_VER - echo "OPENRESTY_PREFIX=$OPENRESTY_PREFIX" >> $GITHUB_ENV - echo "PATH=$DOWNLOAD_PATH:$LUAROCKS_PREFIX/bin:$OPENRESTY_PREFIX/nginx/sbin:$DOWNLOAD_PATH/cpanm:$PATH" >> $GITHUB_ENV - - - name: Lookup build cache - uses: actions/cache@v2 - id: cache-deps - with: - path: | - ${{ env.INSTALL_PATH }} - ~/perl5 - key: ${{ runner.os }}-${{ matrix.openresty-version }}-${{ hashFiles('.github/workflows/latest_os.yml') }} - - - name: Lint code - run: | - eval `luarocks path` - luacheck lib - - install-and-test: - name: Test lua-resty-healthcheck - runs-on: ubuntu-latest - needs: build - strategy: - matrix: - openresty-version: [1.21.4.1, 1.19.9.1] - luarocks-version: [3.8.0] - steps: - - name: Checkout lua-resty-healthcheck - uses: actions/checkout@v2 - - - name: Set environment variables - env: - LUAROCKS_VER: ${{ matrix.luarocks-version }} - OPENRESTY_VER: ${{ matrix.openresty-version }} - run: | - echo "DOWNLOAD_PATH=$HOME/download-root" >> $GITHUB_ENV - export DOWNLOAD_PATH=$HOME/download-root - echo "INSTALL_PATH=$HOME/install-root" >> $GITHUB_ENV - export INSTALL_PATH=$HOME/install-root - echo "LUAROCKS_VER=$LUAROCKS_VER" >> $GITHUB_ENV - echo "OPENRESTY_VER=$OPENRESTY_VER" >> $GITHUB_ENV - export LUAROCKS_PREFIX=$INSTALL_PATH/luarocks-$LUAROCKS_VER - echo "LUAROCKS_PREFIX=$LUAROCKS_PREFIX" >> $GITHUB_ENV - export OPENRESTY_PREFIX=$INSTALL_PATH/openresty-$OPENRESTY_VER - echo "OPENRESTY_PREFIX=$OPENRESTY_PREFIX" >> $GITHUB_ENV - echo "PATH=$DOWNLOAD_PATH:$LUAROCKS_PREFIX/bin:$OPENRESTY_PREFIX/nginx/sbin:$DOWNLOAD_PATH/cpanm:$PATH" >> $GITHUB_ENV - - - name: Lookup build cache - uses: actions/cache@v2 - id: cache-deps - with: - path: | - ${{ env.INSTALL_PATH }} - ~/perl5 - key: ${{ runner.os }}-${{ matrix.openresty-version }}-${{ hashFiles('.github/workflows/latest_os.yml') }} - - - name: Install lua-resty-healthcheck - run: luarocks make - - - name: Run tests - run: | - eval `luarocks path` - eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) - TEST_NGINX_RANDOMIZE=1 prove -I. -r t diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index fad9f649..1c21b062 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,5 +1,10 @@ name: Lint +concurrency: + # for PR's cancel the running task, if another commit is pushed + group: ${{ github.workflow }} ${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + on: pull_request: {} workflow_dispatch: {} @@ -37,7 +42,7 @@ jobs: - name: Lua Check if: steps.changed-files.outputs.any_changed == 'true' - uses: Kong/public-shared-actions/code-check-actions/lua-lint@33449c46c6766a3d3c8f167cc383381225862b36 + uses: Kong/public-shared-actions/code-check-actions/lua-lint@c03e30a36e8a2dde5cbd463229a96aaad7ccad24 with: additional_args: '--no-default-config --config .luacheckrc' files: ${{ steps.changed-files.outputs.all_changed_files }} diff --git a/.github/workflows/old_os.yml b/.github/workflows/old_os.yml deleted file mode 100644 index c93e8102..00000000 --- a/.github/workflows/old_os.yml +++ /dev/null @@ -1,189 +0,0 @@ -name: Build and test for Ubuntu 20.04 - -on: [push, pull_request] - -jobs: - build: - name: Build and install dependencies - runs-on: ubuntu-20.04 - strategy: - matrix: - openresty-version: [1.21.4.1, 1.19.9.1] - luarocks-version: [3.8.0] - - steps: - - name: Update and install OS dependencies - run: sudo apt-get update && sudo apt-get install -y libssl-dev ssl-cert - - - name: Set environment variables - env: - LUAROCKS_VER: ${{ matrix.luarocks-version }} - OPENRESTY_VER: ${{ matrix.openresty-version }} - run: | - echo "DOWNLOAD_PATH=$HOME/download-root" >> $GITHUB_ENV - export DOWNLOAD_PATH=$HOME/download-root - echo "INSTALL_PATH=$HOME/install-root" >> $GITHUB_ENV - export INSTALL_PATH=$HOME/install-root - echo "LUAROCKS_VER=$LUAROCKS_VER" >> $GITHUB_ENV - echo "OPENRESTY_VER=$OPENRESTY_VER" >> $GITHUB_ENV - export LUAROCKS_PREFIX=$INSTALL_PATH/luarocks-$LUAROCKS_VER - echo "LUAROCKS_PREFIX=$LUAROCKS_PREFIX" >> $GITHUB_ENV - export OPENRESTY_PREFIX=$INSTALL_PATH/openresty-$OPENRESTY_VER - echo "OPENRESTY_PREFIX=$OPENRESTY_PREFIX" >> $GITHUB_ENV - echo "PATH=$DOWNLOAD_PATH:$LUAROCKS_PREFIX/bin:$OPENRESTY_PREFIX/nginx/sbin:$DOWNLOAD_PATH/cpanm:$PATH" >> $GITHUB_ENV - - - name: Checkout lua-resty-healthcheck - uses: actions/checkout@v2 - - - name: Lookup build cache - uses: actions/cache@v2 - id: cache-deps - with: - path: | - ${{ env.INSTALL_PATH }} - ~/perl5 - key: ${{ runner.os }}-${{ matrix.openresty-version }}-${{ hashFiles('.github/workflows/old_os.yml') }} - - - name: Create needed paths - if: steps.cache-deps.outputs.cache-hit != 'true' - run: | - mkdir -p $DOWNLOAD_PATH - mkdir -p $INSTALL_PATH - - - name: Build and install OpenResty ${{ matrix.openresty-version }} - if: steps.cache-deps.outputs.cache-hit != 'true' - run: | - if [ ! -d $INSTALL_PATH/openresty-$OPENRESTY_VER ]; - then - pushd $DOWNLOAD_PATH - echo "Downloading from http://openresty.org/download/openresty-$OPENRESTY_VER.tar.gz" - wget -O $DOWNLOAD_PATH/openresty-$OPENRESTY_VER.tar.gz http://openresty.org/download/openresty-$OPENRESTY_VER.tar.gz - echo "tar -zxf $DOWNLOAD_PATH/openresty-$OPENRESTY_VER.tar.gz" - tar -zxf $DOWNLOAD_PATH/openresty-$OPENRESTY_VER.tar.gz - echo "result: $?" - pushd openresty-$OPENRESTY_VER - ./configure --prefix=$OPENRESTY_PREFIX - make - make install - popd - popd - fi - - - name: Build and install LuaRocks ${{ matrix.luarocks-version }} - if: steps.cache-deps.outputs.cache-hit != 'true' - run: | - if [ ! -d $INSTALL_PATH/luarocks-$LUAROCKS_VER ]; - then - pushd $DOWNLOAD_PATH - echo "Downloading from https://luarocks.github.io/luarocks/releases/luarocks-$LUAROCKS_VER.tar.gz" - wget -O $DOWNLOAD_PATH/luarocks-$LUAROCKS_VER.tar.gz https://luarocks.github.io/luarocks/releases/luarocks-$LUAROCKS_VER.tar.gz - tar -zxf $DOWNLOAD_PATH/luarocks-$LUAROCKS_VER.tar.gz - pushd luarocks-$LUAROCKS_VER - ./configure --prefix=$LUAROCKS_PREFIX --with-lua=$OPENRESTY_PREFIX/luajit --with-lua-include=$OPENRESTY_PREFIX/luajit/include/luajit-2.1 --lua-suffix=jit - make build - make install - popd - luarocks install luacheck - popd - fi - - - name: Install Test::NGINX - if: steps.cache-deps.outputs.cache-hit != 'true' - run: | - if [ ! -f $DOWNLOAD_PATH/cpanm ]; - then - wget -O $DOWNLOAD_PATH/cpanm https://cpanmin.us/ - chmod +x $DOWNLOAD_PATH/cpanm - cpanm --notest --local-lib=$HOME/perl5 local::lib && eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) - cpanm --notest Test::Nginx - fi - - lint: - name: Static code analysis - runs-on: ubuntu-20.04 - needs: build - strategy: - matrix: - openresty-version: [1.21.4.1, 1.19.9.1] - luarocks-version: [3.8.0] - steps: - - name: Checkout lua-resty-healthcheck - uses: actions/checkout@v2 - - - name: Set environment variables - env: - LUAROCKS_VER: ${{ matrix.luarocks-version }} - OPENRESTY_VER: ${{ matrix.openresty-version }} - run: | - echo "DOWNLOAD_PATH=$HOME/download-root" >> $GITHUB_ENV - export DOWNLOAD_PATH=$HOME/download-root - echo "INSTALL_PATH=$HOME/install-root" >> $GITHUB_ENV - export INSTALL_PATH=$HOME/install-root - echo "LUAROCKS_VER=$LUAROCKS_VER" >> $GITHUB_ENV - echo "OPENRESTY_VER=$OPENRESTY_VER" >> $GITHUB_ENV - export LUAROCKS_PREFIX=$INSTALL_PATH/luarocks-$LUAROCKS_VER - echo "LUAROCKS_PREFIX=$LUAROCKS_PREFIX" >> $GITHUB_ENV - export OPENRESTY_PREFIX=$INSTALL_PATH/openresty-$OPENRESTY_VER - echo "OPENRESTY_PREFIX=$OPENRESTY_PREFIX" >> $GITHUB_ENV - echo "PATH=$DOWNLOAD_PATH:$LUAROCKS_PREFIX/bin:$OPENRESTY_PREFIX/nginx/sbin:$DOWNLOAD_PATH/cpanm:$PATH" >> $GITHUB_ENV - - - name: Lookup build cache - uses: actions/cache@v2 - id: cache-deps - with: - path: | - ${{ env.INSTALL_PATH }} - ~/perl5 - key: ${{ runner.os }}-${{ matrix.openresty-version }}-${{ hashFiles('.github/workflows/old_os.yml') }} - - - name: Lint code - run: | - eval `luarocks path` - luacheck lib - - install-and-test: - name: Test lua-resty-healthcheck - runs-on: ubuntu-20.04 - needs: build - strategy: - matrix: - openresty-version: [1.21.4.1, 1.19.9.1] - luarocks-version: [3.8.0] - steps: - - name: Checkout lua-resty-healthcheck - uses: actions/checkout@v2 - - - name: Set environment variables - env: - LUAROCKS_VER: ${{ matrix.luarocks-version }} - OPENRESTY_VER: ${{ matrix.openresty-version }} - run: | - echo "DOWNLOAD_PATH=$HOME/download-root" >> $GITHUB_ENV - export DOWNLOAD_PATH=$HOME/download-root - echo "INSTALL_PATH=$HOME/install-root" >> $GITHUB_ENV - export INSTALL_PATH=$HOME/install-root - echo "LUAROCKS_VER=$LUAROCKS_VER" >> $GITHUB_ENV - echo "OPENRESTY_VER=$OPENRESTY_VER" >> $GITHUB_ENV - export LUAROCKS_PREFIX=$INSTALL_PATH/luarocks-$LUAROCKS_VER - echo "LUAROCKS_PREFIX=$LUAROCKS_PREFIX" >> $GITHUB_ENV - export OPENRESTY_PREFIX=$INSTALL_PATH/openresty-$OPENRESTY_VER - echo "OPENRESTY_PREFIX=$OPENRESTY_PREFIX" >> $GITHUB_ENV - echo "PATH=$DOWNLOAD_PATH:$LUAROCKS_PREFIX/bin:$OPENRESTY_PREFIX/nginx/sbin:$DOWNLOAD_PATH/cpanm:$PATH" >> $GITHUB_ENV - - - name: Lookup build cache - uses: actions/cache@v2 - id: cache-deps - with: - path: | - ${{ env.INSTALL_PATH }} - ~/perl5 - key: ${{ runner.os }}-${{ matrix.openresty-version }}-${{ hashFiles('.github/workflows/old_os.yml') }} - - - name: Install lua-resty-healthcheck - run: luarocks make - - - name: Run tests - run: | - eval `luarocks path` - eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) - TEST_NGINX_RANDOMIZE=1 prove -I. -r t diff --git a/.github/workflows/sast.yml b/.github/workflows/sast.yml index 17738a65..b5fe5dc5 100644 --- a/.github/workflows/sast.yml +++ b/.github/workflows/sast.yml @@ -1,5 +1,10 @@ name: SAST +concurrency: + # for PR's cancel the running task, if another commit is pushed + group: ${{ github.workflow }} ${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + on: pull_request: paths: @@ -28,4 +33,4 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: Kong/public-shared-actions/security-actions/semgrep@33449c46c6766a3d3c8f167cc383381225862b36 + - uses: Kong/public-shared-actions/security-actions/semgrep@c03e30a36e8a2dde5cbd463229a96aaad7ccad24 diff --git a/README.md b/README.md index 9eb784ff..53c54bb0 100644 --- a/README.md +++ b/README.md @@ -88,20 +88,6 @@ programmatic API using functions such as `checker:report_http_status(host, port, See the [online LDoc documentation](http://kong.github.io/lua-resty-healthcheck) for the complete API. -## Async behaviour - -Since this library heavily uses the SHM to share data between workers, it must -use locks. The locks themselves need access to `ngx.sleep` which is not available -in all contexts. Most notably not during startup; `init` and `init_worker`. - -The library will try and acquire the lock and update, but if it fails it will -schedule an async update (timer with delay 0). - -One workaround for this in the initial phases would be to replace `ngx.sleep` with -a version that does a blocking sleep in `init`/`init_worker`. This will enable -the usage of locks in those phases. - - ## History Versioning is strictly based on [Semantic Versioning](https://semver.org/) @@ -117,33 +103,43 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/) * push commit and tag * upload rock to luarocks: `luarocks upload rockspecs/[name] --api-key=abc` +### 3.0.0 (12-Oct-2023) + +* Perf: optimize by localizing some functions [#92](https://github.com/Kong/lua-resty-healthcheck/pull/92) (backport) +* Fix: Generate fresh default http_statuses within new() [#83](https://github.com/Kong/lua-resty-healthcheck/pull/83) (backport) + ### 2.0.0 (22-Sep-2020) -* BREAKING: fallback for deprecated top-level field `type` is now removed +**Note:** +Changes in this version has been discarded from current & future development. +Below you can see it's changelog but be aware that these changes might not be present in `3.y.z` unless they are explicitly stated in `3.y.z`, `1.6.3` or previous releases. Read more at: [release 3.0.0 (#142)](https://github.com/Kong/lua-resty-healthcheck/pull/142) and [chore(*): realign master branch to 3.0.0 release (#144)](https://github.com/Kong/lua-resty-healthcheck/pull/144) + +> * BREAKING: fallback for deprecated top-level field `type` is now removed (deprecated since `0.5.0`) [#56](https://github.com/Kong/lua-resty-healthcheck/pull/56) -* BREAKING: Bump `lua-resty-worker-events` dependency to `2.0.0`. This makes +> * BREAKING: Bump `lua-resty-worker-events` dependency to `2.0.0`. This makes a lot of the APIs in this library asynchronous as the worker events `post` and `post_local` won't anymore call `poll` on a running worker automatically, for more information, see: https://github.com/Kong/lua-resty-worker-events#200-16-september-2020 -* BREAKING: tcp_failures can no longer be 0 on http(s) checks (unless http(s)_failures +> * BREAKING: tcp_failures can no longer be 0 on http(s) checks (unless http(s)_failures are also set to 0) [#55](https://github.com/Kong/lua-resty-healthcheck/pull/55) -* feature: Added support for https_sni [#49](https://github.com/Kong/lua-resty-healthcheck/pull/49) -* fix: properly log line numbers by using tail calls [#29](https://github.com/Kong/lua-resty-healthcheck/pull/29) -* fix: when not providing a hostname, use IP [#48](https://github.com/Kong/lua-resty-healthcheck/pull/48) -* fix: makefile; make install -* feature: added a status version field [#54](https://github.com/Kong/lua-resty-healthcheck/pull/54) -* feature: add headers for probe request [#54](https://github.com/Kong/lua-resty-healthcheck/pull/54) -* fix: exit early when reloading during a probe [#47](https://github.com/Kong/lua-resty-healthcheck/pull/47) -* fix: prevent target-list from being nil, due to async behaviour [#44](https://github.com/Kong/lua-resty-healthcheck/pull/44) -* fix: replace timer and node-wide locks with resty-timer, to prevent interval +> * feature: Added support for https_sni [#49](https://github.com/Kong/lua-resty-healthcheck/pull/49) +> * fix: properly log line numbers by using tail calls [#29](https://github.com/Kong/lua-resty-healthcheck/pull/29) +> * fix: when not providing a hostname, use IP [#48](https://github.com/Kong/lua-resty-healthcheck/pull/48) +> * fix: makefile; make install +> * feature: added a status version field [#54](https://github.com/Kong/lua-resty-healthcheck/pull/54) +> * feature: add headers for probe request [#54](https://github.com/Kong/lua-resty-healthcheck/pull/54) +> * fix: exit early when reloading during a probe [#47](https://github.com/Kong/lua-resty-healthcheck/pull/47) +> * fix: prevent target-list from being nil, due to async behaviour [#44](https://github.com/Kong/lua-resty-healthcheck/pull/44) +> * fix: replace timer and node-wide locks with resty-timer, to prevent interval skips [#59](https://github.com/Kong/lua-resty-healthcheck/pull/59) -* change: added additional logging on posting events [#25](https://github.com/Kong/lua-resty-healthcheck/issues/25) -* fix: do not run out of timers during init/init_worker when adding a vast +> * change: added additional logging on posting events [#25](https://github.com/Kong/lua-resty-healthcheck/issues/25) +> * fix: do not run out of timers during init/init_worker when adding a vast amount of targets [#57](https://github.com/Kong/lua-resty-healthcheck/pull/57) -* fix: do not call on the module table, but use a method for locks. Also in +> * fix: do not call on the module table, but use a method for locks. Also in [#57](https://github.com/Kong/lua-resty-healthcheck/pull/57) + ### 1.6.3 (06-Sep-2023) * Feature: Added support for https_sni [#49](https://github.com/Kong/lua-resty-healthcheck/pull/49) (backport) diff --git a/docs/index.html b/docs/index.html index 6492afd6..ec07accb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -27,8 +27,10 @@
resty.healthcheck
Healthcheck library for OpenResty.
-- - -
Some notes on the usage of this library:
+Some notes on the usage of this library:
Each target will have 4 counters, 1 success counter and 3 failure - counters ('http', 'tcp', and 'timeout'). Any failure will only reset the - success counter, but a success will reset all three failure counters.
All targets are uniquely identified by their IP address and port number - combination, most functions take those as arguments.
All keys in the SHM will be namespaced by the healthchecker name as
- provided to the new function. Hence no collissions will occur on shm-keys
- as long as the name
is unique.
Active healthchecks will be synchronized across workers, such that only - a single active healthcheck runs.
Events will be raised in every worker, see lua-resty-worker-events - for details.
Each target will have 4 counters, 1 success counter and 3 failure +counters (‘http’, ‘tcp’, and ‘timeout’). Any failure will only reset the +success counter, but a success will reset all three failure counters.
All targets are uniquely identified by their IP address and port number +combination, most functions take those as arguments.
All keys in the SHM will be namespaced by the healthchecker name as
+provided to the new function. Hence no collissions will occur on shm-keys
+as long as the name
is unique.
Active healthchecks will be synchronized across workers, such that only +a single active healthcheck runs.
Events will be raised in every worker, see lua-resty-worker-events +for details.
run_locked (self, key, fn, ...) | +Acquire a lock and run a function
+
+ The function call itself is wrapped with pcall to protect against + exception. |
+
Clear all healthcheck data. | |
checker:delayed_clear (delay) | +Clear all healthcheck data after a period of time. | +
checker:get_target_status (ip, port, hostname) | Get the current status of the target. |