Doc: Continue with tutorial brainstorming session.
Co-authored-by: Hector Hurtado <hector.hurtado@bbva.com> Co-authored-by: pancho horrillo <pedrofelipe.horrillo@bbva.com>
This commit is contained in:
@@ -38,30 +38,93 @@ ACME's Infrastructure
|
|||||||
User Journey
|
User Journey
|
||||||
------------
|
------------
|
||||||
|
|
||||||
#. Actions over the database. Launch database backup script with an HTTP call.
|
#. Actions over the server. Launch database backup script with an HTTP call.
|
||||||
|
|
||||||
- User Learns: Add a route that executes a command locally.
|
- User Learns: Add a route that executes a command locally.
|
||||||
- Kapow! Concepts: `kapow route add`
|
- Kapow! Concepts: `kapow route add`
|
||||||
|
- Problem/Motivation: Each time an ACME project is finished it is
|
||||||
|
desirable to make a backup of the entire database. Given that the
|
||||||
|
database server is a critical machine we don't want to grant SSH
|
||||||
|
access to lowly developers. The script is very fast because the
|
||||||
|
database is small (for now).
|
||||||
|
- Solution: Instead of launching the script via SSH shell we can
|
||||||
|
provide an HTTP endpoint to perform the task.
|
||||||
|
```
|
||||||
|
ssh user@server
|
||||||
|
$ ./backup_db.sh
|
||||||
|
```
|
||||||
|
- Final Kapow!:
|
||||||
|
```
|
||||||
|
curl -X PUT http://server:8080/db/backup
|
||||||
|
```
|
||||||
|
```
|
||||||
|
kapow route add -X PUT /db/backup -e ./backup_db.sh
|
||||||
|
```
|
||||||
|
|
||||||
#. Basic database monitorization
|
#. Basic server monitoring
|
||||||
|
|
||||||
- User Learns: Execute local commands and output it results to the HTTP body.
|
- User Learns: Execute local commands and output it results to the HTTP body.
|
||||||
- Kapow! Concepts: `kapow set /response/body`
|
- Kapow! Concepts: `kapow set /response/body`
|
||||||
|
- Problem/Motivation:
|
||||||
|
- Solution:
|
||||||
|
- Final Kapow!:
|
||||||
|
```
|
||||||
|
cat /var/log/backup_db.log | kapow set /response/body
|
||||||
|
```
|
||||||
|
|
||||||
#. Advanced database monitorization
|
#. Filter over basic monitoring
|
||||||
- User Learns: Compose complex HTTP responses with more than one local command.
|
|
||||||
- Kapow! Concepts: HEREDOC and subshells
|
- User Learns: Get a parameter from the user and use it to select the
|
||||||
|
script.
|
||||||
|
- Kapow! Concepts: `kapow get /request/params`
|
||||||
|
- Problem/Motivation:
|
||||||
|
- Solution:
|
||||||
|
- Final Kapow!:
|
||||||
|
```
|
||||||
|
LINES="$(kapow get /request/params/lines)"
|
||||||
|
FILTER="$(kapow get /request/params/filter)"
|
||||||
|
grep "$FILTER" /var/log/backup_db.log \
|
||||||
|
| tail -n"$LINES" \
|
||||||
|
| kapow set /response/body
|
||||||
|
```
|
||||||
|
|
||||||
|
#. Advanced database monitoring
|
||||||
|
|
||||||
|
- User Learns: Compose complex HTTP responses with more than one local command.
|
||||||
|
- Kapow! Concepts: HEREDOC and subshells
|
||||||
|
- Problem/Motivation:
|
||||||
|
- Solution:
|
||||||
|
- Final Kapow!:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
echo Memory:
|
||||||
|
free -m
|
||||||
|
echo ================================================================================
|
||||||
|
echo Load:
|
||||||
|
uptime
|
||||||
|
echo ================================================================================
|
||||||
|
echo Disk:
|
||||||
|
df -h
|
||||||
|
} | kapow set /response/body
|
||||||
|
```
|
||||||
|
|
||||||
#. Share your achievements
|
#. Share your achievements
|
||||||
|
|
||||||
- User Learns: Format a complex HTTP response with JSON format to feed the corporate dashboard.
|
- User Learns: Format a complex HTTP response with JSON format to feed the corporate dashboard.
|
||||||
- Kapow! Concepts: backtick interpolation and `kapow set /response/headers`
|
- Kapow! Concepts: backtick interpolation and `kapow set /response/headers`
|
||||||
|
- Problem/Motivation:
|
||||||
#. Unifing the interface (???)
|
- Solution:
|
||||||
|
- Final Kapow!:
|
||||||
- User Learns: Add logic to the handler. React to a specific request.
|
``` DON'T HANDWRITE JSON
|
||||||
- Kapow! Concepts: `kapow get /request/headers` and IF (bash)
|
echo "{memory: `free -m`, ...uups..}' | kapow set /response/body
|
||||||
|
```
|
||||||
|
|
||||||
|
``` USE JQ
|
||||||
|
MEMORY=$(free -m)
|
||||||
|
LOAD=$(uptime)
|
||||||
|
DISK=$(df -h)
|
||||||
|
jq -nc --arg memory "$MEMORY" '{"memory": $memory}'
|
||||||
|
```
|
||||||
|
|
||||||
Ideas
|
Ideas
|
||||||
-----
|
-----
|
||||||
|
|||||||
Reference in New Issue
Block a user