Skip to content

Commit

Permalink
Merge pull request #145 from esl/amoc_core
Browse files Browse the repository at this point in the history
Amoc core
  • Loading branch information
chrzaszcz authored Jun 20, 2023
2 parents d3e1016 + 107c0c0 commit 66eb4d4
Show file tree
Hide file tree
Showing 54 changed files with 261 additions and 1,739 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ jobs:
run: make integration_test
env:
OTP_RELEASE: ${{ matrix.otp_vsn }}
REBAR_RELEASE: ${{ matrix.rebar_vsn }}
51 changes: 14 additions & 37 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
FROM phusion/baseimage:focal-1.0.0 as base-image
FROM base-image as amoc-build
ARG otp_vsn=25.3
FROM erlang:${otp_vsn}-slim AS builder
MAINTAINER Erlang Solutions <[email protected]>

RUN apt-get update
RUN apt-get -y install gnupg2
WORKDIR /amoc_build

ARG DEBIAN_FRONTEND=noninteractive
ARG otp_vsn=24.0
ARG rebar_vsn=3.16.1
COPY ./rebar.config ./rebar.lock ./
RUN rebar3 deps && rebar3 compile -d

ADD https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb /tmp/
RUN dpkg -i /tmp/erlang-solutions_2.0_all.deb
RUN apt-get update
COPY ./integration_test integration_test
COPY ./scenarios scenarios
COPY ./priv priv
COPY ./rel rel
COPY ./src src

RUN apt-get -y install esl-erlang=1:${otp_vsn}-1
RUN rebar3 as demo release

RUN apt-get -y install git make wget
ENV PATH "/amoc_build/_build/demo/rel/amoc/bin:${PATH}"

COPY . /amoc_build

ADD https://github.com/erlang/rebar3/releases/download/${rebar_vsn}/rebar3 /bin
RUN chmod u+x /bin/rebar3

RUN cd /amoc_build && \
git clean -ffxd && \
make rel

FROM base-image

RUN useradd -ms /bin/bash amoc

COPY --from=amoc-build /amoc_build/_build/demo/rel/amoc/ /home/amoc/amoc/
COPY --from=amoc-build /amoc_build/scenarios /amoc_build/scenarios

# It seems hub.docker.com does not support --chown param to COPY directive
RUN chown -R amoc:amoc /home/amoc/amoc

EXPOSE 4000

RUN mkdir /etc/service/amoc
COPY docker/amoc.sh /etc/service/amoc/run

CMD ["/sbin/my_init"]
CMD ["amoc", "foreground"]
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: default rel compile clean ct test integration_test dialyzer xref console lint
.PHONY: default rel compile clean ct test integration_test dialyzer xref console

REBAR = rebar3

Expand All @@ -25,7 +25,7 @@ ct:
## eunit and ct commands always add a test profile to the run
$(REBAR) ct --verbose $(SUITE_OPTS)

test: compile xref lint dialyzer ct
test: compile xref dialyzer ct

integration_test:
./integration_test/stop_demo_cluster.sh
Expand Down Expand Up @@ -54,6 +54,3 @@ console:
@echo "tests can be executed manually using ct:run/1 function:\n" \
' ct:run("test").'
$(REBAR) as test shell

lint:
$(REBAR) as elvis lint
21 changes: 0 additions & 21 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@ Amoc supports the following generic configuration parameters:
* default value - empty list (`[]`)
* example: `AMOC_EXTRA_CODE_PATHS='["/some/path", "/another/path"]'`

In addition to that, `amoc_metrics` allow to configure a Graphite reporter
using the following environment variables:

* ``graphite_host`` - a graphite host address (string or `undefined`):
* default value - `undefined` (amoc_metrics do not try to initialise a metrics reporter)
* example: `AMOC_GRAPHITE_HOST='"graphite"'`

* ``graphite_port`` - graphite port:
* default value - `2003`
* example: `AMOC_GRAPHITE_PORT='2003'`

* ``graphite_prefix`` - graphite prefix:
* default value - `net_adm:localhost()`
* example: `AMOC_GRAPHITE_PREFIX='"amoc"'`

In order to initialise some preconfigured metrics, other applications can declare
the `predefined_metrics` environment variable (in their own `*.app.src` file):
```
{predefined_metrics, [{gauge, some_metric}, {times, another_metric}]}
```

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

The ``amoc_config:get/1`` and ``amoc_config:get/2`` interfaces can be used to get
Expand Down
19 changes: 0 additions & 19 deletions doc/http-api.md

This file was deleted.

64 changes: 64 additions & 0 deletions doc/telemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## Telemetry

Amoc also exposes the following telemetry events:

### Scenario

A telemetry span of a full scenario execution
```erlang
event_name: [amoc, scenario, user]
measurements: #{}
metadata: #{}
```

### Controller

Indicates the number of users added or removed
```erlang
event_name: [amoc, controller, users]
measurements: #{count => non_neg_integer()}
metadata: #{type => add | remove}
```

### Throttle

#### Rate

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

```erlang
event_name: [amoc, throttle, rate]
measurements: #{rate => non_neg_integer()}
metadata: #{name => atom()}
```

#### Request

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

```erlang
event_name: [amoc, throttle, request]
measurements: #{count => 1}
metadata: #{name => atom()}
```

#### Execute

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

```erlang
event_name: [amoc, throttle, execute]
measurements: #{count => 1}
metadata: #{name => atom()}
```

### Coordinate

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

#### Event
```erlang
event_name: [amoc, coordinator, event]
measurements: #{count => 1}
metadata: #{type => atom()}
```
3 changes: 0 additions & 3 deletions docker/amoc.sh

