## Čo s aplikáciou po nasadení?
[Miroslav Biňas](https://bletvaska.github.io)
/ [**UVP Technicom**](https://uvptechnicom.sk/event/co-s-aplikaciou-po-nasadeni/)
![This is Mirek](/images/mirek.na.hackathone.jpg)
![Hard Work](images/hard.work.gif)
notes:
* mozno takto nejako vyzeral pracovny zapal aj vo vasom time este pomerne nedavno (dnes rano?)
* po tyzdnoch tvrdej (timovej) prace ste to nakoniec dali
## Live demo!
notes:
* tadaaaa
## Gratulujem!
notes:
* ale nakoniec ste to dali, takze gratulujem
## Čo ďalej?
aplikácia beží, ale **len** na vašom počítači
## ...a ešte k tomu
* kde a ako hostovať?
* kde a ako ukladať údaje?
* ako to budem aktualizovať? (nbusr style?)
* koľko ma to bude stáť? (denne/ročne)
[![Docker](images/logo-docker.png)](https://www.docker.com/)
notes:
* trendom je dnes robit aplikacie v kontajneroch
* rovno od zaciatku uvazujte presne takto
![The most-loved Tool in Stack Overflow’s 2022 Developer Survey.](images/docker.stackoverflow.survey.png)
notes:
* docker je dnes jednym z najpopularnejsich nastrojov developerov. o tom hovori aj posledny prieskum StackOverflow survery 2022
## Čo je to kontajner?
> Kontajner je **izolované prostredie** na **spustenie procesu**.
notes:
* laicky - zip balik s aplikaciou a potrebnymi kniznicami pre spustenie aplikacie
* proces sa spusta pod linuxovym jadrom
## Prečo kontajnery?
* jednotné prostredie pre rozličné prostredia
* rovnaké prostredie pre vývoj aj nasadenie
* podpora naprieč IDE
* škálovanie...
![Getting on Bus](images/getting.on.bus.png)
![Scaling the Busses](images/horizontal.and.vertical.scaling.of.busses.png)
![](https://docs.docker.com/engine/swarm/images/services-diagram.png)
### Problém: Odkiaľ sú moji zákazníci?
(a kedy ku mne chodia?)
## Logovanie
> Logging - one of the secrets to building extremely stable, robust web applications.
## Kde logovať?
* do lokálneho súboru
* náročná analýza - viacero súborov, rozličné formáty
* do vzdialenej db
* aplikácia musí obsahovať konfiguráciu pre pripojenie
* špeciálne systémy ako [Logstash](https://www.elastic.co/logstash/), [Loki](https://grafana.com/oss/loki/), štandardné SQL databázy
### Aplikácia spustená v kontajneri loguje do štandardného výstupu!
### Logovanie v jazyku Python
```python
import logging
# basic config
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(name)-12s %(levelname)-8s: %(message)s'
)
# creating logger
logger = logging.getLogger('supa')
# logging
logger.info('Starting Application')
```
## Agregácia logov
App > [Docker](https://www.docker.com/) > [Fluentd](https://www.fluentd.org/) (plugin) > [[Logstash](https://www.elastic.co/logstash/) | [Loki](https://grafana.com/oss/loki/)]
## Deadlock
```python
while True:
pass
```
## Jednoduchá kontrola
```python
@app.get('/api/healthz')
def check_health():
return {
'status': 'up'
}
```
## Healthcheck a Docker
```dockerfile
HEALTHCHECK \
--interval=5m \
--timeout=3s \
--retries=3 \
--start-period=5s \
CMD curl -f http://localhost/ || exit 1
```
## Metriky
> Metriky poskytujú **pohľad** na **aktuálny stav** vašej aplikácie. Prípadne vieme pomocou metrík zistiť **stav v čase**.
![](images/four.golden.signals.png)
> **Latency** is the **time** it takes to service a request.
### Meranie latencie s middleware
```python
import time
from fastapi import FastAPI, Request
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
response.headers["X-Process-Time"] = str(process_time)
return response
```
> **Traffic** is a measure of **how much** demand is being placed on your system, measured in a high-level system-specific metric.
![](https://static.wixstatic.com/media/cf93e2_c52dcfd44ea84f01b64cef91b4e54b98~mv2.png/v1/fill/w_640,h_480,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/cf93e2_c52dcfd44ea84f01b64cef91b4e54b98~mv2.png)
> **Errors** is the **rate of requests that fail**, either explicitly (e.g., HTTP 500s), implicitly (for example, an HTTP 200 success response, but coupled with the wrong content), or by policy (for example, "If you committed to one-second response times, any request over one second is an error").
> **Saturation** describes, **how "full" your service is**.
![](https://www.vectorlogo.zone/logos/grafana/grafana-ar21.png)
## Links
* [The four Golden Signals of Kubernetes monitoring](https://sysdig.com/blog/golden-signals-kubernetes/)
* [Microservice Architecture](https://microservices.io/index.html)
![qr code](https://api.qrserver.com/v1/create-qr-code/?data=https://bit.ly/3tAcH9a&size=300x300)
(**https://bit.ly/3tAcH9a**)