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:

  1. GitLab projenize gidin
  2. Settings > CI/CD > Variables bölümüne gidin
  3. 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
- deploy
variables:
NODE_VERSION: "16"
build:
stage: build
image: node:${NODE_VERSION}
script:
- npm install
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 week
test:
stage: test
image: node:${NODE_VERSION}
script:
- npm install
- npm test
performance_test:
stage: performance
image: 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.json
artifacts:
paths:
- performance_results.json
expire_in: 1 week
when: always
# Optional: Only run on specific branches
only:
- main
- develop
deploy:
stage: deploy
script:
- echo "Deploying application..."
only:
- main
# Only deploy if all previous stages succeeded
when: on_success

3. Test Sonuçlarını Görüntüleyin

Pipeline çalıştıktan sonra:

  1. GitLab projenize gidin
  2. CI/CD > Pipelines bölümüne gidin
  3. Pipeline'ınızı bulun ve üzerine tıklayın
  4. "performance_test" işine gidin
  5. Yapay eserleri görüntülemek için sağ kenar çubuğundaki "Browse" düğmesine tıklayın
  6. performance_results.json dosyası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_definition
stage: performance
image: 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.json
artifacts:
paths:
- performance_results.json
expire_in: 1 week
when: always
performance_test_develop:
<<: *performance_test_definition
variables:
TEST_NAME: "API_Test_Develop"
THRESHOLDS: "avgresponse<=300,errors==0,p95<=500"
only:
- develop
performance_test_staging:
<<: *performance_test_definition
variables:
TEST_NAME: "API_Test_Staging"
THRESHOLDS: "avgresponse<=250,errors==0,p95<=350"
only:
- staging
performance_test_production:
<<: *performance_test_definition
variables:
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: performance
image: 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.json
artifacts:
paths:
- api_performance_results.json
expire_in: 1 week
performance_test_ui:
stage: performance
image: 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.json
artifacts:
paths:
- ui_performance_results.json
expire_in: 1 week

GitLab CI/CD Entegrasyonu İçin İpuçları

  1. Önbellek: Pipeline çalışmalarını hızlandırmak için npm bağımlılıklarını önbelleğe alın.

  2. Zaman Aşımı Ayarları: Uzun süreli performans testleri için zaman aşımlarını ayarlayın.

  3. Manuel Tetikleyiciler: Performans testlerinin manuel olarak tetiklenmesine izin verin.

  4. Dinamik Test Yapılandırması: Testleri dinamik olarak yapılandırmak için GitLab önceden tanımlı değişkenlerini kullanın.

  5. 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.