slogan3

Ontwerp een GitHub Actions Workflow voor Geautomatiseerde Performance Monitoring

description

Met deze prompt kan de gebruiker een aangepaste GitHub Actions workflow creëren die automatisch performance metrics bewaakt en rapporteert, waardoor problemen vroegtijdig worden gesignaleerd en de betrouwbaarheid van de applicatie wordt verhoogd. Dit helpt downtime te voorkomen en optimaliseert de gebruikerservaring, beter dan alternatieven die enkel build- en testprocessen automatiseren.

prompt

Help me een GitHub Actions workflow te ontwerpen die geautomatiseerde performance monitoring uitvoert tijdens mijn CI/CD proces. Projecttype: <voer je projecttype in, bijvoorbeeld Node.js, Python, Java>. Monitoring tools die ik wil integreren: < ...

try_prompt

generate_helper
disclaimerOnPageApi

ai_answers

provider: openai
model: gpt-4.1-nano
Hier is een voorstel voor een GitHub Actions workflow die geautomatiseerde performance monitoring uitvoert met Lighthouse en aangepaste scripts voor jouw Node.js project. Deze workflow controleert na de build en tests of de laadtijd onder de 2 seconden blijft en de API-responstijd onder 100ms. ```yaml name: CI met Performance Monitoring on: push: branches: - main # of jouw hoofdbranch jobs: build-en-monitor: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '14' - name: Install dependencies run: npm install - name: Run tests run: npm test - name: Install Lighthouse run: npm install -g lighthouse - name: Perform Lighthouse Performance Test run: | # Voer Lighthouse audit voor je lokale/deploy URL lighthouse https://jouw-website-url.nl --output=json --output-path=./lighthouse-report.json --quiet - name: Check Lighthouse Laadtijd run: | # Extract de First Contentful Paint (FCP) of de laadtijd uit Lighthouse rapport LOAD_TIME=$(jq -r '.audits["largest-contentful-paint"].numericValue' lighthouse-report.json) echo "Laadtijd (ms): $LOAD_TIME" if (( LOAD_TIME > 2000 )); then echo "Performance alert: Laadtijd is meer dan 2 seconden!" exit 1 fi - name: Run custom API responstijd test run: | # Bijvoorbeeld met curl en time, test API-respons RESPONSE_TIME=$(curl -s -w %{time_total} -o /dev/null https://jouw-api-url.nl) echo "API responstijd (s): $RESPONSE_TIME" RESPONSE_MS=$(echo "$RESPONSE_TIME * 1000" | bc) if (( $(echo "$RESPONSE_MS > 100" | bc -l) )); then echo "API-responsduur is meer dan 100ms!" exit 1 fi # Voeg eventueel meer monitoring of rapportage toe ``` **Aanpassingen:** - Vervang `https://jouw-website-url.nl` door je daadwerkelijke website URL. - Vervang `https://jouw-api-url.nl` door je API endpoint. - Je kunt de thresholds aanpassen indien nodig. **Wat doet deze workflow?** - Checkt code bij elke push naar hoofdbranch. - Installeert dependencies en voert tests uit. - Installeert Lighthouse en voert een performance audit uit. - Controleert of de laadtijd onder de 2 seconden ligt. - Voert een eenvoudige curl-test uit om de API-responstijd te meten en te controleren of deze onder de 100ms blijft. Zo heb je een automatische performance monitoring geïntegreerd in je CI/CD proces!
provider: deepseek
model: deepseek-chat
Hier is een aangepaste GitHub Actions workflow met geïntegreerde performance monitoring: ```yaml name: CI met Performance Monitoring on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '14' - run: npm install - run: npm test performance-monitoring: runs-on: ubuntu-latest needs: build steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '14' - run: npm install - name: Start applicatie run: npm start & env: NODE_ENV: production - name: Wacht op applicatie run: npx wait-on http://localhost:3000 --timeout 60000 - name: Installeer Lighthouse run: npm install -g lighthouse - name: Voer Lighthouse audit uit run: | lighthouse http://localhost:3000 --output=json --output-path=./lighthouse-results.json \ --chrome-flags="--headless --no-sandbox" - name: Voer custom performance scripts uit run: node scripts/performance-test.js env: PERFORMANCE_TARGET_LOADTIME: 2000 PERFORMANCE_TARGET_API_RESPONSE: 100 - name: Analyseer resultaten run: node scripts/analyze-performance.js - name: Upload Lighthouse rapport uses: actions/upload-artifact@v3 with: name: lighthouse-report path: lighthouse-results.json ``` **Aanvullende bestanden die je nodig hebt:** 1. **scripts/performance-test.js**: ```javascript const axios = require('axios'); async function runPerformanceTests() { const loadTimeTarget = parseInt(process.env.PERFORMANCE_TARGET_LOADTIME); const apiResponseTarget = parseInt(process.env.PERFORMANCE_TARGET_API_RESPONSE); // Test API response tijd const start = Date.now(); await axios.get('http://localhost:3000/api/health'); const apiResponseTime = Date.now() - start; console.log(`API Response Time: ${apiResponseTime}ms`); if (apiResponseTime > apiResponseTarget) { throw new Error(`API response tijd ${apiResponseTime}ms overschrijdt doel van ${apiResponseTarget}ms`); } // Simuleer pagina laadtijd test const loadTime = await simulatePageLoad(); console.log(`Gesimuleerde laadtijd: ${loadTime}ms`); if (loadTime > loadTimeTarget) { throw new Error(`Laadtijd ${loadTime}ms overschrijdt doel van ${loadTimeTarget}ms`); } console.log('✅ Alle performance doelen behaald'); } async function simulatePageLoad() { // Voeg hier je eigen laadtijd meting logica toe return Math.random() * 1500 + 500; // Voorbeeld } runPerformanceTests().catch(console.error); ``` 2. **scripts/analyze-performance.js**: ```javascript const fs = require('fs'); function analyzeLighthouseResults() { try { const data = JSON.parse(fs.readFileSync('./lighthouse-results.json', 'utf8')); const performanceScore = data.categories.performance.score * 100; const firstContentfulPaint = data.audits['first-contentful-paint'].numericValue; const largestContentfulPaint = data.audits['largest-contentful-paint'].numericValue; console.log(`Lighthouse Performance Score: ${performanceScore}`); console.log(`First Contentful Paint: ${firstContentfulPaint}ms`); console.log(`Largest Contentful Paint: ${largestContentfulPaint}ms`); if (performanceScore < 80) { throw new Error('Lighthouse performance score onder 80'); } if (firstContentfulPaint > 2000) { throw new Error('First Contentful Paint overschrijdt 2 seconden'); } } catch (error) { console.error('Performance analyse gefaald:', error.message); process.exit(1); } } analyzeLighthouseResults(); ``` **package.json aanpassingen**: ```json { "scripts": { "performance-test": "node scripts/performance-test.js", "analyze-performance": "node scripts/analyze-performance.js" }, "devDependencies": { "lighthouse": "^9.6.8", "axios": "^1.4.0", "wait-on": "^7.0.1" } } ``` Deze workflow: - Voert eerst de bestaande build en tests uit - Start je applicatie en wacht tot deze beschikbaar is - Voert Lighthouse audits uit voor web performance - Voert custom performance tests uit met je specifieke doelen - Faalt de workflow als performance doelen niet worden gehaald - Bewaart gedetailleerde rapporten als artifacts