-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feat(alerts): add alert on mattermost in case of cron failure #280
Feat(alerts): add alert on mattermost in case of cron failure #280
Conversation
accd390
to
9e6d584
Compare
9e6d584
to
1e46fc1
Compare
1e46fc1
to
ea07e5a
Compare
ea07e5a
to
db7271e
Compare
a9d3559
to
467a3f7
Compare
87f9466
to
67ec49e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quelques petits commentaires ! Et perso je ne l'appellerais pas run_management_command.sh
; c'etait pour les emplois spécifiquement parce que eux ils wrappent django-admin
qui lance des... "management commands" Django.
Nous on a plutot un ... execute_and_notify.sh
?
api/run_management_command.sh
Outdated
#!/bin/sh | ||
set -u | ||
|
||
# Execute the command and capture standard output and error output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attention aux commentaires misleadings ou inutiles.
$@ & : on sait que ça va executer la commande en detached
... par contre je ne vois pas comment cela capturerait les sorties ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commentaires obsoletes
api/run_management_command.sh
Outdated
@@ -0,0 +1,21 @@ | |||
#!/bin/sh | |||
set -u |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pour quoi faire ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c'est sense rendre le script plus robuste. Ca genere une erreur en cas d'utilisation de variables non definit. Pas indispensable, mais pas incompatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi pas, mais bon a priori a part les variables d'environnement (pas sûr qu'elles soient prises par -u
? A vérifier !) on les définit toutes en interne les variables bash donc ça va.
Ca aurait pu être intéressant si par exemple on était capables de crasher si $MATTERMOST_WEBHOOK_URL est non défini mais bon, dans ce cas on aura pas de notification non plus ^^ Scalingo va juste rester silencieux comme d'hab ! Donc so far, je vois pas trop à quoi ça servira dans le fond.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Les var d'env sont prise par le -u :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je fais souvent des choses par mimetisme (peut etre une habitude perdre). Les script sh commence souvent par ca. On peut le virer pour etre un peu plus yagni. J'ai pas d'avis fort la dessus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ca ne changera rien au schmilblick final mais bon, gardons le ça ne pose pas de souci !
api/run_management_command.sh
Outdated
|
||
wait $command_pid | ||
|
||
exit_code=$? # Capture the exit code of the previous command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
je pense que là aussi, vu le nom de la variable, on peut se passer du commentaire ^
api/run_management_command.sh
Outdated
|
||
exit_code=$? # Capture the exit code of the previous command | ||
|
||
# Check if the exit code indicates an error (not equal to 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api/run_management_command.sh
Outdated
# Execute the curl command in case of an error | ||
escaped_command="in command '$@'" | ||
echo "Error with exit code $exit_code $escaped_command, sending message to Mattermost" | ||
curl -i -X POST -H "Content-Type: application/json" -d "{\"text\": \"Error with exit code $exit_code $escaped_command: \nLogs: scalingo --region osc-secnum-fr1 --app data-inclusion-api-prod logs --lines 1000 -F $CONTAINER -f\"}" $MATTERMOST_HOOK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice :)
Je raffinerais encore un poil plus:
Error $exit_code with command : `$escaped_command`
(note les `` qui seront formatés par Mattermost)
Ensuite pour la commande de logs, je me demande pourquoi le -f
ou les 1000 lignes ? Et pareil, je le mettrais bien dans des backticks pour que ça soit chouli dans Mattermost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-f pour la navigation
1000 ligne c'est pour eviter d'en avoir trop
Ok pour les ``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes mais:
- le
-f
te donne juste la "suite" de la commande or elle est déjà crashée a priori, donc pas de nouvelles lignes n'arriveront ? - 1000 lignes : ok, pourquoi pas !
api/run_management_command.sh
Outdated
# Check if the exit code indicates an error (not equal to 0) | ||
if [ $exit_code -ne 0 ] && [ "$ENV" = "prod" ]; then | ||
# Execute the curl command in case of an error | ||
escaped_command="in command '$@'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est pour éviter d'envoyer des trucs bizarres dans Mattermost c'est ça ? Il s'est passé des choses bizarres ? En tout cas je recommande le backtick plus que les guillemets, cf. plus bas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai galerer avec le format, j'avais des erreur chelou de caracter non escaped, je vais essayer de les remettre
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, intéressant, je veux bien voir dans quels cas du coup le format rend mattermost pas content, c'est une bonne info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si tu as des soucis de caractères non échappés, potentiellement je te recommande d'utilise $*
au lieu de $@
.
"$@"
(donc mis dans une chaine de caractères) devient une liste d'arguments séparés. "$*"
devient un seul paramètre, qui sont tous les arguments du script ($1, $2, ...) concaténés en un seul.
31059b9
to
f7cbe37
Compare
api/Dockerfile
Outdated
RUN chmod +x docker-entrypoint.sh | ||
RUN chmod +x run_management_command.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops
api/cron.json
Outdated
@@ -1,15 +1,15 @@ | |||
{ | |||
"jobs": [ | |||
{ | |||
"command": "30 * * * * TQDM_DISABLE=1 test $ENV = 'prod' && data-inclusion-api load_inclusion_data", | |||
"command": "30 * * * * TQDM_DISABLE=1 test $ENV = 'prod' && sh run_management_command.sh data-inclusion-api load_inclusion_data", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops
api/execute_and_notify.sh
Outdated
|
||
exit_code=$? | ||
if [ $exit_code -ne 0 ] && [ "$ENV" = "prod" ]; then | ||
# Execute the curl command in case of an error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tjs inutile je pense :) surtout avec le print qui vient expliquer exactement ça juste en dessous
api/cron.json
Outdated
"size": "XL" | ||
}, | ||
{ | ||
"command": "30 * * * * TQDM_DISABLE=1 test $ENV != 'prod' && data-inclusion-api load_inclusion_data", | ||
"command": "30 * * * * TQDM_DISABLE=1 test $ENV != 'prod' && sh run_management_command.sh data-inclusion-api load_inclusion_data", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pas nécessaire de le mettre en staging du coup ? puisque à l'intérieur du script on hardcode "prod" deux fois ^^
111ac63
to
d5ae3bc
Compare
d5ae3bc
to
bbef4b3
Compare
bbef4b3
to
9ef3a7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LVGTM !
(tu peux virer le sh xxxx.sh
puisque a priori, tu as:
- un shbang
- les droits d'execution appliqués via chmod dans le Dockerfile
Vérifie quand meme que le fichier est executable dans le repository pour que Scalingo puisse le lancer sans pb
0ca81da
to
c40c683
Compare
…in case of failure
c40c683
to
1748f10
Compare
No description provided.