Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hackaton orange fix ansible #2

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1d6f1eb
feat: add a requirement.yml file
bamthomas May 24, 2024
628d858
fix: remove external deps message to install docker-py
bamthomas May 24, 2024
c0854ec
fix: remove use_case var for cleaning previous results
bamthomas May 24, 2024
1fc90e1
feat: add group_vars for global variables
bamthomas May 24, 2024
76b12be
feat: add scenario in runner execution - intermediate commit
youenchene May 24, 2024
57aed26
feat: add init scenario in runner docker image
youenchene May 24, 2024
e1e9063
feat: list and run automatically all services with selected scenarii
youenchene May 24, 2024
7ae0a34
tmp: exlude mysql for the moment
youenchene May 24, 2024
07371cc
feat: filter by mysql + eval
youenchene May 24, 2024
b3ce803
Revert "fix: remove use_case var for cleaning previous results"
bamthomas May 24, 2024
71888c1
refactor: remove use_case var from database docker build script
bamthomas May 24, 2024
72ac81a
infra: docker build update for repo boavizta
youenchene May 24, 2024
f34e4c2
fix: ghrc boavizta docker packages
youenchene May 24, 2024
84ec2ff
infra: builder for all services
youenchene May 24, 2024
1ae61a1
fix: database host from magic var hostvars
bamthomas May 24, 2024
8ff9f98
refactor: rename docker image url
bamthomas May 24, 2024
563e582
refactor: rename use_case -> scenario
bamthomas May 24, 2024
46d3b4b
fix: builder scripts
bamthomas May 24, 2024
7752214
fix: dockerfile for the runner
bamthomas May 24, 2024
4d22101
fix: docker images and json results paths
bamthomas May 24, 2024
302b11c
feat: add init runner
youenchene May 24, 2024
30f129e
fix: syntax in ansible file
youenchene Jul 24, 2024
c56c1f1
chore: divide into 3 ansible set of roles.
youenchene Oct 21, 2024
1e64148
fix: right way to launch the benchmark
youenchene Oct 21, 2024
844fa97
chore: add xk6-file
youenchene Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions builder/database.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@

#!/bin/bash

if test "$#" -ne 1; then
if test "$#" -ne 0; then
echo "Invalid number of arguments..."
echo
echo "Usage: ./builder/database.sh <use_case>"
echo
echo "Available tags:"
echo "default (the use case to compare to)"
echo "Usage: ./builder/database.sh"
echo
exit 1
fi

export ORG=${ORG:-jdrouet}
export use_case=$1
export ORG=${ORG:-boavizta}

echo "Building database for use case $use_case"
echo "Building database"

docker buildx build --push --tag "$ORG/eco-benchmark:database-$use_case" ./migrations
docker buildx build --push --tag "ghcr.io/$ORG/ecobenchmark-4-builder-efootprint:database" ./migrations

exit 0

16 changes: 5 additions & 11 deletions builder/runner.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@

#!/bin/bash

if test "$#" -ne 1; then
if test "$#" -ne 0; then
echo "Invalid number of arguments..."
echo
echo "Usage: ./builder/runner.sh <use_case>"
echo
echo "Available tags:"
echo "default (the use case to compare to)"
echo "Usage: ./builder/runner.sh"
echo
exit 1
fi

export ORG=${ORG:-jdrouet}
export use_case=$1

echo "Building runner for use case $use_case"
export ORG=${ORG:-boavizta}

docker buildx build --push --tag "$ORG/eco-benchmark:runner-$use_case" ./runner

exit 0
docker buildx build --push --tag "ghcr.io/$ORG/ecobenchmark-4-builder-efootprint:runner" ./runner

exit 0
24 changes: 12 additions & 12 deletions builder/service.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#!/bin/bash

if test "$#" -ne 2; then
if test "$#" -ne 0; then
echo "Invalid number of arguments..."
echo
echo "Usage: ./builder/service.sh <service> <use_case>"
echo "Usage: ./builder/service.sh "
echo
echo "Available services:"
ls service
echo
echo "Available tags:"
echo "default (the use case to compare to)"
echo
exit 1
fi

export ORG=${ORG:-jdrouet}
export service=$1
export use_case=$2
export ORG=${ORG:-boavizta}


echo "Building service $service for use case $use_case"
folder_path=./service

