Skip to content

Commit bc377e7

Browse files
authored
Merge pull request #152 from esl/distribute-modules-as-binaries
Distribute modules as binaries This PR introduces the following changes: - Cleanup of the integration testing - Since we moved REST API out of this repo, all the leftovers are removed - Extraction of amoc_code_server functionality from of amoc_scenario module: - now amoc_scenario is just a wrapper for behavior. - and amoc_code_server is responsible for modules' analysis and distribution of uploaded modules. - Modules' distribution is now based on binary representation, so it's language agnostic and can be reused for elixir. - comparison of the modules is based on MD5 - amoc_code_server_SUITE covers all the basic use cases and demonstrates some of the corner cases that are covered in amoc_code_server
2 parents ffff0fe + 6d4d273 commit bc377e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1438
-664
lines changed

Dockerfile

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
ARG otp_vsn=25.3
2-
FROM erlang:${otp_vsn}-slim AS builder
2+
FROM erlang:${otp_vsn}
33
MAINTAINER Erlang Solutions <mongoose-im@erlang-solutions.com>
44

5-
WORKDIR /amoc_build
5+
WORKDIR /amoc
6+
COPY ./ ./
67

7-
COPY ./rebar.config ./rebar.lock ./
8-
RUN rebar3 deps && rebar3 compile -d
8+
RUN make clean
9+
RUN make rel
910

10-
COPY ./integration_test integration_test
11-
COPY ./scenarios scenarios
12-
COPY ./priv priv
13-
COPY ./rel rel
14-
COPY ./src src
15-
16-
RUN rebar3 as demo release
17-
18-
ENV PATH "/amoc_build/_build/demo/rel/amoc/bin:${PATH}"
11+
ENV PATH "/amoc/_build/default/rel/amoc/bin:${PATH}"
1912

2013
CMD ["amoc", "foreground"]

Makefile

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,64 @@
1-
.PHONY: default rel compile clean ct test integration_test dialyzer xref console lint
1+
.PHONY: default rel deps compile clean ct lint dialyzer xref console
2+
.PHONY: test integration_test rerun_integration_test
23

34
REBAR = rebar3
45

56
ifdef SUITE
67
SUITE_OPTS = --suite $$SUITE
78
endif
89

9-
## this target is triggered when amoc is used as an erlang.mk dependency
10-
default:
11-
$(REBAR) compile
10+
default: compile
1211

1312
rel:
14-
$(REBAR) as demo tar
13+
$(REBAR) release
14+
15+
deps:
16+
$(REBAR) deps
17+
$(REBAR) compile --deps_only
1518

1619
compile:
17-
$(REBAR) as demo compile
20+
$(REBAR) compile
1821

