과팅 연결 부하테스트 - #305
Conversation
📝 WalkthroughWalkthroughWebSocket 설정에 origins 기반의 새로운 엔드포인트가 추가되었고, K6 로드 테스트 환경(Dockerfile, docker-compose, 테스트 스크립트)이 추가되었습니다. .gitignore, build.gradle, 애플리케이션 설정 파일에 소소한 변경이 이루어졌습니다. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@build.gradle`:
- Around line 73-75: The build currently declares H2 as developmentOnly
('developmentOnly' dependency for com.h2database:h2) while the comment says it
should be runtimeOnly for k6 tests and there's no handling of the -PincludeH2
flag; update build.gradle to ensure H2 is available for containerized k6 tests
by either changing the H2 dependency scope from developmentOnly to runtimeOnly
for com.h2database:h2, or add conditional logic that checks
project.hasProperty('includeH2') (or the -PincludeH2 flag) and registers the H2
dependency as runtimeOnly only when that flag is provided so k6 test containers
get H2 on the classpath.
🧹 Nitpick comments (7)
src/main/resources/application-local.yml (1)
199-200: 로컬 프로필에서 앱체크 전체 경로 무시 — 의도 확인 필요
ignore-path를/**로 설정하면 로컬 환경에서 모든 경로의 앱체크가 비활성화됩니다. 부하 테스트를 위한 변경이라면 이해되지만, 이 설정이main브랜치에 머지되면 로컬 개발 시 앱체크 관련 버그를 놓칠 수 있습니다. 테스트 완료 후 원래 값(/ws/**등)으로 복원하는 것을 권장합니다.src/main/java/com/dongsoop/dongsoop/common/config/WebSocketConfig.java (1)
36-46:/ws/chat과/ws/blinddate엔드포인트의 보안 설정 불일치
/ws/chat은setAllowedOriginPatterns("*")로 모든 오리진을 허용하지만,/ws/blinddate는 설정 파일의origins로 제한합니다. 의도된 차이라면 문제없지만,/ws/chat에도 동일한 오리진 제한을 적용하는 것이 보안상 바람직합니다.src/test/k6/blinddate_load_test/Dockerfile (2)
32-32: COPY 경로가 혼란스러움 — 절대 경로 사용 권장
../../build/build/libs/*.jar경로는 현재 WORKDIR(/app) 기준으로/build/build/libs/*.jar로 해석되어 동작하지만, 상대 경로가 직관적이지 않습니다.♻️ 절대 경로로 변경
-COPY --from=builder ../../build/build/libs/*.jar app.jar +COPY --from=builder /build/build/libs/*.jar app.jar
27-42: 컨테이너가 root 사용자로 실행됨Trivy 정적 분석에서도 지적된 것처럼, 컨테이너가 root로 실행됩니다. 테스트 전용 Dockerfile이지만, 비root 사용자로 실행하는 것이 좋은 습관입니다.
🛡️ 비root 사용자 추가
COPY --from=builder /build/build/libs/*.jar app.jar RUN apt-get update && \ apt-get install -y --no-install-recommends curl && \ rm -rf /var/lib/apt/lists/* +RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser +USER appuser + ENV JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"src/test/k6/blinddate_load_test/script.js (2)
10-11: 하드코딩된 시크릿 키 (Gitleaks 경고)
SECRET_KEY가 스크립트에 하드코딩되어 있습니다.application-local.yml에 있는 로컬 개발용 키와 동일하지만, 테스트 스크립트에도 중복 관리되면 키 변경 시 동기화가 누락될 수 있습니다. 환경 변수(__ENV.SECRET_KEY)로 주입하는 방식을 고려해 주세요.♻️ 환경 변수로 주입
-const SECRET_KEY = 'VGhpc0lzQVZlcnlMb25nU2VjcmV0S2V5Rm9yRG9uZ3Nvb3BMb2NhbERldmVsb3BtZW50VGVzdGluZ1B1cnBvc2VPbmx5MTIzNDU2'; +const SECRET_KEY = __ENV.SECRET_KEY || 'VGhpc0lzQVZlcnlMb25nU2VjcmV0S2V5Rm9yRG9uZ3Nvb3BMb2NhbERldmVsb3BtZW50VGVzdGluZ1B1cnBvc2VPbmx5MTIzNDU2';그런 다음
docker-compose.yml의 k6 서비스에서 환경 변수로 전달:environment: - SECRET_KEY=VGhpc0lz...
117-151: STOMP 메시지 핸들러에서CONNECTED와MESSAGE분기 로직 확인Line 119에서
msg.startsWith('CONNECTED')를 체크한 뒤 구독을 보내고, Line 126에서!msg.startsWith('MESSAGE')이면 리턴합니다.CONNECTED메시지를 받았을 때 구독 후 바로 리턴하지 않기 때문에,CONNECTED로 시작하는 메시지가 Line 126의 체크도 통과하여 불필요하게 body 파싱을 시도합니다. 기능상 문제는 없지만(catch에서 무시),else if또는 early return으로 명확히 분리하는 것이 좋습니다.♻️ early return 추가
socket.on('message', function (msg) { if (msg.startsWith('CONNECTED')) { socket.send(`SUBSCRIBE\nid:sub-0\ndestination:/user/queue/blinddate/join\n\n\0`); - + return; } if (!msg.startsWith('MESSAGE')) {src/test/k6/blinddate_load_test/docker-compose.yml (1)
1-1:version키는 Docker Compose v2에서 더 이상 사용되지 않음최신 Docker Compose에서는
version필드가 무시되며 경고가 출력됩니다. 제거해도 무방합니다.
|
|
||
| // k6 테스트 시 runtimeOnly로 | ||
| developmentOnly 'com.h2database:h2' |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check for includeH2 property and conditional logic in build.gradle
rg -n 'includeH2|developmentOnly.*h2|h2.*developmentOnly' build.gradle
# Also search for any gradle properties or initialization scripts
fd -name 'build.gradle*' -o -name 'gradle.properties' -o -name 'settings.gradle*' | head -20Repository: dongsooop/backend
Length of output: 351
🏁 Script executed:
#!/bin/bash
# Search for includeH2 and other H2 configurations in build.gradle
rg -i 'includeh2|h2|runtimeonly' build.gradle
# Check for gradle.properties
cat gradle.properties 2>/dev/null || echo "No gradle.properties found"
# Count lines in build.gradle to determine size
wc -l build.gradleRepository: dongsooop/backend
Length of output: 361
🏁 Script executed:
#!/bin/bash
# Read the entire build.gradle
cat -n build.gradle
# Also search for any other gradle files
find . -maxdepth 2 -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | head -10Repository: dongsooop/backend
Length of output: 3521
🏁 Script executed:
#!/bin/bash
# Read settings.gradle
cat settings.gradle
# Also search for any other gradle configuration
find . -maxdepth 2 -type f \( -name "*.gradle" -o -name "*.gradle.kts" -o -name "gradle.properties" \) 2>/dev/nullRepository: dongsooop/backend
Length of output: 123
H2 의존성 스코프와 주석 불일치
주석에는 "k6 테스트 시 runtimeOnly로"라고 되어 있지만, 실제 H2 의존성은 developmentOnly로 선언되어 있습니다. Spring Boot의 developmentOnly 스코프는 로컬 개발 환경에서만 포함되며, Dockerfile 빌드 시에는 제외됩니다. 따라서 k6 테스트 컨테이너에서 H2가 클래스패스에 없어 local 프로필(H2 datasource 사용) 실행이 실패할 수 있습니다.
현재 build.gradle에 -PincludeH2 플래그를 처리하는 조건부 로직이 없으므로, k6 테스트가 컨테이너 환경에서 실행될 경우 의존성 누락으로 인한 오류가 발생할 수 있습니다. H2 의존성 스코프를 runtimeOnly로 변경하거나, 조건부 로직을 추가하여 명시적으로 처리해야 합니다.
🤖 Prompt for AI Agents
In `@build.gradle` around lines 73 - 75, The build currently declares H2 as
developmentOnly ('developmentOnly' dependency for com.h2database:h2) while the
comment says it should be runtimeOnly for k6 tests and there's no handling of
the -PincludeH2 flag; update build.gradle to ensure H2 is available for
containerized k6 tests by either changing the H2 dependency scope from
developmentOnly to runtimeOnly for com.h2database:h2, or add conditional logic
that checks project.hasProperty('includeH2') (or the -PincludeH2 flag) and
registers the H2 dependency as runtimeOnly only when that flag is provided so k6
test containers get H2 on the classpath.
관련 이슈
Closes #이슈번호
🎯 배경
🔍 주요 내용
⌛️ 리뷰 소요 시간
5분
Summary by CodeRabbit
릴리스 노트
New Features
Tests
Chores