add test script
This commit is contained in:
95
generate-traffic.sh
Executable file
95
generate-traffic.sh
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env bash
|
||||
# generate-traffic.sh — Sends a mix of orders to the Quarkus demo app
|
||||
# to produce metrics, traces, and logs for the troubleshooting session.
|
||||
#
|
||||
# Usage: bash scripts/generate-traffic.sh [BASE_URL] [ITERATIONS]
|
||||
#
|
||||
# Prerequisites: curl, jq (optional for pretty output)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
BASE_URL="${1:-http://localhost:8080}"
|
||||
ITERATIONS="${2:-100}"
|
||||
|
||||
PRODUCTS=("laptop" "keyboard" "mouse" "monitor" "headset" "webcam")
|
||||
CUSTOMERS=("cust-001" "cust-002" "cust-003" "cust-004" "cust-005")
|
||||
|
||||
PRICES_laptop=999.99
|
||||
PRICES_keyboard=79.99
|
||||
PRICES_mouse=49.99
|
||||
PRICES_monitor=349.99
|
||||
PRICES_headset=129.99
|
||||
PRICES_webcam=89.99
|
||||
|
||||
echo "========================================="
|
||||
echo " OTel Demo Traffic Generator"
|
||||
echo " Target: ${BASE_URL}"
|
||||
echo " Iterations: ${ITERATIONS}"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
success=0
|
||||
errors=0
|
||||
|
||||
for i in $(seq 1 "$ITERATIONS"); do
|
||||
# Pick a random product and customer
|
||||
product=${PRODUCTS[$((RANDOM % ${#PRODUCTS[@]}))]}
|
||||
customer=${CUSTOMERS[$((RANDOM % ${#CUSTOMERS[@]}))]}
|
||||
|
||||
# Vary quantity — occasionally large orders to trigger "complex" processing
|
||||
if (( RANDOM % 5 == 0 )); then
|
||||
quantity=$((RANDOM % 20 + 6)) # 6-25 items (complex)
|
||||
else
|
||||
quantity=$((RANDOM % 5 + 1)) # 1-5 items (simple)
|
||||
fi
|
||||
|
||||
# Look up price
|
||||
price_var="PRICES_${product}"
|
||||
unit_price="${!price_var}"
|
||||
|
||||
# Send the order
|
||||
status=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||
-X POST "${BASE_URL}/api/orders" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"customerId\": \"${customer}\",
|
||||
\"product\": \"${product}\",
|
||||
\"quantity\": ${quantity},
|
||||
\"unitPrice\": ${unit_price}
|
||||
}" 2>/dev/null || echo "000")
|
||||
|
||||
if [[ "$status" =~ ^2 ]]; then
|
||||
((success++))
|
||||
echo "[${i}/${ITERATIONS}] ✓ ${status} — ${product} x${quantity} for ${customer}"
|
||||
else
|
||||
((errors++))
|
||||
echo "[${i}/${ITERATIONS}] ✗ ${status} — ${product} x${quantity} for ${customer}"
|
||||
fi
|
||||
|
||||
# Small delay to spread the load
|
||||
sleep "0.$((RANDOM % 5 + 1))"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo " Results"
|
||||
echo " Successful: ${success}"
|
||||
echo " Errors: ${errors}"
|
||||
echo " Total: ${ITERATIONS}"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# Also hit the list and inventory endpoints
|
||||
echo "Fetching order list..."
|
||||
curl -s "${BASE_URL}/api/orders" | head -c 500
|
||||
echo ""
|
||||
|
||||
echo "Fetching inventory levels..."
|
||||
curl -s "${BASE_URL}/api/inventory"
|
||||
echo ""
|
||||
|
||||
echo ""
|
||||
echo "Done! Open Grafana at http://localhost:3000 to explore:"
|
||||
echo " → Explore → Prometheus: rate(orders_total[5m])"
|
||||
echo " → Explore → Tempo: { resource.service.name = \"otel-quarkus-demo\" }"
|
||||
echo " → Explore → Loki: {service_name=\"otel-quarkus-demo\"}"
|
||||
Reference in New Issue
Block a user