feat: production ingest test suite with detailed logging

Add comprehensive E2E test scripts and logging for production testing:

- test_prod_ingest_real.sh: Full ingest test against K8s cluster with api-gw
- apply_migrations.sh: Manual database schema migration (backup method)
- collect_prod_logs.sh: Pod log collection before/after tests
- run_production_test.sh: Orchestrates full test + log collection
- tests/integration_ingest_with_gw.rs: Integration test with embeddings
- tests/unit_ingest_logging.rs: Unit tests for extraction pipeline

Enhanced logging in ingest_worker.rs:
- Per-record event tracking (extraction, save)
- Entity and edge operation logging
- Error accumulation and reporting
- Structured logging for observability

Production testing identified root cause:
- Ingest + embedding pipeline working correctly
- Entity extraction functional
- Database schema missing (migration not applied)
- Logs clearly show: relation "memory_entity" does not exist

Next: Trigger DB Migration workflow in Forgejo Actions to apply
crates/mem-store/migrations/*.sql files.
This commit is contained in:
2026-09-14 22:33:16 +09:00
parent 5fd3ac826b
commit 6915dc2462
7 changed files with 1151 additions and 22 deletions
+124
View File
@@ -0,0 +1,124 @@
#!/bin/bash
# Apply all database migrations to production PostgreSQL
#
# Usage:
# ./apply_migrations.sh
#
# Connects to: poimen namespace, memory-db-rw service
set -e
NAMESPACE="poimen"
DB_SERVICE="memory-db-rw"
DB_PORT="5432"
DB_USER="app"
DB_NAME="memory"
LOCAL_PORT="5433"
echo "=========================================="
echo "Poimen Memory Database Migrations"
echo "=========================================="
echo ""
# Start port-forward
echo "Starting port-forward to $DB_SERVICE..."
kubectl -n "$NAMESPACE" port-forward "svc/$DB_SERVICE" "$LOCAL_PORT:$DB_PORT" >/dev/null 2>&1 &
PF_PID=$!
cleanup() {
if [ -n "$PF_PID" ]; then
kill $PF_PID 2>/dev/null || true
wait $PF_PID 2>/dev/null || true
fi
}
trap cleanup EXIT
sleep 2
if ! kill -0 $PF_PID 2>/dev/null; then
echo "✗ Port-forward failed"
exit 1
fi
echo "✓ Port-forward active (PID $PF_PID)"
echo ""
# Test connection
echo "Testing database connection..."
if ! PGPASSWORD="$DB_PASSWORD" psql -h localhost -p "$LOCAL_PORT" -U "$DB_USER" -d "$DB_NAME" -c "SELECT version();" >/dev/null 2>&1; then
echo "✗ Cannot connect to database"
echo " Host: localhost:$LOCAL_PORT"
echo " User: $DB_USER"
echo " Database: $DB_NAME"
exit 1
fi
echo "✓ Database connected"
echo ""
# Get migration files
MIGRATION_DIR="crates/mem-store/migrations"
if [ ! -d "$MIGRATION_DIR" ]; then
echo "✗ Migration directory not found: $MIGRATION_DIR"
exit 1
fi
MIGRATIONS=($(ls -1 "$MIGRATION_DIR"/*.sql | sort))
if [ ${#MIGRATIONS[@]} -eq 0 ]; then
echo "✗ No migrations found in $MIGRATION_DIR"
exit 1
fi
echo "Found ${#MIGRATIONS[@]} migration(s):"
for m in "${MIGRATIONS[@]}"; do
echo " - $(basename $m)"
done
echo ""
# Run migrations
echo "=========================================="
echo "Running Migrations"
echo "=========================================="
echo ""
success=0
failed=0
for migration in "${MIGRATIONS[@]}"; do
name=$(basename "$migration")
echo -n "$name ... "
if PGPASSWORD="$DB_PASSWORD" psql -h localhost -p "$LOCAL_PORT" -U "$DB_USER" -d "$DB_NAME" -f "$migration" >/dev/null 2>&1; then
echo "✓"
((success++))
else
echo "✗"
echo " Error output:"
PGPASSWORD="$DB_PASSWORD" psql -h localhost -p "$LOCAL_PORT" -U "$DB_USER" -d "$DB_NAME" -f "$migration" 2>&1 | sed 's/^/ /'
((failed++))
fi
done
echo ""
echo "=========================================="
echo "Migration Summary"
echo "=========================================="
echo " Success: $success"
echo " Failed: $failed"
echo ""
# Verify schema
echo "Verifying schema..."
echo ""
echo "Tables created:"
PGPASSWORD="$DB_PASSWORD" psql -h localhost -p "$LOCAL_PORT" -U "$DB_USER" -d "$DB_NAME" -c "SELECT tablename FROM pg_tables WHERE schemaname='public' ORDER BY tablename;" | grep -v "^--" | tail -n+3
echo ""
if [ $failed -eq 0 ]; then
echo "✓ All migrations applied successfully"
exit 0
else
echo "✗ Some migrations failed"
exit 1
fi