Skip to content

Commit 464bc78

Browse files
committed
test
1 parent 6283460 commit 464bc78

File tree

1 file changed

+7
-95
lines changed
  • terraform/python/ec2/adot-genai

1 file changed

+7
-95
lines changed

terraform/python/ec2/adot-genai/main.tf

Lines changed: 7 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -112,104 +112,16 @@ done
112112
# Create traffic generator script
113113
cat > /app/generate_traffic.sh << 'TRAFFIC_EOF'
114114
#!/bin/bash
115-
116-
# Configuration
117-
SERVER_URL="$${SERVER_URL:-http://localhost:8000}"
118-
ENDPOINT="$$SERVER_URL/ai-chat"
119-
DELAY_SECONDS="$${DELAY_SECONDS:-3600}"
115+
DELAY_SECONDS="$${DELAY_SECONDS:-60}"
120116
NUM_REQUESTS="$${NUM_REQUESTS:-5}"
121117
TIMEOUT="$${TIMEOUT:-30}"
118+
MESSAGES=("What is the weather like today?" "Tell me a joke" "How do I make a cup of coffee?" "What are the benefits of exercise?" "Explain quantum computing in simple terms")
122119
123-
124-
# Array of sample messages
125-
MESSAGES=(
126-
"What is the weather like today?"
127-
"Tell me a joke"
128-
"How do I make a cup of coffee?"
129-
"What are the benefits of exercise?"
130-
"Explain quantum computing in simple terms"
131-
"What's the capital of France?"
132-
"How do I learn programming?"
133-
"What are some healthy breakfast ideas?"
134-
"Tell me about artificial intelligence"
135-
"How can I improve my productivity?"
136-
"What's the difference between a list and a tuple in Python?"
137-
"Explain the concept of microservices"
138-
"What are some best practices for API design?"
139-
"How does machine learning work?"
140-
"What's the purpose of unit testing?"
141-
)
142-
143-
# Function to send a request
144-
send_request() {
145-
local message="$$1"
146-
local request_num="$$2"
147-
local timestamp=$$(date '+%Y-%m-%d %H:%M:%S')
148-
149-
echo "[$$timestamp] Request #$$request_num"
150-
echo "Message: \"$$message\""
151-
152-
local trace_id_header="$${TRACE_ID:-${var.trace_id}}"
153-
154-
echo "Using Trace ID: $$trace_id_header"
155-
156-
response=$$(curl -s -X POST "$$ENDPOINT" \
157-
-H "Content-Type: application/json" \
158-
-H "X-Amzn-Trace-Id: $$trace_id_header" \
159-
-d "{\"message\": \"$$message\"}" \
160-
-m "$$TIMEOUT" \
161-
-w "\nHTTP_STATUS:%%{http_code}\nTIME_TOTAL:%%{time_total}")
162-
163-
http_status=$$(echo "$$response" | grep "HTTP_STATUS:" | cut -d: -f2)
164-
time_total=$$(echo "$$response" | grep "TIME_TOTAL:" | cut -d: -f2)
165-
body=$$(echo "$$response" | sed '/HTTP_STATUS:/d' | sed '/TIME_TOTAL:/d')
166-
167-
if [ "$$http_status" = "200" ]; then
168-
echo "Success ($${time_total}s)"
169-
echo "Response: $$body"
170-
else
171-
echo "Error: HTTP $$http_status"
172-
if [ -n "$$body" ]; then
173-
echo "Response: $$body"
174-
fi
175-
fi
176-
echo "---"
177-
}
178-
179-
echo "Starting traffic generation to $$ENDPOINT"
180-
echo "Configuration:"
181-
echo " - Delay between requests: $${DELAY_SECONDS}s"
182-
echo " - Request timeout: $${TIMEOUT}s"
183-
echo " - Number of requests: $${NUM_REQUESTS} (0 = infinite)"
184-
echo " - Requests per minute: ~$$((60 / DELAY_SECONDS))"
185-
echo "=================================="
186-
187-
count=0
188-
start_time=$$(date +%s)
189-
190-
while true; do
191-
random_index=$$((RANDOM % $${#MESSAGES[@]}))
192-
message="$${MESSAGES[$$random_index]}"
193-
194-
count=$$((count + 1))
195-
196-
send_request "$$message" "$$count"
197-
198-
if [ "$$NUM_REQUESTS" -gt 0 ] && [ "$$count" -ge "$$NUM_REQUESTS" ]; then
199-
end_time=$$(date +%s)
200-
duration=$$((end_time - start_time))
201-
echo "Completed $$count requests in $${duration}s"
202-
break
203-
fi
204-
205-
if [ $$((count % 10)) -eq 0 ]; then
206-
current_time=$$(date +%s)
207-
elapsed=$$((current_time - start_time))
208-
rate=$$(echo "scale=2; $$count / $$elapsed * 60" | bc 2>/dev/null || echo "N/A")
209-
echo "Progress: $$count requests sent, Rate: $${rate} req/min"
210-
fi
211-
212-
sleep "$$DELAY_SECONDS"
120+
for i in $$(seq 1 $$NUM_REQUESTS); do
121+
message="$${MESSAGES[$$((RANDOM % $${#MESSAGES[@]}))]}"
122+
echo "Request $$i: $$message"
123+
curl -X POST http://localhost:8000/ai-chat -H "Content-Type: application/json" -d "{\"message\": \"$$message\"}" -m $$TIMEOUT
124+
sleep $$DELAY_SECONDS
213125
done
214126
TRAFFIC_EOF
215127

0 commit comments

Comments
 (0)