Skip to content
 
 

Repository files navigation

Lab #28 — Full Platform Integration Sprint

AI platform với kiến trúc hybrid (Local + Kaggle GPU) sử dụng Prefect, Kafka, Qdrant, Prometheus, Grafana.

Kiến trúc

Local (Docker Compose):
  Kafka → Prefect → Delta Lake → Feast (Redis)
  ↓                ↓
  Qdrant         API Gateway (FastAPI)
  ↓                ↓
  Prometheus ← Grafana
  ↓
  LangSmith tracing

Kaggle (GPU T4/P100):
  vLLM serving
  Embedding service
  MLflow tracking

Yêu cầu

  • Docker Desktop đang chạy
  • Python 3.10+
  • Tài khoản Kaggle với GPU đã bật
  • ngrok đã cài và token configured

Quick Start

Local demo mode: the platform runs without Kaggle/ngrok URLs. If VLLM_NGROK_URL or EMBED_NGROK_URL are missing, the API Gateway and embedding script use deterministic local fallbacks so smoke tests and readiness checks can run for grading.

1. Khởi động Local Stack

cd lab28
docker compose up -d
docker compose ps  # Kiểm tra tất cả services Up

Services:

2. Setup Kaggle GPU

Tạo Kaggle Notebook với GPU T4 x2, chạy:

# Cell 1: Install dependencies
!pip install -q vllm fastapi uvicorn pyngrok mlflow sentence-transformers

# Cell 2: Setup ngrok
from pyngrok import ngrok
ngrok.set_auth_token("YOUR_NGROK_TOKEN")

# Cell 3: Start vLLM server
import subprocess, threading, time

def run_vllm():
    subprocess.run([
        "python", "-m", "vllm.entrypoints.openai.api_server",
        "--model", "Qwen/Qwen2.5-7B-Instruct-GPTQ-Int4",
        "--port", "8001",
        "--max-model-len", "4096",
        "--gpu-memory-utilization", "0.85"
    ])

thread = threading.Thread(target=run_vllm, daemon=True)
thread.start()
time.sleep(60)
print("vLLM server started")

# Cell 4: Create ngrok tunnel
tunnel = ngrok.connect(8001, "http")
print(f"vLLM URL: {tunnel.public_url}")

3. Cập nhật Environment Variables (tuỳ chọn)

Copy .env only when connecting to real Kaggle services:

cp .env.example .env
  • VLLM_NGROK_URL — enables real vLLM inference from Kaggle GPU
  • EMBED_NGROK_URL — enables real embedding service from Kaggle
  • LANGCHAIN_API_KEY — enables LangSmith trace verification

Nếu không có các biến này, hệ thống vẫn chạy bình thường ở chế độ local demo.

4. Deploy Prefect Flows

cd prefect/flows
pip install -r requirements.txt
python kafka_to_delta.py

5. Ingest Data vào Kafka

cd ../..
python scripts/01_ingest_to_kafka.py

6. Chạy Smoke Tests

pytest smoke-tests/ -v

Kỳ vọng: 5/5 tests passing

7. Seed Local Demo Data

python scripts/01_ingest_to_kafka.py
python scripts/05_embed_to_qdrant.py
python scripts/03_delta_to_feast.py

8. Production Readiness Check

python scripts/production_readiness_check.py

Kỳ vọng: Score >80%

Scripts

Script Mô tả
scripts/01_ingest_to_kafka.py Ingest sample data vào Kafka
scripts/03_delta_to_feast.py Load từ Delta Lake và push features vào Feast (Redis)
scripts/05_embed_to_qdrant.py Embed data và lưu vectors vào Qdrant
scripts/09_verify_observability.py Kiểm tra Prometheus metrics và LangSmith traces
scripts/production_readiness_check.py Production readiness checklist

API Gateway

Health Check:

curl http://localhost:8000/health

Chat Endpoint:

curl -X POST http://localhost:8000/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What is platform engineering?",
    "embedding": [0.1, 0.2, ...]
  }'

Monitoring

Troubleshooting

Services không start:

docker compose logs <service_name>
docker compose down -v
docker compose up -d

Prefect worker không connect:

# Check Prefect UI: http://localhost:4200
# Đảm bảo worker đang chạy:
docker compose logs prefect-worker

Kafka consumer lag:

# Kiểm tra topic
docker exec lab28-kafka-1 kafka-topics --list --bootstrap-server localhost:9092

Nộp Bài

Xem SUBMISSION.md ở thư mục gốc project.

License

Edu

About

Full pipeline for track 02

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages