GitLab CI/CD
Bu kılavuz, otomatik performans testi için LoadFocus JMeter API Client'ı GitLab CI/CD ile nasıl entegre edeceğinizi açıklar.
Kurulum Adımları
1. Kimlik Bilgilerini GitLab CI/CD Değişkenleri Olarak Saklayın
Öncelikle LoadFocus API kimlik bilgilerinizi GitLab CI/CD değişkenleri olarak saklayın:
- GitLab projenize gidin
- Settings > CI/CD > Variables bölümüne gidin
- Aşağıdaki değişkenleri ekleyin:
LOADFOCUS_API_KEY: LoadFocus API anahtarınız ("Masked" olarak işaretleyin)LOADFOCUS_TEAM_ID: LoadFocus takım kimliğiniz
2. GitLab CI/CD Pipeline Oluşturun
Deponuzda .gitlab-ci.yml dosyasını oluşturun veya güncelleyin:
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. Test Sonuçlarını Görüntüleyin
Pipeline çalıştıktan sonra:
- GitLab projenize gidin
- CI/CD > Pipelines bölümüne gidin
- Pipeline'ınızı bulun ve üzerine tıklayın
- "performance_test" işine gidin
- Yapay eserleri görüntülemek için sağ kenar çubuğundaki "Browse" düğmesine tıklayın
performance_results.jsondosyasını indirin ve görüntüleyin
Gelişmiş Yapılandırma
Ortama Özel Test
Farklı ortamlar için farklı performans testleri çalıştırın:
.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
Paralel Test
Birden fazla performans testini paralel olarak çalıştırın:
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
GitLab CI/CD Entegrasyonu İçin İpuçları
Önbellek: Pipeline çalışmalarını hızlandırmak için npm bağımlılıklarını önbelleğe alın.
Zaman Aşımı Ayarları: Uzun süreli performans testleri için zaman aşımlarını ayarlayın.
Manuel Tetikleyiciler: Performans testlerinin manuel olarak tetiklenmesine izin verin.
Dinamik Test Yapılandırması: Testleri dinamik olarak yapılandırmak için GitLab önceden tanımlı değişkenlerini kullanın.
Bildirimler: Performans testleri başarısız olduğunda bildirimler gönderin.
Daha fazla bilgi için GitLab CI/CD dokümantasyonuna ve LoadFocus API Client dokümantasyonuna başvurun.