Skip to content

Commit 366fda6

Browse files
authored
Merge pull request #1 from splunk/SQ-server-on--fraud
Sql server added to frauddetection
2 parents 2ae520c + ab2d207 commit 366fda6

27 files changed

+3791
-234
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ the release.
77

88
## Unreleased
99

10+
* [fraud-detection] Add automatic SQL Server database initialization for FraudDetection database
11+
- Added ConfigMap with database initialization script
12+
- Added postStart lifecycle hook to execute init script on SQL Server startup
13+
- Fixed connection string to use correct database name (FraudDetection)
1014
* [chore] Use pre-built nginx otel image
1115
([#2614](https://github.com/open-telemetry/opentelemetry-demo/pull/2614))
1216
* [grafana] Update grafana version to 12.2.0

DEMO_WORKFLOW.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Demo Workflow - Build Up & Tear Down
2+
3+
Perfect for demos that get built up and torn down frequently!
4+
5+
## 🚀 Deploy (One Command)
6+
7+
```bash
8+
cd /Users/phagen/GIT/opentelemetry-demo-Splunk
9+
kubectl apply -f kubernetes/opentelemetry-demo.yaml
10+
```
11+
12+
Wait ~3 minutes for everything to initialize.
13+
14+
## 🧹 Tear Down (One Command)
15+
16+
```bash
17+
./cleanup.sh
18+
```
19+
20+
This script:
21+
- ✅ Deletes all deployments, services, statefulsets
22+
- ✅ Cleans up all PVCs (prevents corrupted data)
23+
- ✅ Ensures fresh start on next deploy
24+
25+
## What's Configured for Easy Demos
26+
27+
### SQL Server StatefulSet
28+
**Added automatic PVC cleanup:**
29+
```yaml
30+
persistentVolumeClaimRetentionPolicy:
31+
whenDeleted: Delete # Auto-delete PVC when StatefulSet deleted
32+
whenScaled: Delete # Auto-delete PVC when scaled down
33+
```
34+
35+
This means:
36+
- `kubectl delete` will automatically remove the PVC
37+
- No corrupted SQL Server data on next deploy
38+
- Clean slate every time
39+
40+
### Fraud Detection Service
41+
**Auto-initializes everything:**
42+
- Creates `FraudDetection` database if missing
43+
- Creates `OrderLogs` table if missing
44+
- Logs every Kafka order message
45+
46+
## Complete Demo Cycle
47+
48+
### 1. Deploy
49+
```bash
50+
kubectl apply -f kubernetes/opentelemetry-demo.yaml
51+
```
52+
53+
### 2. Verify
54+
```bash
55+
# Check pods are running
56+
kubectl get pods -n otel-demo
57+
kubectl get pods -n sql
58+
59+
# Watch fraud-detection logs
60+
kubectl logs -f -n otel-demo -l app.kubernetes.io/component=fraud-detection
61+
```
62+
63+
### 3. Use the Demo
64+
```bash
65+
# Access frontend
66+
kubectl port-forward -n otel-demo svc/frontend 8080:8080
67+
# Browse to http://localhost:8080 and place orders
68+
69+
# Access SQL Server
70+
kubectl port-forward -n sql svc/sql-express 1433:1433
71+
# Connect to localhost:1433 with sa/ChangeMe_SuperStrong123!
72+
```
73+
74+
### 4. Query Data
75+
```bash
76+
kubectl exec -it sql-express-0 -n sql -- /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'ChangeMe_SuperStrong123!' -Q "SELECT COUNT(*) FROM FraudDetection.dbo.OrderLogs"
77+
```
78+
79+
### 5. Tear Down
80+
```bash
81+
./cleanup.sh
82+
```
83+
84+
## Troubleshooting
85+
86+
### SQL Server in CrashLoopBackOff
87+
88+
**Cause:** Corrupted PVC from previous deployment
89+
90+
**Fix:**
91+
```bash
92+
kubectl delete statefulset sql-express -n sql
93+
kubectl delete pvc data-sql-express-0 -n sql
94+
kubectl apply -f kubernetes/opentelemetry-demo.yaml
95+
```
96+
97+
### Fraud Detection Stuck "waiting for sql-express"
98+
99+
**Cause:** SQL Server not ready
100+
101+
**Fix:**
102+
```bash
103+
# Check SQL Server status
104+
kubectl get pods -n sql
105+
kubectl logs sql-express-0 -n sql
106+
107+
# If SQL Server is crashing, clean and redeploy
108+
./cleanup.sh
109+
kubectl apply -f kubernetes/opentelemetry-demo.yaml
110+
```
111+
112+
## Files Modified for Demo Workflow
113+
114+
### Changed
115+
- `kubernetes/opentelemetry-demo.yaml`
116+
- Line 343-345: Added `persistentVolumeClaimRetentionPolicy` to sql-express StatefulSet
117+
- Line 1372: Updated fraud-detection image to `2.1.3-sql.1`
118+
- Line 1402-1411: Added SQL Server environment variables
119+
- Line 1423-1428: Added wait-for-sqlserver init container
120+
121+
### Added
122+
- `cleanup.sh` - Automated cleanup script
123+
- `src/fraud-detection/build-fraud-detection.sh` - Build script
124+
- All fraud-detection code for SQL Server logging
125+
126+
## Quick Reference
127+
128+
| Action | Command |
129+
|--------|---------|
130+
| Deploy | `kubectl apply -f kubernetes/opentelemetry-demo.yaml` |
131+
| Tear Down | `./cleanup.sh` |
132+
| Watch Logs | `kubectl logs -f -n otel-demo -l app.kubernetes.io/component=fraud-detection` |
133+
| SQL Status | `kubectl get pods -n sql` |
134+
| Access Frontend | `kubectl port-forward -n otel-demo svc/frontend 8080:8080` |
135+
| Access SQL Server | `kubectl port-forward -n sql svc/sql-express 1433:1433` |
136+
| Query Database | See "Query Data" section above |
137+
138+
## Expected Timeline
139+
140+
- **Deploy:** 3 minutes
141+
- **Tear Down:** 30 seconds
142+
- **Redeploy:** 2 minutes (with cleanup)
143+
144+
Perfect for rapid demo cycles! 🎯

cleanup.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Cleanup script for OpenTelemetry Demo with SQL Server
3+
# This ensures a clean teardown for demos that get built up and torn down often
4+
5+
set -e
6+
7+
echo "🧹 Cleaning up OpenTelemetry Demo..."
8+
9+
# Delete all resources from the main manifest
10+
echo "Deleting deployments, services, and statefulsets..."
11+
kubectl delete -f kubernetes/opentelemetry-demo.yaml --ignore-not-found=true
12+
13+
# Give it a moment to process deletions
14+
sleep 2
15+
16+
# Delete any remaining PVCs (in case retention policy doesn't work)
17+
echo "Cleaning up PVCs..."
18+
kubectl delete pvc --all -n sql --ignore-not-found=true
19+
kubectl delete pvc --all -n otel-demo --ignore-not-found=true
20+
21+
# Optional: Delete namespaces for a complete clean
22+
# Uncomment these lines if you want to remove namespaces too
23+
# echo "Deleting namespaces..."
24+
# kubectl delete namespace sql --ignore-not-found=true
25+
# kubectl delete namespace otel-demo --ignore-not-found=true
26+
27+
echo "✅ Cleanup complete!"
28+
echo ""
29+
echo "To redeploy, run:"
30+
echo " kubectl apply -f kubernetes/opentelemetry-demo.yaml"

kubernetes/bundle-k8s-manifest.sh

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)