guptaaryan16/observability_env_test
0
1#!/bin/bash2# Phase 1: The "Chaos" Recipe (Generating the Dataset)3# This script sets up the workspace, modifying the Google Microservices Demo to include bugs.4 5set -e6 7WORKSPACE_DIR="./workspace"8REPO_URL="https://github.com/GoogleCloudPlatform/microservices-demo.git"9 10echo "Setting up workspace..."11mkdir -p "$WORKSPACE_DIR"12cd "$WORKSPACE_DIR"13 14if [ ! -d "microservices-demo" ]; then15 echo "Cloning microservices-demo..."16 git clone $REPO_URL17fi18 19cd microservices-demo20git checkout main21 22echo "Injecting Task 1: Syntax Trace (ERR_CART_OVERLOAD)"23# Simulating the checkout failure bug on line 24524CHECKOUT_GO="src/checkoutservice/main.go"25if grep -q "ERR_CART_OVERLOAD" "$CHECKOUT_GO"; then26 echo "Task 1 bug already injected."27else28 # Find the PlaceOrder function and inject the error logic29 # This is a naive injection for demo purposes.30 sed -i '/func (cs \*checkoutService) PlaceOrder(.* {/a \31\t// INJECTED BUG: Fail if items > 3 (ERR_CART_OVERLOAD)\n\tif len(req.UserCurrency) == 3 { \n\t\tlog.Errorf("Payment gateway timeout simulation: ERR_CART_OVERLOAD")\n\t\treturn nil, status.Errorf(codes.ResourceExhausted, "ERR_CART_OVERLOAD")\n\t}' "$CHECKOUT_GO"32 echo "Task 1 bug injected."33fi34 35echo "Injecting Task 2: Config Mismatch (SMTP_PORT missing)"36# Modifying compose manifest to remove SMTP_PORT37# We'll just mock this for the log generation phase by editing docker-compose38docker-compose --version || echo "Docker-compose not installed, but we would remove SMTP_PORT from emailservice env vars here."39 40echo "Injecting Task 3: Silent Logical Bug (shipping calculation)"41SHIPPING_GO="src/shippingservice/main.go"42if grep -q "count \* 0.5" "$SHIPPING_GO"; then43 echo "Task 3 bug already injected."44else45 # Naively finding the quote math. Actual repo logic varies, so we just mock a change46 echo "Mocking shipping logic calculation bug..."47 sed -i 's/val \* 5.0/val \* 0.5/g' "$SHIPPING_GO" 2>/dev/null || true48fi49 50echo "Moving code to correct structure for the agent..."51mkdir -p ../src52mkdir -p ../logs53cp -r src/checkoutservice ../src/54cp -r src/emailservice ../src/55cp -r src/shippingservice ../src/56 57echo "Mocking log dumps..."58# In a real environment, you'd run `docker-compose up -d`, use a load generator, and `docker logs`.59# We output synthetic logs for the agent based on the injected bugs to complete the dataset design.60 61cat <<EOF > ../logs/checkoutservice.log62time="2024-05-15T12:00:00Z" level=info msg="Starting CheckoutService"63time="2024-05-15T12:05:22Z" level=error msg="Payment gateway timeout simulation: ERR_CART_OVERLOAD" req_id="123"64time="2024-05-15T12:05:22Z" level=info msg="Checkout failed."65EOF66 67cat <<EOF > ../logs/emailservice.log68time="2024-05-15T12:00:00Z" level=info msg="Starting Python Email Service"69Traceback (most recent call last):70 File "email_server.py", line 45, in <module>71 port = os.environ['SMTP_PORT']72 File "/usr/lib/python3.8/os.py", line 680, in __getitem__73 raise KeyError(key) from None74KeyError: 'SMTP_PORT'75EOF76 77cat <<EOF > ../logs/shippingservice.log78time="2024-05-15T12:00:00Z" level=info msg="Starting Shipping Service"79time="2024-05-15T12:10:00Z" level=info msg="Received Quote request for 10 items"80time="2024-05-15T12:10:00Z" level=info msg="Quote calculated. Total cost processed: $5.00"81EOF82 83# Provide ripgrep wrapper or ensure it's documented.84echo "Dataset generated successfully in $WORKSPACE_DIR."85 