GitLab CI/CD
Diese Anleitung erklaert, wie Sie den LoadFocus JMeter API Client mit GitLab CI/CD fuer automatisierte Leistungstests integrieren.
Einrichtungsschritte
1. Anmeldedaten als GitLab CI/CD-Variablen speichern
Speichern Sie zunaechst Ihre LoadFocus API-Zugangsdaten als GitLab CI/CD-Variablen:
- Gehen Sie zu Ihrem GitLab-Projekt
- Navigieren Sie zu Settings > CI/CD > Variables
- Fuegen Sie folgende Variablen hinzu:
LOADFOCUS_API_KEY: Ihr LoadFocus API-Schluessel (als "Masked" markieren)LOADFOCUS_TEAM_ID: Ihre LoadFocus Team-ID
2. GitLab CI/CD-Pipeline erstellen
Erstellen oder aktualisieren Sie Ihre .gitlab-ci.yml-Datei in Ihrem Repository:
stages:- build- test- performance- deployvariables:NODE_VERSION: "16"build:stage: buildimage: node:${NODE_VERSION}script:- npm install- npm run buildartifacts:paths:- dist/expire_in: 1 weektest:stage: testimage: node:${NODE_VERSION}script:- npm install- npm testperformance_test:stage: performanceimage: node:${NODE_VERSION}script:# Install LoadFocus JMeter API Client- npm install -g @loadfocus/loadfocus-api-client# Configure LoadFocus API Client- loadfocus-api config set apikey $LOADFOCUS_API_KEY- loadfocus-api config set teamid $LOADFOCUS_TEAM_ID# Run Performance Tests- |loadfocus-api jmeter run-test \--name "GitLab_${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.jsonartifacts:paths:- performance_results.jsonexpire_in: 1 weekwhen: always# Optional: Only run on specific branchesonly:- main- developdeploy:stage: deployscript:- echo "Deploying application..."only:- main# Only deploy if all previous stages succeededwhen: on_success
3. Testergebnisse anzeigen
Nachdem die Pipeline ausgefuehrt wurde:
- Gehen Sie zu Ihrem GitLab-Projekt
- Navigieren Sie zu CI/CD > Pipelines
- Finden Sie Ihre Pipeline und klicken Sie darauf
- Gehen Sie zum Job "performance_test"
- Klicken Sie auf "Browse" in der rechten Seitenleiste, um Artefakte anzuzeigen
- Laden Sie die Datei
performance_results.jsonherunter und sehen Sie sie ein
Erweiterte Konfiguration
Umgebungsspezifische Tests
Verschiedene Leistungstests fuer verschiedene Umgebungen ausfuehren:
.performance_test_template: &performance_test_definitionstage: performanceimage: node:${NODE_VERSION}script:- npm install -g @loadfocus/loadfocus-api-client- loadfocus-api config set apikey $LOADFOCUS_API_KEY- loadfocus-api config set teamid $LOADFOCUS_TEAM_ID- |loadfocus-api jmeter run-test \--name "${TEST_NAME}" \--thresholds "${THRESHOLDS}" \--format json > performance_results.jsonartifacts:paths:- performance_results.jsonexpire_in: 1 weekwhen: alwaysperformance_test_develop:<<: *performance_test_definitionvariables:TEST_NAME: "API_Test_Develop"THRESHOLDS: "avgresponse<=300,errors==0,p95<=500"only:- developperformance_test_staging:<<: *performance_test_definitionvariables:TEST_NAME: "API_Test_Staging"THRESHOLDS: "avgresponse<=250,errors==0,p95<=350"only:- stagingperformance_test_production:<<: *performance_test_definitionvariables:TEST_NAME: "API_Test_Production"THRESHOLDS: "avgresponse<=200,errors==0,p95<=250"only:- main
Parallele Tests
Mehrere Leistungstests parallel ausfuehren:
performance_test_api:stage: performanceimage: node:${NODE_VERSION}script:- npm install -g @loadfocus/loadfocus-api-client- loadfocus-api config set apikey $LOADFOCUS_API_KEY- loadfocus-api config set teamid $LOADFOCUS_TEAM_ID- |loadfocus-api jmeter run-test \--name "API_Performance_Test" \--thresholds "avgresponse<=150,errors==0" \--format json > api_performance_results.jsonartifacts:paths:- api_performance_results.jsonexpire_in: 1 weekperformance_test_ui:stage: performanceimage: node:${NODE_VERSION}script:- npm install -g @loadfocus/loadfocus-api-client- loadfocus-api config set apikey $LOADFOCUS_API_KEY- loadfocus-api config set teamid $LOADFOCUS_TEAM_ID- |loadfocus-api jmeter run-test \--name "UI_Performance_Test" \--thresholds "avgresponse<=300,errors==0" \--format json > ui_performance_results.jsonartifacts:paths:- ui_performance_results.jsonexpire_in: 1 week
Tipps fuer die GitLab CI/CD-Integration
Caching: npm-Abhaengigkeiten cachen, um Pipeline-Laeufe zu beschleunigen:
performance_test:stage: performanceimage: node:${NODE_VERSION}cache:key: ${CI_COMMIT_REF_SLUG}paths:- node_modules/script:- npm install -g @loadfocus/loadfocus-api-client# Rest of the script...Timeout-Einstellungen: Timeouts fuer lang laufende Leistungstests festlegen:
performance_test:stage: performanceimage: node:${NODE_VERSION}timeout: 2h # Set a 2-hour timeoutscript:# Performance test script...Manuelle Ausloeser: Leistungstests manuell auslosen lassen:
performance_test:stage: performanceimage: node:${NODE_VERSION}script:# Performance test script...when: manual
Weitere Informationen finden Sie in der GitLab CI/CD-Dokumentation und der LoadFocus API Client-Dokumentation.