GitLab CI/CD
이 가이드에서는 자동화된 성능 테스트를 위해 LoadFocus JMeter API Client를 GitLab CI/CD와 통합하는 방법을 설명합니다.
설정 단계
1. GitLab CI/CD 변수로 자격 증명 저장
먼저 LoadFocus API 자격 증명을 GitLab CI/CD 변수로 저장합니다:
- GitLab 프로젝트로 이동합니다
- Settings > CI/CD > Variables로 이동합니다
- 다음 변수를 추가합니다:
LOADFOCUS_API_KEY: LoadFocus API 키 ("Masked"로 표시)LOADFOCUS_TEAM_ID: LoadFocus 팀 ID
2. GitLab CI/CD 파이프라인 생성
리포지토리에 .gitlab-ci.yml 파일을 생성하거나 업데이트합니다:
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:# LoadFocus JMeter API Client 설치- npm install -g @loadfocus/loadfocus-api-client# 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 "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# 선택 사항: 특정 브랜치에서만 실행only:- main- developdeploy:stage: deployscript:- echo "Deploying application..."only:- main# 모든 이전 스테이지가 성공한 경우에만 배포when: on_success
3. 테스트 결과 보기
파이프라인이 실행된 후:
- GitLab 프로젝트로 이동합니다
- CI/CD > Pipelines로 이동합니다
- 파이프라인을 찾아 클릭합니다
- "performance_test" 작업으로 이동합니다
- 오른쪽 사이드바의 "Browse"를 클릭하여 아티팩트를 확인합니다
performance_results.json파일을 다운로드하여 확인합니다
고급 구성
환경별 테스트
환경에 따라 다른 성능 테스트를 실행합니다:
.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
병렬 테스트
여러 성능 테스트를 병렬로 실행합니다:
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에서 파이프라인 스케줄을 생성합니다:
- GitLab 프로젝트로 이동합니다
- CI/CD > Schedules로 이동합니다
- "New schedule"을 클릭합니다
- 스케줄을 설정합니다 (예: 매일 자정)
성능 보고서 생성
JSON 결과에서 HTML 보고서를 생성합니다:
performance_test: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 "GitLab_${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json# HTML 보고서 생성- npm install -g performance-report-generator # 실제 보고서 생성기로 교체- performance-report-generator --input performance_results.json --output performance_report.htmlartifacts:paths:- performance_results.json- performance_report.htmlexpire_in: 1 weekwhen: always# 선택 사항: GitLab Pages로 보고서 게시pages:stage: deploydependencies:- performance_testscript:- mkdir -p public/performance-reports- cp performance_report.html public/performance-reports/index.htmlartifacts:paths:- publiconly:- main
GitLab 기능과의 통합
Merge Request 위젯
GitLab의 JUnit 보고서 기능을 사용하여 Merge Request에 성능 테스트 결과를 표시합니다:
performance_test: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 "GitLab_${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json# JUnit 형식으로 변환 (커스텀 스크립트 사용)- node convert-to-junit.js performance_results.json junit-report.xmlartifacts:reports:junit: junit-report.xmlpaths:- performance_results.jsonexpire_in: 1 week
GitLab 메트릭
GitLab의 메트릭 기능을 사용하여 시간에 따른 성능을 추적합니다:
performance_test: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 "GitLab_${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json# 메트릭을 추출하여 GitLab에 보고- |# JSON을 파싱하여 메트릭 추출RESPONSE_TIME=$(jq '.labels[0].metrics.avgresponse' performance_results.json)ERROR_RATE=$(jq '.labels[0].metrics.errors' performance_results.json)# 메트릭 보고echo "performance_avg_response_time ${RESPONSE_TIME}" >> metrics.txtecho "performance_error_rate ${ERROR_RATE}" >> metrics.txtartifacts:reports:metrics: metrics.txtpaths:- performance_results.jsonexpire_in: 1 week
GitLab 환경
성능 테스트를 특정 환경과 연결합니다:
performance_test_staging:stage: performanceimage: node:${NODE_VERSION}environment:name: stagingscript:- 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 "Staging_Performance_Test" \--thresholds "avgresponse<=250,errors==0" \--format json > performance_results.jsonartifacts:paths:- performance_results.jsonexpire_in: 1 weekonly:- staging
GitLab CI/CD 통합 팁
캐싱: npm 종속성을 캐싱하여 파이프라인 실행 속도를 높입니다:
performance_test:stage: performanceimage: node:${NODE_VERSION}cache:key: ${CI_COMMIT_REF_SLUG}paths:- node_modules/script:- npm install -g @loadfocus/loadfocus-api-client# 나머지 스크립트...타임아웃 설정: 오래 실행되는 성능 테스트에 대한 타임아웃을 설정합니다:
performance_test:stage: performanceimage: node:${NODE_VERSION}timeout: 2h # 2시간 타임아웃 설정script:# 성능 테스트 스크립트...수동 트리거: 성능 테스트를 수동으로 트리거할 수 있도록 합니다:
performance_test:stage: performanceimage: node:${NODE_VERSION}script:# 성능 테스트 스크립트...when: manual동적 테스트 구성: GitLab 사전 정의 변수를 사용하여 테스트를 동적으로 구성합니다:
performance_test:stage: performanceimage: node:${NODE_VERSION}script:- |# 브랜치에 따라 임계값 설정if [ "$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알림: 성능 테스트가 실패할 때 알림을 보냅니다:
performance_test:stage: performanceimage: node:${NODE_VERSION}script:# 성능 테스트 스크립트...after_script:- |if [ $? -ne 0 ]; then# curl, GitLab API 또는 기타 방법을 사용하여 알림 전송curl -X POST -H "Content-Type: application/json" \-d "{\"text\":\"${CI_PROJECT_NAME}의 성능 테스트가 실패했습니다\"}" \$WEBHOOK_URLfi
자세한 내용은 GitLab CI/CD 문서와 LoadFocus API Client 문서를 참조하세요.