CircleCI
이 가이드에서는 자동화된 성능 테스트를 위해 LoadFocus JMeter API Client를 CircleCI와 통합하는 방법을 설명합니다.
설정 단계
1. 환경 변수 추가
LoadFocus API 자격 증명을 CircleCI에 환경 변수로 저장합니다:
- CircleCI에서 프로젝트로 이동합니다
- Project Settings > Environment Variables로 이동합니다
- 다음 변수를 추가합니다:
LOADFOCUS_API_KEY: LoadFocus API 키LOADFOCUS_TEAM_ID: LoadFocus 팀 ID
2. CircleCI 워크플로 구성
성능 테스트를 포함하도록 .circleci/config.yml 파일을 생성하거나 업데이트합니다:
version: 2.1jobs:performance_test:docker:- image: cimg/node:16.13steps:- checkout- run:name: Install LoadFocus JMeter API Clientcommand: npm install -g @loadfocus/loadfocus-api-client- run:name: Configure LoadFocus API Clientcommand: |loadfocus-api config set apikey $LOADFOCUS_API_KEYloadfocus-api config set teamid $LOADFOCUS_TEAM_ID- run:name: Run Performance Testscommand: |loadfocus-api jmeter run-test \--name "CircleCI_${CIRCLE_PROJECT_REPONAME}_${CIRCLE_BRANCH}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json- store_artifacts:path: performance_results.jsondestination: performance-test-resultsworkflows:version: 2build_test_deploy:jobs:- build_and_test- performance_test:requires:- build_and_test- deploy:requires:- performance_testfilters:branches:only: main
3. 성능 문제 시 빌드 실패 처리
성능 임계값을 충족하지 못할 때 파이프라인을 실패시키려면 "Run Performance Tests" 단계를 수정합니다:
- run:name: Run Performance Testscommand: |loadfocus-api jmeter run-test \--name "CircleCI_${CIRCLE_PROJECT_REPONAME}_${CIRCLE_BRANCH}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json# Check exit code - the command will exit with code 1 if thresholds are not metif [ $? -ne 0 ]; thenecho "Performance test failed to meet thresholds"exit 1fi
고급 구성
병렬 테스트
여러 성능 테스트를 병렬로 실행하려면:
performance_tests:docker:- image: cimg/node:16.13parallelism: 3steps:- checkout- run:name: Install LoadFocus JMeter API Clientcommand: npm install -g @loadfocus/loadfocus-api-client- run:name: Configure LoadFocus API Clientcommand: |loadfocus-api config set apikey $LOADFOCUS_API_KEYloadfocus-api config set teamid $LOADFOCUS_TEAM_ID- run:name: Run Performance Testscommand: |# Get test name based on indexTESTS=("API_Test" "Frontend_Test" "Database_Test")INDEX=$(( $CIRCLE_NODE_INDEX % 3 ))TEST_NAME=${TESTS[$INDEX]}echo "Running test: $TEST_NAME"loadfocus-api jmeter run-test \--name "$TEST_NAME" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > "performance_results_${TEST_NAME}.json"- store_artifacts:path: performance_results_*.jsondestination: performance-test-results
CircleCI 통합 팁
Resource Allocation: Ensure your CircleCI plan has sufficient resources for running performance tests, especially if they're long-running.
Timeout Settings: For longer tests, adjust the job timeout in CircleCI:
- run:name: Run Performance Testscommand: loadfocus-api jmeter run-test --name "Test_Name" --waitTimeout 3600no_output_timeout: 60mConditional Testing: Only run performance tests on specific branches or for specific commits:
performance_test:# Only run if commit message contains [PERF-TEST]when:condition:or:- equal: [ main, << pipeline.git.branch >> ]- matches:pattern: ".*\\[PERF-TEST\\].*"value: << pipeline.git.commit.message >>Notifications: Set up notifications for performance test failures:
- run:name: Notify on Performance Test Failurecommand: |if [ $? -ne 0 ]; thencurl -X POST -H "Content-Type: application/json" \-d '{"text":"Performance test failed for $CIRCLE_PROJECT_REPONAME"}' \$SLACK_WEBHOOK_URLfiwhen: on_fail
자세한 내용은 CircleCI 문서와 LoadFocus API Client 문서를 참조하세요.