Лаб6 - оценка 4
This commit is contained in:
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
echo " Сценарий: получение ApiHighErrorRate firing "
|
||||
|
||||
docker compose stop postgres
|
||||
sleep 3
|
||||
|
||||
python3 student-tests/trigger_error_rate.py &
|
||||
BG_PID=$!
|
||||
|
||||
echo "Ждём 150 секунд для срабатывания alert..."
|
||||
sleep 150
|
||||
|
||||
echo ""
|
||||
echo " Состояние alerts в момент отказа (PostgreSQL STOPPED) "
|
||||
curl -s http://localhost:9090/api/v1/alerts > evidence/alerts_firing.json
|
||||
python3 -c "
|
||||
import json
|
||||
with open('evidence/alerts_firing.json') as f:
|
||||
data = json.load(f)
|
||||
firing_found = False
|
||||
for group in data.get('data',{}).get('groups',[]):
|
||||
for rule in group.get('rules',[]):
|
||||
if rule.get('alerts'):
|
||||
for alert in rule['alerts']:
|
||||
state = alert['state']
|
||||
name = alert['labels']['alertname']
|
||||
print(f\"{name}: {state}\")
|
||||
if state == 'firing':
|
||||
firing_found = True
|
||||
print(f\" ✓ FIRING: {alert.get('annotations',{}).get('summary','')}\")
|
||||
if firing_found:
|
||||
print('\\n✓ ALERT FIRING CONFIRMED')
|
||||
else:
|
||||
print('\\n✗ No alerts firing')
|
||||
"
|
||||
|
||||
echo ""
|
||||
echo " Метрика error rate "
|
||||
curl -s 'http://localhost:9090/api/v1/query' \
|
||||
--data-urlencode 'query=sum(rate(http_server_request_duration_seconds_count{service_name="messenger-api",http_response_status_code=~"5.."}[5m])) / clamp_min(sum(rate(http_server_request_duration_seconds_count{service_name="messenger-api"}[5m])), 0.001)' \
|
||||
| python3 -c "import sys,json; d=json.load(sys.stdin); [print(f'{float(r[\"value\"][1])*100:.2f}%') for r in d['data']['result']]" \
|
||||
| tee evidence/error_rate_at_firing.txt
|
||||
|
||||
echo ""
|
||||
echo " Восстановление PostgreSQL "
|
||||
docker compose start postgres
|
||||
|
||||
wait $BG_PID 2>/dev/null || true
|
||||
|
||||
echo "Ждём 20 секунд на восстановление..."
|
||||
sleep 20
|
||||
|
||||
echo ""
|
||||
echo " Состояние alerts после восстановления "
|
||||
curl -s http://localhost:9090/api/v1/alerts > evidence/alerts_resolved.json
|
||||
python3 -c "
|
||||
import json
|
||||
with open('evidence/alerts_resolved.json') as f:
|
||||
data = json.load(f)
|
||||
for group in data.get('data',{}).get('groups',[]):
|
||||
for rule in group.get('rules',[]):
|
||||
if rule.get('alerts'):
|
||||
for alert in rule['alerts']:
|
||||
print(f\"{alert['labels']['alertname']}: {alert['state']}\")
|
||||
"
|
||||
|
||||
echo ""
|
||||
echo " Финальная проверка smoke "
|
||||
make test
|
||||
Reference in New Issue
Block a user