This file was deleted.

26 changes: 0 additions & 26 deletions elvis.config

This file was deleted.

11 changes: 2 additions & 9 deletions integration_test/build_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ source "$(dirname "$0")/helper.sh"
enable_strict_mode
cd "$git_root"

otp_vsn="${OTP_RELEASE:-24.0}"
rebar_vsn="${REBAR_RELEASE:-3.16.1}"
otp_vsn="${OTP_RELEASE:-25.3}"
echo "ERLANG/OTP '${otp_vsn}'"
echo "REBAR '${rebar_vsn}'"

docker build \
-f Dockerfile \
-t amoc:latest \
--build-arg "otp_vsn=${otp_vsn}" \
--build-arg "rebar_vsn=${rebar_vsn}" \
.
docker_compose build --build-arg otp_vsn=${otp_vsn}
33 changes: 6 additions & 27 deletions integration_test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,31 @@
version: "3.4"

x-amoc-defaults: &amoc-defaults
image: "amoc:latest"
build:
context: ../
dockerfile: Dockerfile
networks:
- amoc-test-network
volumes:
- type: bind
source: ./extra_code_paths
target: /extra_code_paths
environment:
AMOC_GRAPHITE_HOST: '"graphite"'
AMOC_NODES: "['amoc@amoc-master']"
AMOC_EXTRA_CODE_PATHS: '["/extra_code_paths/test1", "/extra_code_paths/test2"]'
healthcheck:
test: "/home/amoc/amoc/bin/amoc status"
test: "amoc status"

services:
amoc-master:
<<: *amoc-defaults
hostname: "amoc-master"
ports:
- "4000:4000"
amoc-worker-1: &amoc-worker
<<: *amoc-defaults
hostname: "amoc-worker-1"
ports:
- "4001:4000"
amoc-worker-2:
amoc-worker-2:
<<: *amoc-defaults
hostname: "amoc-worker-2"
ports:
- "4002:4000"
amoc-worker-3:
amoc-worker-3:
<<: *amoc-defaults
hostname: "amoc-worker-3"
ports:
- "4003:4000"
graphite:
image: "graphiteapp/graphite-statsd:1.1.7-2"
ports:
- "8080:80"
networks:
- amoc-test-network
grafana:
image: "grafana/grafana:6.7.3"
ports:
- "3000:3000"
networks:
- amoc-test-network
networks:
amoc-test-network:
2 changes: 1 addition & 1 deletion integration_test/dummy_scenario.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ init() ->
-spec start(amoc_scenario:user_id()) -> any().
start(_Id) ->
%%sleep 15 minutes
timer:sleep(1000 * 60 * 15),
timer:sleep(timer:minutes(15)),
amoc_user:stop().
16 changes: 2 additions & 14 deletions integration_test/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,13 @@ function wait_for_cmd() {
######################
## docker functions ##
######################
function amoc_container_port() {
local service="$1"
case "$service" in
amoc-master)
echo 4000 ;;
amoc-worker-[0-9])
echo "400${service#amoc-worker-}" ;;
*)
return 1 ;;
esac
}

docker_compose() {
local compose_file="${git_root}/integration_test/docker-compose.yml"
docker-compose -p "amoc-demo-cluster" -f "$compose_file" "$@"
docker compose -p "amoc-demo-cluster" -f "$compose_file" "$@"
}

function amoc_eval() {
local exec_path="/home/amoc/amoc/bin/amoc"
local exec_path="amoc"
local service="$1"
shift 1
docker_compose exec -T "$service" "$exec_path" eval "$@"
Expand Down
15 changes: 1 addition & 14 deletions integration_test/start_demo_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,8 @@ enable_strict_mode
create_code_path test1
create_code_path test2

docker_compose up -d amoc-{master,worker-1,worker-2} graphite grafana
docker_compose up -d amoc-{master,worker-1,worker-2}

wait_for_healthcheck amoc-master
wait_for_healthcheck amoc-worker-1
wait_for_healthcheck amoc-worker-2

json=( '{'
'"name": "graphite",'
'"access": "proxy",'
'"type": "graphite",'
'"url": "http://graphite",'
'"isDefault": true'
'}' )

## configure default grafana datasource
curl 'http://admin:admin@localhost:3000/api/datasources' -X POST \
-H 'Content-Type: application/json;charset=UTF-8' \
-d "${json[*]}" -w "\n%{response_code}\n"
1 change: 1 addition & 0 deletions integration_test/test_add_new_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ wait_for_healthcheck amoc-worker-3
amoc_eval amoc-worker-3 "amoc_controller:get_status()." | contain dummy_scenario running
amoc_eval amoc-worker-3 "binary_to_list(amoc_config:get(test))." | contain "test_value"
amoc_eval amoc-worker-3 "dummy_helper:test_amoc_dist()." | contain 'amoc_dist_works_as_expected'
echo "amoc_dist_works_as_expected"
2 changes: 0 additions & 2 deletions integration_test/test_amoc_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ amoc_eval amoc-worker-2 "nodes()." | contain amoc-master amoc-worker-1
echo "checking that AMOC_EXTRA_CODE_PATHS setting works as expected"
amoc_eval amoc-master "amoc_scenario:does_scenario_exist(test1)." | contain true
amoc_eval amoc-master "amoc_scenario:does_scenario_exist(test2)." | contain true

wait_for_metrics "amoc-"{"master","worker-1","worker-2"}".amoc.users.size"
Loading

0 comments on commit 66eb4d4

Please sign in to comment.