1922
clean:
2023
rm -rf _build
21-
rm -rfv priv/scenarios_ebin/*.beam
2224

2325
ct:
24-
rm -rfv priv/scenarios_ebin/*.beam
25-
## eunit and ct commands always add a test profile to the run
26-
$(REBAR) ct --verbose $(SUITE_OPTS)
26+
## in order to run some specific test suite(s) you can override
27+
## the SUITE variable from the command line or as env variable:
28+
## make ct SUITE=some_test_SUITE
29+
## make ct SUITE=some_test_SUITE,another_test_SUITE
30+
## SUITE=some_test_SUITE make ct
31+
## SUITE=some_test_SUITE,another_test_SUITE make ct
32+
@ echo $(REBAR) ct --verbose $(SUITE_OPTS)
33+
@ $(REBAR) ct --verbose $(SUITE_OPTS)
2734

2835
lint:
2936
$(REBAR) as elvis lint
3037

3138
test: compile xref dialyzer ct lint
3239

3340
integration_test:
34-
./integration_test/stop_demo_cluster.sh
41+
./integration_test/stop_test_cluster.sh
3542
./integration_test/build_docker_image.sh
36-
./integration_test/start_demo_cluster.sh
43+
./integration_test/start_test_cluster.sh
3744
./integration_test/test_amoc_cluster.sh
3845
./integration_test/test_distribute_scenario.sh
3946
./integration_test/test_run_scenario.sh
4047
./integration_test/test_add_new_node.sh
4148

4249
rerun_integration_test:
43-
./integration_test/stop_demo_cluster.sh
44-
./integration_test/start_demo_cluster.sh
50+
./integration_test/stop_test_cluster.sh
51+
./integration_test/start_test_cluster.sh
4552
./integration_test/test_amoc_cluster.sh
4653
./integration_test/test_distribute_scenario.sh
4754
./integration_test/test_run_scenario.sh
4855
./integration_test/test_add_new_node.sh
4956

5057
dialyzer:
51-
$(REBAR) as demo dialyzer
58+
$(REBAR) dialyzer
5259

5360
xref:
54-
$(REBAR) as demo xref
61+
$(REBAR) xref
5562

5663
console:
5764
@echo "tests can be executed manually using ct:run/1 function:\n" \

elvis.config

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
filter => "*.erl",
55
ruleset => erl_files,
66
rules => [
7-
{elvis_style, invalid_dynamic_call, #{ignore => [amoc_user]}},
7+
{elvis_style, invalid_dynamic_call,
8+
#{ignore => [amoc_user, {amoc_code_server, get_md5, 1}]}},
89
{elvis_style, export_used_types, disable},
910
{elvis_style, no_throw, #{ignore => [{amoc_config, get, 2}] }},
1011
{elvis_text_style, line_length, #{skip_comments => whole_line }},
@@ -14,10 +15,14 @@
1415
filter => "*.erl",
1516
ruleset => erl_files,
1617
rules => [
17-
{elvis_style, function_naming_convention, #{regex => "^[a-z]([a-z0-9]*_?)*$"}},
18-
{elvis_style, atom_naming_convention, #{regex => "^[a-z]([a-z0-9]*_?)*(_SUITE)?$"}},
18+
{elvis_style, function_naming_convention,
19+
#{regex => "^[a-z]([a-z0-9]*_?)*$"}},
20+
{elvis_style, atom_naming_convention,
21+
#{regex => "^[a-z]([a-z0-9]*_?)*(_SUITE)?$"}},
22+
{elvis_style, invalid_dynamic_call, #{ignore => [amoc_code_server_SUITE]}},
1923
{elvis_style, dont_repeat_yourself, #{min_complexity => 50}},
2024
{elvis_style, no_debug_call, disable},
25+
{elvis_style, no_block_expressions, #{ignore => [amoc_code_server_SUITE]}},
2126
{elvis_style, no_throw, disable},
2227
{elvis_style, no_import, disable}
2328
]},

guides/coordinator.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ It’s guaranteed that all the *Coordination Actions* with `all` are executed af
3737

3838
## Example
3939

40-
This scenario will demonstrate how do the `users` interact with `amoc_coordinator`:
40+
This scenario shows how the `users` interact with `amoc_coordinator`:
4141

4242
```erlang
4343
-module(example).
@@ -114,7 +114,7 @@ User = 3
114114
Three new users showed up
115115

116116
User = 4
117-
% We have 4 and 4 rem 2 == 0 therefore users added to amoc_coordinator so all of the {3, _} actions are triggered:
117+
% We have 4 and 4 rem 2 == 0 therefore users added to amoc_coordinator so all of the {2, _} actions are triggered:
118118
Two new users showed up: Event = {coordinate,2}; User1 = {<0.1144.0>,4}; User2 = {<0.1143.0>,3}
119119
Two new users showed up: Event = {coordinate,2}; ListOfUsers = [{<0.1144.0>,4},{<0.1143.0>,3}]
120120
Two new users showed up: Event = {coordinate,2}

guides/local-run.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Everything you need to do is to create the release. To achieve that run:
44
`make rel`. Now you are ready to test our scenario locally with one Amoc node;
5-
to start the node run `_build/demo/rel/amoc/bin/amoc console`.
5+
to start the node run `_build/default/rel/amoc/bin/amoc console`.
66

77
Start `my_scenario` spawning 10 amoc users with IDs from range (1,10) inclusive.
88
```erlang

guides/scenario.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ It has to export two callback functions:
66
- `init/0` - called only once per test run on every node, at the very beginning.
77
It can be used for setting up initial (global) state: metrics, database connections, etc.
88
It can return an `ok` or a tuple `{ok, State}` from which the `State` may be passed to every user.
9-
- `start/1` or `start/2` - describes the actual scenario and is executed for
9+
- `start/1` or `start/2` - implements the actual scenario and is executed for
1010
each user, in the context of that user's process.
1111
The first argument is the given user's unique integer id.
1212
The second, which is optional, is the state, as returned from the `init/0` function.
13-
When the `start` function returns, it is executed again after some delay (60 seconds by default).
13+
14+
In addition to that, the scenario module can implement a `terminate/0,1` callback;
15+
it has one optional argument – the scenario state, as returned from the `init/0` function.
1416

1517
A typical scenario file will look like this:
1618

guides/telemetry.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,20 @@ metadata: #{type => add | remove}
2020

2121
## Throttle
2222

23+
### Init
24+
25+
Raised when a throttle mechanism is initialised.
26+
27+
```erlang
28+
event_name: [amoc, throttle, init]
29+
measurements: #{count => 1}
30+
metadata: #{name => atom()}
31+
```
32+
2333
### Rate
2434

2535
Raised when a throttle mechanism is initialised or its configured rate is changed.
36+
This event is raised only on the master node.
2637

2738
```erlang
2839
event_name: [amoc, throttle, rate]
@@ -50,13 +61,13 @@ measurements: #{count => 1}
5061
metadata: #{name => atom()}
5162
```
5263

53-
## Coordinate
64+
## Coordinator
5465

55-
Indicates when a coordinating event was raised, like a callback index being reached or a timeout being triggered
66+
Indicates when a coordinating event was raised, like a process being added for coordination or a timeout being triggered
5667

5768
### Event
5869
```erlang
59-
event_name: [amoc, coordinator, event]
70+
event_name: [amoc, coordinator, start | stop | add | reset | timeout]
6071
measurements: #{count => 1}
61-
metadata: #{type => atom()}
72+
metadata: #{name => atom()}
6273
```

integration_test/README.md

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,33 @@ In the Amoc repo root directory run:
99

1010
`./integration_test/build_docker_image.sh`
1111

12-
This command builds docker image `amoc:latest`.
12+
This command builds the `amoc:latest` docker image.
1313

14-
### 2. Start amoc demo cluster
14+
### 2. Start amoc test cluster
1515

16-
`./integration_test/start_demo_cluster.sh`
16+
`./integration_test/start_test_cluster.sh`
1717

18-
More information about the demo cluster can be found further in this document.
18+
This command requires the `amoc:latest` docker image to exist. More information about the test cluster can be found further in this document.
1919

20-
### 3. Check the amoc clustering is done properly
20+
### 3. Check that clustering is done properly
2121

2222
`./integration_test/test_amoc_cluster.sh`
2323

24-
This command verifies that clustering is done properly and metrics are reported
25-
from all the nodes.
24+
This command verifies that clustering is done properly.
2625

27-
### 4. Test installation of user scenario in amoc cluster
26+
### 4. Test distribution of a custom scenario in amoc cluster
2827

2928
`./integration_test/test_distribute_scenario.sh`
30-
31-
This command uploads a sample `dummy_scenario.erl` on the `amoc-master` node
32-
using `curl` and after uploading verifies that scenario is propagated to the
33-
worker nodes.
3429

35-
### 5. Run the uploaded scenario.
30+
This command checks distribution of the sample `dummy_scenario.erl` from the `amoc-master` node
31+
to the worker nodes.
32+
33+
### 5. Run the distributed scenario.
3634

3735
`./integration_test/test_run_scenario.sh`
3836

39-
This command starts execution of `dummy_scenario.erl` scenario (must be uploaded
40-
before this action)
37+
This command starts execution of `dummy_scenario.erl` scenario (it must be distributed
38+
prior to this action)
4139

4240
### 6. Add additional node to the cluster
4341

@@ -49,32 +47,31 @@ when the new amoc node joins.
4947

5048
### 7. Cleanup
5149

52-
To stop Amoc demo cluster run:
50+
To stop Amoc test cluster run:
5351

54-
`./integration_test/stop_demo_cluster.sh`
52+
`./integration_test/stop_test_cluster.sh`
5553

56-
## Demo cluster
54+
## Test cluster
5755

58-
To start the demo cluster you can run these commands:
56+
* To start the test cluster you can run these commands:
5957

6058
```
6159
./integration_test/build_docker_image.sh
62-
./integration_test/start_demo_cluster.sh
60+
./integration_test/start_test_cluster.sh
6361
```
6462

65-
When the demo cluster is up and running you can access its
66-
different components using the following addresses:
67-
* Amoc Swagger UI:
68-
* [amoc-master](http://localhost:4000/api-docs/)
69-
* [amoc-worker-1](http://localhost:4001/api-docs/)
70-
* [amoc-worker-2](http://localhost:4002/api-docs/)
71-
* [graphite](http://localhost:8080/) web interface
72-
* [grafana](http://localhost:3000/) - default username and password is `admin`/`admin`
63+
* To get the list of nodes in the amoc test cluster use the following command:
64+
65+
`docker compose -p "amoc-test-cluster" ps`
66+
67+
* To check the most recent `amoc-master` logs you can run this command:
68+
69+
`docker compose -p "amoc-test-cluster" logs --tail=100 amoc-master`
7370

74-
To check the most recent `amoc-master` logs you can run this command:
71+
* In order to attach to the `amoc-master` erlang node run the following command:
7572

76-
`docker-compose -p "amoc-demo-cluster" logs --tail=100 amoc-master`
73+
`docker compose -p "amoc-test-cluster" exec amoc-master amoc remote_console`
7774

78-
To attach to `amoc-master` node use the following command:
75+
* To open a shell inside the `amoc-master` container use this command:
7976

80-
`docker-compose -p "amoc-demo-cluster" exec amoc-master /home/amoc/amoc/bin/amoc remote_console`
77+
`docker compose -p "amoc-test-cluster" exec amoc-master bash`

integration_test/build_docker_image.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ cd "$git_root"
77
otp_vsn="${OTP_RELEASE:-25.3}"
88
echo "ERLANG/OTP '${otp_vsn}'"
99

10-
docker_compose build --build-arg otp_vsn=${otp_vsn}
10+
docker build \
11+
-f Dockerfile \
12+
-t amoc:latest \
13+
--build-arg "otp_vsn=${otp_vsn}" \
14+
.

integration_test/docker-compose.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
x-amoc-defaults: &amoc-defaults
2-
build:
3-
context: ../
4-
dockerfile: Dockerfile
2+
image: "amoc:latest"
53
networks:
64
- amoc-test-network
75
volumes:
@@ -10,14 +8,15 @@ x-amoc-defaults: &amoc-defaults
108
target: /extra_code_paths
119
environment:
1210
AMOC_NODES: "['amoc@amoc-master']"
13-
AMOC_EXTRA_CODE_PATHS: '["/extra_code_paths/test1", "/extra_code_paths/test2"]'
1411
healthcheck:
1512
test: "amoc status"
1613

1714
services:
1815
amoc-master:
1916
<<: *amoc-defaults
2017
hostname: "amoc-master"
18+
environment:
19+
AMOC_EXTRA_CODE_PATHS: '["/extra_code_paths/path1", "/extra_code_paths/path2"]'
2120
amoc-worker-1: &amoc-worker
2221
<<: *amoc-defaults
2322
hostname: "amoc-worker-1"

0 commit comments

Comments
 (0)