Merge remote-tracking branch 'xinyu/fix_relup_testcases' into 0623-fix-relup

This commit is contained in:
Zaiming (Stone) Shi 2022-06-24 06:00:16 +02:00
commit 0d6c4e0996
3 changed files with 77 additions and 54 deletions

View File

@ -1,36 +1,41 @@
-module(http_server). -module(http_server).
-import(minirest, [ return/0 -import(minirest, [
, return/1 return/0,
]). return/1
]).
-export([ start/0 -export([
, stop/0 start/0,
]). stop/0
]).
-rest_api(#{ name => get_counter -rest_api(#{
, method => 'GET' name => get_counter,
, path => "/counter" method => 'GET',
, func => get_counter path => "/counter",
, descr => "Check counter" func => get_counter,
}). descr => "Check counter"
-rest_api(#{ name => add_counter }).
, method => 'POST' -rest_api(#{
, path => "/counter" name => add_counter,
, func => add_counter method => 'POST',
, descr => "Counter plus one" path => "/counter",
}). func => add_counter,
descr => "Counter plus one"
}).
-export([ get_counter/2 -export([
, add_counter/2 get_counter/2,
]). add_counter/2
]).
start() -> start() ->
application:ensure_all_started(minirest), application:ensure_all_started(minirest),
ets:new(relup_test_message, [named_table, public]), ets:new(relup_test_message, [named_table, public]),
Handlers = [{"/", minirest:handler(#{modules => [?MODULE]})}], Handlers = [{"/", minirest:handler(#{modules => [?MODULE]})}],
Dispatch = [{"/[...]", minirest, Handlers}], Dispatch = [{"/[...]", minirest, Handlers}],
minirest:start_http(?MODULE, #{socket_opts => [inet, {port, 8080}]}, Dispatch). minirest:start_http(?MODULE, #{socket_opts => [inet, {port, 7077}]}, Dispatch).
stop() -> stop() ->
ets:delete(relup_test_message), ets:delete(relup_test_message),
@ -39,12 +44,12 @@ stop() ->
get_counter(_Binding, _Params) -> get_counter(_Binding, _Params) ->
return({ok, ets:info(relup_test_message, size)}). return({ok, ets:info(relup_test_message, size)}).
add_counter(_Binding, Params) -> add_counter(_Binding, Params) ->
case lists:keymember(<<"payload">>, 1, Params) of case lists:keymember(<<"payload">>, 1, Params) of
true -> true ->
{value, {<<"id">>, ID}, Params1} = lists:keytake(<<"id">>, 1, Params), {value, {<<"id">>, ID}, Params1} = lists:keytake(<<"id">>, 1, Params),
ets:insert(relup_test_message, {ID, Params1}); ets:insert(relup_test_message, {ID, Params1});
_ -> _ ->
ok ok
end, end,
return(). return().

View File

@ -1,7 +1,6 @@
[config var=PROFILE] [config var=PROFILE]
[config var=PACKAGE_PATH] [config var=PACKAGE_PATH]
[config var=BENCH_PATH] [config var=BENCH_PATH]
[config var=ONE_MORE_EMQX_PATH]
[config var=VSN] [config var=VSN]
[config var=OLD_VSNS] [config var=OLD_VSNS]
@ -16,16 +15,17 @@
???Eshell ???Eshell
???> ???>
!http_server:start(). !http_server:start().
?Start http_server listener on 8080 successfully. ?Start http_server listener on 7077 successfully.
?ok ?ok
?> ?>
[shell emqx1] [shell emqx1]
!cd $PACKAGE_PATH !cd $PACKAGE_PATH
!mkdir -p emqx1 !mkdir -p emqx1
!tar -C emqx1 -zxf ${PROFILE}-$(echo $old_vsn | sed -r 's/[v|e]//g')-*-ubuntu20.04-amd64.tar.gz !tar -C emqx -zxf ${PROFILE}-$(echo $old_vsn | sed -r 's/[v|e]//g')-*-ubuntu20.04-amd64.tar.gz
?SH-PROMPT ?SH-PROMPT
!cd emqx1
!cd emqx
!export EMQX_NODE_NAME='emqx1@127.0.0.1' !export EMQX_NODE_NAME='emqx1@127.0.0.1'
!./bin/emqx start !./bin/emqx start
?EMQX .* is started successfully! ?EMQX .* is started successfully!
@ -33,15 +33,18 @@
[shell emqx2] [shell emqx2]
!cd $PACKAGE_PATH !cd $PACKAGE_PATH
!tar -C emqx2 -zxf ${PROFILE}-$(echo $old_vsn | sed -r 's/[v|e]//g')-*-ubuntu20.04-amd64.tar.gz
!mkdir -p emqx2 !mkdir -p emqx2
!tar -C emqx -zxf ${PROFILE}-$(echo $old_vsn | sed -r 's/[v|e]//g')-*-ubuntu20.04-amd64.tar.gz
?SH-PROMPT ?SH-PROMPT
!cd emqx2 !cd emqx2
!export EMQX_NODE_NAME='emqx2@127.0.0.1' !export EMQX_NODE__NAME='emqx2@127.0.0.1'
!export EMQX_listeners__tcp__default__bind=2883 !export EMQX_STATSD__SERVER='127.0.0.1:8124'
!export EMQX_listeners__ssl__default__bind=9883 !export EMQX_LISTENERS__TCP__DEFAULT__BIND='0.0.0.0:1882'
!export EMQX_listeners__ws__default__bind=9083 !export EMQX_LISTENERS__SSL__DEFAULT__BIND='0.0.0.0:8882'
!export EMQX_listeners__wss__default__bind=9084 !export EMQX_LISTENERS__WS__DEFAULT__BIND='0.0.0.0:8082'
!export EMQX_LISTENERS__WSS__DEFAULT__BIND='0.0.0.0:8085'
!export EMQX_DASHBOARD__LISTENERS__HTTP__BIND='0.0.0.0:18082'
!./bin/emqx start !./bin/emqx start
?EMQX .* is started successfully! ?EMQX .* is started successfully!
?SH-PROMPT ?SH-PROMPT
@ -54,12 +57,24 @@
???["emqx1@127.0.0.1","emqx2@127.0.0.1"] ???["emqx1@127.0.0.1","emqx2@127.0.0.1"]
?SH-PROMPT ?SH-PROMPT
# TODO find another way to create resource ## create a webhook data bridge with id "my_webhook"
# !./bin/emqx_ctl resources create 'web_hook' -i 'resource:691c29ba' -c '{"url": "http://127.0.0.1:8080/counter", "method": "POST"}' !curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/bridges' -X 'POST' -H 'Content-Type: application/json' --data-binary '{"name":"my_webhook","method":"post","url":"http://127.0.0.1:7077/counter","headers":{"content-type":"application/json"},"pool_size":4,"enable_pipelining":100,"connect_timeout":"5s","request_timeout":"5s","max_retries":3,"type":"webhook","ssl":{"enable":false,"verify":"verify_none"}}' | jq '.status'
# ?created ?connected
# ?SH-PROMPT ?SH-PROMPT
# !./bin/emqx_ctl rules create 'SELECT * FROM "t/#"' '[{"name":"data_to_webserver", "params": {"$$resource": "resource:691c29ba"}}]'
# ?created ## create a rule that uses the webhook as action, the rule id = "rule_edsy"
!curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/rules' -X 'POST' -H 'Content-Type: application/json' --data-binary '{"id":"rule_edsy","sql":"SELECT\n *\nFROM\n \"t/#\"","actions":["webhook:my_webhook"]}' | jq '.id'
?rule_edsy
?SH-PROMPT
[shell emqx1]
## verify the bridges and rules are sync to the other node
!curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/bridges/webhook:my_webhook' -X 'GET' -H 'Content-Type: application/json' | jq '.name'
?my_webhook
?SH-PROMPT
!curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/rules/rule_edsy' -X 'GET' -H 'Content-Type: application/json' | jq '.id'
?rule_edsy
?SH-PROMPT
[shell bench] [shell bench]
!cd $BENCH_PATH !cd $BENCH_PATH
@ -153,14 +168,18 @@
!sleep 5 !sleep 5
?SH-PROMPT ?SH-PROMPT
# TODO adjust rule metrics query API !curl --user admin:public --silent --show-error http://localhost:18083/api/v5/rules | jq --raw-output ".[0].node_metrics[] | select(.node==\"emqx@127.0.0.1\") | .metrics.matched"
# !curl --user admin:public --silent --show-error http://localhost:18083/api/v5/rules | jq --raw-output ".[0].node_metrics[] | select(.node==\"emqx@127.0.0.1\") | .metrics.matched" ?300
# ?300 ?SH-PROMPT
# ?SH-PROMPT
# !curl --user admin:public --silent --show-error http://localhost:18083/api/v5/rules | jq --raw-output ".[0].node_metrics[] | select(.node==\"emqx@127.0.0.1\") | .metrics.\"actions.success\"" !curl --user admin:public --silent --show-error http://localhost:18083/api/v5/rules | jq --raw-output ".[0].node_metrics[] | select(.node==\"emqx@127.0.0.1\") | .metrics.\"actions.success\""
# ?\{"data":(29[0-9])|(300),"code":0\} ?\{"data":(29[0-9])|(300),"code":0\}
# ?SH-PROMPT ?SH-PROMPT
## The /counter API is provided by .ci/fvt_test/http_server
!curl http://127.0.0.1:7077/counter
?\{"data":(29[0-9])|(300),"code":0\}
?SH-PROMPT
[shell emqx2] [shell emqx2]
!cat log/emqx.log.1 |grep -v 691c29ba |tail -n 100 !cat log/emqx.log.1 |grep -v 691c29ba |tail -n 100

View File

@ -15,6 +15,8 @@ on:
jobs: jobs:
relup_test: relup_test:
runs-on: aws-amd64
strategy: strategy:
matrix: matrix:
profile: profile:
@ -32,13 +34,13 @@ jobs:
arch: arch:
- amd64 - amd64
runs-on: ubuntu-20.04
container: "ghcr.io/emqx/emqx-builder/5.0-16:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}" container: "ghcr.io/emqx/emqx-builder/5.0-16:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}"
defaults: defaults:
run: run:
shell: bash shell: bash
steps: steps:
- uses: AutoModality/action-clean@v1
- uses: actions/setup-python@v2 - uses: actions/setup-python@v2
with: with:
python-version: '3.8' python-version: '3.8'
@ -67,10 +69,8 @@ jobs:
- name: Get old vsn - name: Get old vsn
run: | run: |
set -x set -x
OLD_VSNS="$(emqx/scripts/relup-base-vsns.sh ${{ matrix.profile }} | xargs echo -n)" echo "OLD_VSNS=$(emqx/scripts/relup-base-vsns.sh ${{ matrix.profile }} | xargs echo -n)" >> $GITHUB_ENV
NOW_VSN=$(emqx/pkg-vsn.sh ${{ matrix.profile }}) echo "NOW_VSN=$(emqx/pkg-vsn.sh ${{ matrix.profile }})" >> $GITHUB_ENV
echo "OLD_VSNS=$OLD_VSNS" >> $GITHUB_ENV
echo "NOW_VSN=$NOW_VSN" >> $GITHUB_ENV
- name: build emqx - name: build emqx
env: env:
@ -101,7 +101,6 @@ jobs:
--var PROFILE=$PROFILE \ --var PROFILE=$PROFILE \
--var PACKAGE_PATH=$(pwd)/packages \ --var PACKAGE_PATH=$(pwd)/packages \
--var BENCH_PATH=$(pwd)/emqtt-bench \ --var BENCH_PATH=$(pwd)/emqtt-bench \
--var ONE_MORE_EMQX_PATH=$(pwd)/one_more_emqx \
--var VSN="$NOW_VSN" \ --var VSN="$NOW_VSN" \
--var OLD_VSNS="$OLD_VSNS" \ --var OLD_VSNS="$OLD_VSNS" \
emqx/.ci/fvt_tests/relup.lux emqx/.ci/fvt_tests/relup.lux