docker buildx build --push --tag "$ORG/eco-benchmark:service-$service-$use_case" ./service/$service
folder_names=$(find $folder_path -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
for service in $folder_names; do
if [[ $folder_name != *mysql ]]; then #temp patch
echo "Building service $service"
docker buildx build --push --tag "ghcr.io/$ORG/ecobenchmark-4-builder-efootprint:service-$service" ./service/$service
fi
done

exit 0

9 changes: 8 additions & 1 deletion runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
FROM grafana/xk6

RUN xk6 build v0.54.0 --with github.com/avitalique/xk6-file@latest

FROM grafana/k6

COPY --from=0 /xk6/k6 /usr/bin/k6

COPY scenario-INIT.js /config/scenario-INIT.js
COPY scenario-DATA_WRITE.js /config/scenario-DATA_WRITE.js
COPY scenario-DATA_LIST.js /config/scenario-DATA_LIST.js
COPY scenario-DATA_SIMPLE_ANALYTICS.js /config/scenario-DATA_SIMPLE_ANALYTICS.js
COPY scenario-DATA_SIMPLE_ANALYTIC.js /config/scenario-DATA_SIMPLE_ANALYTIC.js

9 changes: 7 additions & 2 deletions runner/scenario-INIT.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import http from 'k6/http';
import { check, sleep } from 'k6';
import file from 'k6/x/file';

let loginIndex = 0;
let serverHost = __ENV.SERVER_HOST || 'localhost:8080';


const filepath = '/tmp/account_id';

function success_response(r) {
return r.status >= 200 && r.status < 300;
}
Expand All @@ -24,7 +27,9 @@ function json_post(name, path, data) {
export default function() {
const data = { login: `user_${loginIndex++}` };
// login
let account = json_post('login', '/api/accounts', data);

console.log(`AccountID: ${account.id}`);
file.writeString(filepath, `PLOP`);
let account = json_post('login', '/api/accounts', data);
file.writeString(filepath, `PLOP2`);
file.writeString(filepath, `${account}`);
}
58 changes: 0 additions & 58 deletions runner/scenario.js

This file was deleted.

10 changes: 10 additions & 0 deletions script/group_vars/all
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
database_host: "{{ hostvars[groups['server_database_host'][0]]}}"
database_username: postgres
database_password: password
database_name: postgres
database_url: "jdbc:postgresql://{{ database_host }}:5432/{{ database_name }}"


virtual_users: 20
duration: 600
run_id: overrideme
6 changes: 3 additions & 3 deletions script/hosts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[application]
app_server ansible_host="{{ server_application_host }}" ansible_user="{{ server_application_user }}"
app_server ansible_host="{{ server_application_host }}"

[database]
db_server ansible_host="{{ server_database_host }}" ansible_user="{{ server_database_user }}"
db_server ansible_host="{{ server_database_host }}"

[runner]
run_server ansible_host="{{ server_runner_host }}" ansible_user="{{ server_runner_user }}"
run_server ansible_host="{{ server_runner_host }}"

[all:vars]
ansible_python_interpreter=/usr/bin/python3
Expand Down
3 changes: 3 additions & 0 deletions script/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ ansible-playbook -u THE_USER_TO_CONNECT_YOUR_SERVERS -i hosts-default site.yml -

To switch use cases, just use a different inventory (in this case `hosts-default`).

```bash
SERVER_APPLICATION_HOST=146.59.196.189 SERVER_DATABASE_HOST=5.135.139.189 SERVER_RUNNER_HOST=51.68.34.240 ./run-all.sh
```
1 change: 1 addition & 0 deletions script/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- name: nickjj.docker
2 changes: 1 addition & 1 deletion script/roles/cleanup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
command:
- "/bin/rm"
- "-f"
- "/tmp/{{ service }}_{{ use_case }}_{{ run_id }}*"
- "/tmp/{{ service }}_{{ scenario }}_{{ run_id }}*"
tags:
- cleanup

8 changes: 4 additions & 4 deletions script/roles/deploy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: deploy database
community.docker.docker_container:
name: eco-benchmark-database
image: "jdrouet/eco-benchmark:database-{{ use_case }}"
image: "ghcr.io/boavizta/ecobenchmark-4-builder-efootprint:database"
state: started
network_mode: host
restart_policy: unless-stopped
Expand All @@ -19,7 +19,7 @@
- name: deploy application
community.docker.docker_container:
name: eco-benchmark-application
image: "jdrouet/eco-benchmark:service-{{ service }}-{{ use_case }}"
image: "ghcr.io/boavizta/ecobenchmark-4-builder-efootprint:service-{{ service }}"
state: started
network_mode: host
restart_policy: unless-stopped
Expand Down Expand Up @@ -53,7 +53,7 @@
- "file"
- "--format"
- "json"
- "/tmp/{{ service }}_{{ use_case }}_{{ run_id }}_docker-activity-{{ instance_type }}.json"
- "/tmp/{{ service }}_{{ scenario }}_{{ run_id }}_docker-activity-{{ instance_type }}.json"
tags:
- deploy
when: instance_type == "application" or instance_type == "database"
Expand All @@ -76,7 +76,7 @@
- "-n"
- "100000000"
- "-f"
- "/tmp/{{ service }}_{{ use_case }}_{{ run_id }}_scaphandre-{{ instance_type }}.json"
- "/tmp/{{ service }}_{{ scenario }}_{{ run_id }}_scaphandre-{{ instance_type }}.json"
tags:
- deploy
when: instance_type == "application" or instance_type == "database"
Expand Down
25 changes: 25 additions & 0 deletions script/roles/execute-init/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: start runner
community.docker.docker_container:
name: eco-benchmark-runner
image: "ghcr.io/boavizta/ecobenchmark-4-builder-efootprint:runner"
detach: no
user: "1000:1000"
volumes:
- "{{ ansible_env.HOME }}:/tmp"
command:
- "run"
- "/config/scenario-{{ scenario }}.js"
- "-e"
- "SERVER_HOST={{ server_application_host }}:8080"
- debug: msg="{{ansible_env.HOME}}"
# output_logs: true
# log_driver: local
# register: output
#- debug: msg="{{output.container.Output}}"
# set_fact:
# account_id: "{{ command_output.stdout }}"
#- shell: "echo $account_id"
# environment:
# ACCOUNT_ID: "{{ account_id }}"

8 changes: 4 additions & 4 deletions script/roles/execute/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
- name: start runner
community.docker.docker_container:
name: eco-benchmark-runner
image: "jdrouet/eco-benchmark:runner-{{ use_case }}"
image: "ghcr.io/boavizta/ecobenchmark-4-builder-efootprint:runner"
detach: no
user: "1000:1000"
volumes:
- "{{ ansible_env.HOME }}:/tmp"
command:
- "run"
- "/config/scenario.js"
- "/config/scenario-{{ scenario }}.js"
- "--vus"
- "{{ virtual_users | to_json }}"
- "--duration"
- "{{ duration }}s"
- "-e"
- "SERVER_HOST={{ server_application_host }}:8080"
- "--summary-export"
- "/tmp/{{ service }}_{{ use_case }}_{{ run_id }}_k6-summary.json"
- "/tmp/{{ service }}_{{ scenario }}_{{ run_id }}_k6-summary.json"
# - "--out"
# - "json=/tmp/{{ service }}-{{ use_case }}-{{ run_id }}-k6.json"
# - "json=/tmp/{{ service }}-{{ scenario }}-{{ run_id }}-k6.json"
12 changes: 6 additions & 6 deletions script/roles/gathering/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

- name: gather docker activity results
fetch:
src: "{{ ansible_env.HOME }}/{{ service }}_{{ use_case }}_{{ run_id }}_docker-activity-{{ instance_type }}.json"
dest: "{{ output_directory }}/{{ service }}_{{ use_case }}_{{ run_id }}_docker-activity-{{ instance_type }}.json"
src: "/tmp/{{ service }}_{{ scenario }}_{{ run_id }}_docker-activity-{{ instance_type }}.json"
dest: "{{ output_directory }}/{{ service }}_{{ scenario }}_{{ run_id }}_docker-activity-{{ instance_type }}.json"
flat: yes
# validate_checksum: no
tags:
Expand All @@ -33,8 +33,8 @@

- name: gather scaphandre results
fetch:
src: "{{ ansible_env.HOME }}/{{ service }}_{{ use_case }}_{{ run_id }}_scaphandre-{{ instance_type }}.json"
dest: "{{ output_directory }}/{{ service }}_{{ use_case }}_{{ run_id }}_scaphandre-{{ instance_type }}.json"
src: "/tmp/{{ service }}_{{ scenario }}_{{ run_id }}_scaphandre-{{ instance_type }}.json"
dest: "{{ output_directory }}/{{ service }}_{{ scenario }}_{{ run_id }}_scaphandre-{{ instance_type }}.json"
flat: yes
# validate_checksum: no
tags:
Expand All @@ -43,8 +43,8 @@

- name: gather k6 results
fetch:
src: "{{ ansible_env.HOME }}/{{ service }}_{{ use_case }}_{{ run_id }}_k6-summary.json"
dest: "{{ output_directory }}/{{ service }}_{{ use_case }}_{{ run_id }}_k6-summary.json"
src: "/tmp/{{ service }}_{{ scenario }}_{{ run_id }}_k6-summary.json"
dest: "{{ output_directory }}/{{ service }}_{{ scenario }}_{{ run_id }}_k6-summary.json"
flat: yes
# validate_checksum: no
tags:
Expand Down
9 changes: 9 additions & 0 deletions script/roles/install/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
- install
- python

# see https://stackoverflow.com/questions/75608323/how-do-i-solve-error-externally-managed-environment-every-time-i-use-pip-3
- name: Remove externaly-managed error for docker-py
ansible.builtin.file:
path: /usr/lib/python3.11/EXTERNALLY-MANAGED
state: absent
tags:
- install
- docker

- name: install docker-py
pip:
name: docker
Expand Down
Loading