Skip to content

Commit 46f44f6

Browse files
authored
Merge pull request #147 from esl/hex_package
Hex package preparations
2 parents 66eb4d4 + 184c38f commit 46f44f6

24 files changed

+218
-222
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ _build
1818
*.iml
1919
rebar3.crashdump
2020
*~
21+
doc/

README.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,9 @@ All the XMPP scenarios can be found [here](https://github.com/esl/amoc-arsenal-x
1515

1616
---------------------------------------------------------------------
1717
In order to implement and run locally your scenarios, follow the chapters about
18-
[developing](doc/scenario.md) and [running](doc/local-run.md) a scenario
18+
[developing](guides/scenario.md) and [running](guides/local-run.md) a scenario
1919
locally.
20-
Before [setting up the distributed environment](doc/distributed.md),
20+
Before [setting up the distributed environment](guides/distributed.md),
2121
please read through the configuration overview.
22-
If you wish to run load tests via http api,
23-
take a look at the [REST API](doc/http-api.md) chapter.
2422

25-
### Table of Contents
26-
- [Developing a scenario](doc/scenario.md)
27-
- [Running locally](doc/local-run.md)
28-
- [Configuration](doc/configuration.md)
29-
- [Setting up distributed environment](doc/distributed.md)
30-
- [Running load test](doc/distributed-run.md)
31-
- [REST API](doc/http-api.md)
32-
- [Amoc throttle](doc/amoc_throttle.md)
33-
- [Amoc coordinator](doc/amoc_coordinator.md)
23+
To see the full documentation, see [hexdocs](https://hexdocs.pm/amoc).
Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Configuration
22

33
Amoc is configured through environment variables (uppercase with prefix ``AMOC_``).
4-
Note that the environment variables are evaluated as erlang code
4+
Note that the environment variables are evaluated as Erlang code.
55

66
Amoc supports the following generic configuration parameters:
77

@@ -25,12 +25,60 @@ Amoc supports the following generic configuration parameters:
2525

2626
In the same manner you can also define your own entries to configure the scenario.
2727

28+
## Required Variables
29+
2830
The ``amoc_config:get/1`` and ``amoc_config:get/2`` interfaces can be used to get
2931
parameters required for your scenario, however every scenario must declare (using
3032
`-required_variable(...)` attributes) all the required parameters in advance. For more
3133
information, see the example [scenario module](../integration_test/dummy_scenario.erl)
3234

33-
Scenario configuration also can be set/updated at runtime using REST API.
35+
Scenario configuration also can be set/updated at runtime using an API.
36+
37+
```erlang
38+
-required_variable(#{name => Name, description => Description,
39+
default_value => Value,
40+
update => UpdateFn,
41+
verification => VerificationFn}).
42+
```
43+
where
44+
45+
### `name`
46+
* **Syntax:** atom
47+
* **Example:** `name = var1`
48+
* **Default:** this field is mandatory
49+
50+
### `description`
51+
* **Syntax:** A string describing how this variable is used, can be extracted by APIs to document the behaviour
52+
* **Example:** `description = "a description of this variable"`
53+
* **Default:** this field is mandatory
54+
55+
### `default_value`
56+
* **Syntax:** value of the expected type
57+
* **Example:** `default_value = 10`
58+
* **Default:** `undefined`
59+
60+
### `verification`
61+
* **Syntax:** `none`, a list of allowed values, or an `mfa` of arity `1`
62+
* **Example:** `verification = {?MODULE, is_binary, 1}`
63+
* **Default:** `none`
64+
65+
A verification function that will check the given value is correct. It is trigger for verifying the initial values, including the default value, and before updated values are applied.
66+
- If it is set to `none`, all values are allowed.
67+
- If it is set to a list of values, any given value checks that the new value is in such allowlist.
68+
- If it is an `mfa`, the given function will be called on the given value. This function
69+
must be pure and return a boolean or a `{true, NewValue} | {false, Reason}`. It can also be used for preprocessing of the input value by returning `{true, NewValue}`.
70+
71+
### `update`
72+
* **Syntax:** `read_only`, `none`, or an `mfa` of arity 2
73+
* **Example:** `update = {?MODULE, update, 2}`
74+
* **Default:** `read_only`
75+
76+
An action to take when the value of this variable is updated. It is triggered at runtime when updates to the value are applied.
77+
- If it is set to `read_only`, updates will fail.
78+
- If it is set to `none`, all updates are allowed.
79+
- If it is an `mfa`, the given function will be called on the old and new value.
80+
81+
## Reasonale
3482

3583
NB: the reason why the `-required_variable(...)` is preferred over the usual behaviour
3684
callback is because the orchestration tools can easily extract the attributes even
@@ -46,7 +94,7 @@ compilation of the module. As an example, a module:
4694
cannot be compiled without the ``some_unavailable_header.hrl`` file, but we still
4795
can parse it and extract the attributes:
4896
```
49-
Eshell V10.3 (abort with ^G)
97+
Eshell V14.0 (press Ctrl+G to abort, type help(). for help)
5098
1> c(example).
5199
example.erl:2: can't find include file "some_unavailable_header.hrl"
52100
error
@@ -62,5 +110,4 @@ error
62110
[{"some",value},
63111
{another,"value"},
64112
{yet,<<"another">>,"value"}]
65-
66113
```
Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# amoc_coordinator
1+
## API
22

3-
## Module
4-
5-
`amoc_coordinator`
3+
See `amoc_coordinator`.
64

75
## Description
86

@@ -20,8 +18,8 @@ If more then one of the *Coordination Items* matching the `NumberOfUsers` is tri
2018
For example if the *Coordination Plan* is `[{2, Act1}, {3, Act2}]` then on the 6th user calling `add`, `Act1` will be called with 2 users passed and `Act2` will be called with 3 users passed.
2119

2220
*Coordination Actions* may be one of the following:
23-
- `fun(Event) -> any()` - this type of action does not care about particular users, but only about the number of them;
24-
- `fun(Event, ListOfUsersData) -> any()` - this type of action gets `ListOfUsersData` which is a list of `{Pid, Data}` tuples with `Pid`s passed by users calling `amoc_coordinator:add/2` or `amoc_coordinator:add/3`;
21+
- `fun(Event) -> any()` - this type of action does not care about particular users, but only about the number of them;
22+
- `fun(Event, ListOfUsersData) -> any()` - this type of action gets `ListOfUsersData` which is a list of `{Pid, Data}` tuples with `Pid`s passed by users calling `amoc_coordinator:add/2` or `amoc_coordinator:add/3`;
2523
- `fun(Event, User1, User2) -> any()` - this type of action gets `distinct pairs` from the batch of users `User1` and `User2` which are `{Pid, Data}` tuples with `Pid`s passed by users calling `amoc_coordinator:add/2` or `amoc_coordinator:add/3`;
2624

2725
where an `Event` is a `{EventType, NumOfUsers}` tuple, in which `NumOfUsers` is the number of users passed to the event.
@@ -37,44 +35,6 @@ It’s guaranteed that all the *Coordination Actions* with `all` are executed af
3735
- Eg. for `[a, b]`, the `distinct pairs` collection is `[{a, b}]`;
3836
- Eg. for `[a, b, c]`, the `distinct pairs` collection is `[{a, b}, {a, c}, {b, c}]`.
3937

40-
## Exports
41-
42-
#### `start(CoordinatorName, CoordinationPlan) -> ok | error`
43-
#### `start(CoordinatorName, CoordinationPlan, Timeout) -> ok | error`
44-
45-
##### Types
46-
```erlang
47-
CoordinatorName :: atom()
48-
CoordinationPlan :: [ CoordinationItem ]
49-
CoordinationItem :: {NumberOfUsers :: pos_integer() | all, CoordinationActions}
50-
CoordinationActions :: [ CoordinationActions ] | CoordinationAction
51-
CoordinationAction ::
52-
fun(Event) -> any() |
53-
fun(Event, ListOfUsersData) -> any() |
54-
fun(Event, MaybeUser, MaybeUser) -> any()
55-
Event :: {EventType, NumOfUsers}
56-
EventType :: coordinate | timeout | stop | reset
57-
NumOfUsers :: non_neg_integer()
58-
ListOfUsersData :: [ User ]
59-
MaybeUser :: undefined | User
60-
User :: {UsersPid :: pid(), Data :: any()}
61-
Timeout :: pos_integer() | infinity
62-
```
63-
64-
This function starts a coordinator. Usually is called in `init/0` of a amoc scenario.
65-
66-
#### `add(CoordinatorName, Data) -> ok`
67-
#### `add(CoordinatorName, Pid, Data) -> ok`
68-
69-
##### Types
70-
```erlang
71-
CoordinatorName :: atom()
72-
UsersPid :: pid()
73-
Data :: any()
74-
```
75-
76-
This function adds the current process data. It is usually called in `start/2` of a amoc scenario.
77-
7838
## Example
7939

8040
This scenario will demonstrate how do the `users` interact with `amoc_coordinator`:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ key set to ``2000``.
4242
Also all the user processes trap exit signal.
4343

4444

45-
### Don't stop scenario on exit
45+
## Don't stop scenario on exit
4646

4747
There is one problem with the `bin/amoc console` command. When you exit the Erlang
4848
shell the scenario is stopped (in fact the erlang nodes are killed).
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
## Set-up distributed environment with docker
2-
31
To build a Docker image with Amoc, run the following command from the root of
42
the repository:
53
```
@@ -49,3 +47,4 @@ docker run --rm -t -d --name amoc-2 -h amoc-2 \
4947
Connect to Amoc console and go to the [next](../doc/distributed-run.md) section.
5048
```
5149
docker exec -it amoc-1 /home/amoc/amoc/bin/amoc remote_console
50+
```
File renamed without changes.

doc/scenario.md renamed to guides/scenario.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ For developing XMPP scenarios, we recommend the
6060
If additional dependencies are required by your scenario,
6161
a `rebar.config` file can be created inside the `scenario` dir
6262
and `deps` from that file will be merged with Amoc's dependencies.
63+
64+
## Coordinate users
65+
See `amoc_coordinator`.
66+
67+
## Throttle actions
68+
See `amoc_throttle`.

doc/telemetry.md renamed to guides/telemetry.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
## Telemetry
2-
31
Amoc also exposes the following telemetry events:
42

5-
### Scenario
3+
## Scenario
64

75
A telemetry span of a full scenario execution
86
```erlang
@@ -11,7 +9,7 @@ measurements: #{}
119
metadata: #{}
1210
```
1311

14-
### Controller
12+
## Controller
1513

1614
Indicates the number of users added or removed
1715
```erlang
@@ -20,9 +18,9 @@ measurements: #{count => non_neg_integer()}
2018
metadata: #{type => add | remove}
2119
```
2220

23-
### Throttle
21+
## Throttle
2422

25-
#### Rate
23+
### Rate
2624

2725
Raised when a throttle mechanism is initialised or its configured rate is changed.
2826

@@ -32,7 +30,7 @@ measurements: #{rate => non_neg_integer()}
3230
metadata: #{name => atom()}
3331
```
3432

35-
#### Request
33+
### Request
3634

3735
Raised when a process client requests to be allowed pass through a throttled mechanism.
3836

@@ -42,7 +40,7 @@ measurements: #{count => 1}
4240
metadata: #{name => atom()}
4341
```
4442

45-
#### Execute
43+
### Execute
4644

4745
Raised when a process client is allowed to execute after a throttled mechanism.
4846

@@ -52,11 +50,11 @@ measurements: #{count => 1}
5250
metadata: #{name => atom()}
5351
```
5452

55-
### Coordinate
53+
## Coordinate
5654

5755
Indicates when a coordinating event was raised, like a callback index being reached or a timeout being triggered
5856

59-
#### Event
57+
### Event
6058
```erlang
6159
event_name: [amoc, coordinator, event]
6260
measurements: #{count => 1}

0 commit comments

Comments
 (0)