Skip to content

Add monitoring for resilientdb performance from rescanvas operations #200

Add monitoring for resilientdb performance from rescanvas operations

Add monitoring for resilientdb performance from rescanvas operations #200

Workflow file for this run

name: ResCanvas Test Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
PYTHON_VERSION: '3.10'
NODE_VERSION: '18'
jobs:
backend-unit-tests:
name: Backend Unit Tests
runs-on: ubuntu-latest
services:
mongodb:
image: mongo:6
env:
MONGO_INITDB_ROOT_USERNAME: testuser
MONGO_INITDB_ROOT_PASSWORD: testpass
options: >-
--health-cmd "mongosh --eval 'db.adminCommand(\"ping\")'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 27017:27017
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache Python dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Wait for MongoDB
run: |
for i in {1..30}; do
if mongosh --host localhost:27017 --username testuser --password testpass --authenticationDatabase admin --eval "db.adminCommand('ping')" > /dev/null 2>&1; then
echo "MongoDB is ready"
break
fi
echo "Waiting for MongoDB... ($i/30)"
sleep 2
done
- name: Install dependencies
run: |
cd backend
pip install -r requirements.txt
- name: Generate test keys
run: |
cd backend
python3 gen_keys.py > /tmp/keys.txt
export SIGNER_PUBLIC_KEY=$(grep "Public Key:" /tmp/keys.txt | awk '{print $3}')
export SIGNER_PRIVATE_KEY=$(grep "Private Key:" /tmp/keys.txt | awk '{print $3}')
printf "JWT_SECRET=test-secret-key-do-not-use-in-production\n" > .env
printf "MONGO_ATLAS_URI=mongodb://testuser:testpass@localhost:27017/?authSource=admin\n" >> .env
printf "SIGNER_PUBLIC_KEY=%s\n" "$SIGNER_PUBLIC_KEY" >> .env
printf "SIGNER_PRIVATE_KEY=%s\n" "$SIGNER_PRIVATE_KEY" >> .env
printf "RESILIENTDB_GRAPHQL_URI=https://cloud.resilientdb.com/graphql\n" >> .env
printf "RES_DB_BASE_URI=https://crow.resilientdb.com\n" >> .env
- name: Run unit tests
env:
JWT_SECRET: 'test-secret-key-do-not-use-in-production'
RESILIENTDB_GRAPHQL_URI: 'https://cloud.resilientdb.com/graphql'
RES_DB_BASE_URI: 'https://crow.resilientdb.com'
run: |
cd backend
export SIGNER_PUBLIC_KEY=$(grep "SIGNER_PUBLIC_KEY=" .env | cut -d'=' -f2)
export SIGNER_PRIVATE_KEY=$(grep "SIGNER_PRIVATE_KEY=" .env | cut -d'=' -f2)
pytest tests/unit/ -n auto -m unit
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./backend/coverage.xml
flags: backend-unit
name: backend-unit-coverage
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: backend-unit-coverage
path: backend/htmlcov/
frontend-unit-tests:
name: Frontend Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache Node modules
uses: actions/cache@v3
with:
path: frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: |
cd frontend
npm ci
- name: Run unit tests
run: |
cd frontend
npm test -- --coverage --watchAll=false --testPathIgnorePatterns='Canvas.test.js|Dashboard.test.js|App.test.js' --ci
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./frontend/coverage/coverage-final.json
flags: frontend-unit
name: frontend-unit-coverage
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: frontend-unit-coverage
path: frontend/coverage/
code-quality:
name: Code Quality Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Python linters
run: |
pip install flake8 black
- name: Run flake8
run: |
cd backend
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=incubator-*,__pycache__
- name: Check black formatting
continue-on-error: true
run: |
cd backend
black --check . --exclude='incubator-*'
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache Node modules
uses: actions/cache@v3
with:
path: frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install frontend dependencies
run: |
cd frontend
npm ci
- name: Run ESLint
run: |
cd frontend
npm run lint || true
coverage-report:
name: Generate Coverage Report
needs: [backend-unit-tests, frontend-unit-tests]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download all coverage artifacts
uses: actions/download-artifact@v4
- name: Display coverage summary
run: |
echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "Coverage reports have been uploaded to Codecov" >> $GITHUB_STEP_SUMMARY
echo "View detailed reports in the artifacts" >> $GITHUB_STEP_SUMMARY