GitLab CI/CD
Ez az útmutató bemutatja, hogyan integrálhatja a LoadFocus JMeter API klienst a GitLab CI/CD-vel az automatizált teljesítményteszteléshez.
Beállítási lépések
1. Hitelesítő adatok tárolása GitLab CI/CD változókként
Először tárolja LoadFocus API hitelesítő adatait GitLab CI/CD változókként:
- Navigáljon a GitLab projektjéhez
- Lépjen a Settings > CI/CD > Variables menüpontba
- Adja hozzá a következő változókat:
LOADFOCUS_API_KEY: Az Ön LoadFocus API kulcsa (jelölje "Masked"-ként)LOADFOCUS_TEAM_ID: Az Ön LoadFocus csapat azonosítója
2. GitLab CI/CD Pipeline létrehozása
Hozza létre vagy frissítse a .gitlab-ci.yml fájlt a tárhelyén:
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. Teszteredmények megtekintése
A pipeline futtatása után:
- Navigáljon a GitLab projektjéhez
- Lépjen a CI/CD > Pipelines menüpontba
- Keresse meg a pipeline-ját és kattintson rá
- Navigáljon a "performance_test" feladathoz
- Kattintson az oldalsávon a "Browse" opcióra az artifaktumok megtekintéséhez
- Töltse le és tekintse meg a
performance_results.jsonfájlt
Haladó konfiguráció
Környezet-specifikus tesztelés
Különböző teljesítménytesztek futtatása különböző környezetekhez:
.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
Párhuzamos tesztelés
Több teljesítményteszt párhuzamos futtatása:
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
Tippek a GitLab CI/CD integrációhoz
Gyorsítótárazás: Gyorsítótárazza az npm függőségeket a pipeline futtatások felgyorsításához:
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...Időtúllépés beállítások: Állítson be időtúllépéseket a hosszan futó teljesítménytesztekhez:
performance_test:stage: performanceimage: node:${NODE_VERSION}timeout: 2h # Set a 2-hour timeoutscript:# Performance test script...Kézi indítás: Tegye lehetővé a teljesítménytesztek kézi indítását:
performance_test:stage: performanceimage: node:${NODE_VERSION}script:# Performance test script...when: manualDinamikus teszt konfiguráció: Használjon GitLab előre meghatározott változókat a tesztek dinamikus konfigurálásához:
performance_test:stage: performanceimage: node:${NODE_VERSION}script:- |# Set thresholds based on branchif [ "$CI_COMMIT_REF_NAME" = "main" ]; thenTHRESHOLDS="avgresponse<=200,errors==0,p95<=250"elseTHRESHOLDS="avgresponse<=300,errors==0,p95<=500"filoadfocus-api jmeter run-test \--name "GitLab_${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}" \--thresholds "$THRESHOLDS" \--format json > performance_results.jsonÉrtesítések: Küldjön értesítéseket, ha a teljesítménytesztek meghiúsulnak:
performance_test:stage: performanceimage: node:${NODE_VERSION}script:# Performance test script...after_script:- |if [ $? -ne 0 ]; thencurl -X POST -H "Content-Type: application/json" \-d "{\"text\":\"Performance test failed for ${CI_PROJECT_NAME}\"}" \$WEBHOOK_URLfi
További információkért tekintse meg a GitLab CI/CD dokumentációt és a LoadFocus API kliens dokumentációt.