Skip to content

Conversation

@lvalentine6
Copy link
Member

@lvalentine6 lvalentine6 commented Aug 10, 2025

✨ 개요

  • [PRODUCT-223] [Feat] API 응답 시간 개선 #133 과 디스코드로 공유드린 api 응답 지연을 해결하기 위한 첫번째 작업입니다.
  • 원인이 파악되었음으로 해결을 위해 인스턴스를 스케일업 합니다.
  • 현재 무중단 배포가 필수 요구사항이 아니므로 네트워크 모드를 bridge에서 host 으로 변경합니다.
  • 스크립트 수정과 관련 권한을 업데이트 했습니다.

🧾 관련 이슈

#133

🔍 참고 사항 (선택)

Summary by CodeRabbit

  • 신규 기능

    • EC2에서 ECS로의 IAM 역할에 SSM 파라미터 접근 권한 정책이 추가되었습니다.
  • 버그 수정

    • 백업 로그 디렉토리 및 크론 작업 로그 경로가 /home/ec2-user/logs/backup으로 통일되어 권한 및 로그 관리가 개선되었습니다.
  • 기능 개선

    • 개발 및 운영 환경 EC2 인스턴스 타입이 더 높은 사양(t3a.small)으로 변경되었습니다.
    • ECS 태스크의 메모리 할당량이 증가하고 네트워크 모드가 "host"로 변경되어 성능 및 네트워크 연결성이 향상되었습니다.
    • Datadog 에이전트 및 API 서비스의 호스트 주소가 루프백(127.0.0.1)으로 변경되어 설정이 간소화되었습니다.
    • 운영 환경에서 API 컨테이너의 볼륨 경로 및 실행 파일 경로가 업데이트되었습니다.

- 컨테이너 네트워크 모드를 host 타입으로 변경
- 에이전트 컨테이너를 루프백 주소로 변경
@coderabbitai
Copy link

coderabbitai bot commented Aug 10, 2025

Walkthrough

이번 변경 사항은 개발 및 운영 환경의 Terraform 인프라 구성에 집중되어 있습니다. EC2 인스턴스 타입, ECS 태스크 정의의 메모리 및 네트워크 모드, 스크립트의 디렉터리 및 권한 설정, IAM 정책 추가, 컨테이너 명령어 및 로그 경로 등이 업데이트되었습니다. 주요 리소스의 성능 및 보안 관련 설정이 조정되었습니다.

Changes

Cohort / File(s) Change Summary
EC2 인스턴스 타입 및 로컬 변수 조정
terraform/dev/locals.tf, terraform/prod/locals.tf
개발 환경은 "t2.micro"에서 "t3a.small"로, 운영 환경은 "t3.micro"에서 "t3a.small"로 인스턴스 타입 변경.
ECS 태스크 정의 리소스 및 네트워크 모드 변경
terraform/dev/terraform.tfvars, terraform/prod/terraform.tfvars
api-dev/api-proddatadog 태스크의 메모리 증가, 네트워크 모드 "bridge"에서 "host"로 변경. 일부 볼륨 경로 및 환경 변수도 조정됨.
컨테이너 명령어 및 환경 변수 업데이트
terraform/dev/locals.tf, terraform/prod/ecs/locals.tf
Datadog 에이전트 호스트를 고정 IP에서 루프백(127.0.0.1)으로 변경, jar 경로 및 Java agent 경로 수정.
유저 데이터 스크립트 디렉터리 및 권한, 로그 경로 변경
terraform/dev/scripts/user-data.sh, terraform/prod/scripts/user-data.sh
로그 디렉터리 구조를 /home/ec2-user/logs/backup로 변경, 디렉터리 권한 재설정, 크론 로그 경로를 홈 디렉터리 하위로 이동.
IAM 인라인 정책 추가
terraform/common/locals.tf
ec2-to-ecs 역할에 SSM 파라미터(parameter/dev/MYSQL_URL) 접근을 허용하는 커스텀 인라인 정책 추가.

Sequence Diagram(s)

sequenceDiagram
    participant UserDataScript
    participant OS
    participant Cron

    UserDataScript->>OS: /home/ec2-user/logs/backup 디렉터리 생성
    UserDataScript->>OS: logs, mysql, scripts 디렉터리 권한 재설정
    UserDataScript->>Cron: 크론 작업 등록 (로그를 logs/backup 하위로 리디렉션)
Loading
sequenceDiagram
    participant Terraform
    participant AWS IAM
    participant EC2

    Terraform->>AWS IAM: ec2-to-ecs 역할에 ssm_mysql_url_access 인라인 정책 추가
    EC2->>AWS IAM: SSM 파라미터 dev/MYSQL_URL 접근 시도
    AWS IAM-->>EC2: 접근 허용
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–25 minutes

Poem

🐰
로그의 집을 넓혔지, 백업도 꼼꼼히~
인스턴스도 커졌고, 네트워크는 더 빠르게!
IAM 권한도 촘촘히, SSM 파라미터 지키네.
토끼는 오늘도 깡총깡총, 인프라 튜닝에 신이 났네!
🌱

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/latency

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

📄 Terraform Plan Summary

🛡️ Common Infrastructure

  + create
  + resource aws_iam_policy custom {
  + resource aws_iam_role_policy_attachment custom_policy_attachment {
Plan: 2 to add, 0 to change, 0 to destroy.

Status: 🔄 Changes Detected


🛠️ Development Environment

  ~ update in-place
  ~ resource aws_instance dev {
  ~ ecs_task_definitions_check = (sensitive value)
Plan: 3 to add, 1 to change, 3 to destroy.

Status: 🔄 Changes Detected


📋 Full Results: View in Actions

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0e722a and 718a692.

📒 Files selected for processing (8)
  • terraform/common/locals.tf (1 hunks)
  • terraform/dev/locals.tf (2 hunks)
  • terraform/dev/scripts/user-data.sh (2 hunks)
  • terraform/dev/terraform.tfvars (3 hunks)
  • terraform/prod/ecs/locals.tf (1 hunks)
  • terraform/prod/locals.tf (1 hunks)
  • terraform/prod/scripts/user-data.sh (2 hunks)
  • terraform/prod/terraform.tfvars (1 hunks)
🔇 Additional comments (14)
terraform/prod/locals.tf (1)

53-53: 인스턴스 스케일업 변경 승인

t3.micro에서 t3a.small로의 인스턴스 타입 변경이 API 응답 지연 문제 해결을 위한 PR 목표와 일치합니다. 성능 향상에 기여할 것으로 예상됩니다.

terraform/dev/locals.tf (2)

45-45: 인스턴스 스케일업 변경 승인

개발 환경에서도 인스턴스 타입이 t2.micro에서 t3a.small로 변경되어 프로덕션 환경과 일관성을 유지하며 성능 향상에 기여할 것입니다.


84-84: 네트워크 모드 변경에 맞춘 적절한 Datadog 에이전트 호스트 설정

Datadog 에이전트 호스트가 고정 IP에서 127.0.0.1로 변경되었습니다. 이는 ECS 태스크의 네트워크 모드가 "host"로 변경된 것과 일치하여 올바른 설정입니다.

terraform/prod/ecs/locals.tf (1)

78-91: 컨테이너 파일 경로 확인 완료: 경로 일치

  • Dockerfile에서 /dd-java-agent.jar/api.jar가 컨테이너 루트에 복사되는 것이 확인되었습니다.
  • Terraform의 -javaagent:/dd-java-agent.jar-jar /api.jar 명령과 완전히 일치합니다.
terraform/dev/scripts/user-data.sh (2)

10-14: 디렉토리 구조 및 권한 설정 개선 승인

로그 백업을 위한 중첩 디렉토리 구조 생성과 재귀적 소유권 설정이 추가되었습니다. 이는 로그 관리 개선과 적절한 파일 권한 보장에 도움이 됩니다.


32-33: 크론 작업 로그 경로 일관성 확보

크론 작업의 로그 출력 경로가 새로운 backup 서브디렉토리와 일치하도록 업데이트되었습니다. 로그 관리의 일관성을 향상시킵니다.

terraform/prod/terraform.tfvars (3)

21-22: 리소스 할당 및 네트워크 모드 변경 승인

API 컨테이너의 메모리가 256MB에서 1024MB로 4배 증가하고 네트워크 모드가 "host"로 변경되었습니다. 이는 API 응답 지연 해결을 위한 성능 개선 목표와 일치합니다.


30-30: 볼륨 경로 변경 확인

볼륨 호스트 경로가 /home/ec2-user/api에서 /home/ec2-user/logs/로 변경되었습니다. 이는 로그 중심의 디렉토리 구조로의 변경을 반영합니다.


38-40: Datadog 에이전트 리소스 및 네트워크 설정 개선

Datadog 에이전트의 메모리가 128MB에서 256MB로 증가하고 네트워크 모드가 "host"로 변경되었습니다. 이는 향상된 모니터링 성능과 host 네트워킹의 이점을 활용할 수 있게 합니다.

terraform/prod/scripts/user-data.sh (2)

10-13: 프로덕션 환경 디렉토리 구조 일관성 확보

개발 환경과 일치하는 로그 백업 디렉토리 구조와 재귀적 소유권 설정이 추가되었습니다. 환경 간 일관성과 적절한 권한 관리를 보장합니다.


28-28: 크론 작업 로그 경로 업데이트 승인

크론 작업 로그가 새로운 backup 서브디렉토리로 리디렉션되도록 업데이트되어 로그 관리 구조가 개선되었습니다.

terraform/dev/terraform.tfvars (3)

24-25: 개발 환경 API 컨테이너 리소스 및 네트워크 설정 승인

API 컨테이너의 메모리가 4배 증가(256MB → 1024MB)하고 네트워크 모드가 "host"로 변경되어 프로덕션 환경과 일관성을 유지하며 성능 개선을 달성합니다.


51-51: MySQL 컨테이너 네트워크 모드 변경 승인

MySQL 컨테이너의 네트워크 모드가 "host"로 변경되어 다른 서비스들과 일관된 네트워킹 구성을 제공합니다.


92-93: Datadog 에이전트 리소스 및 네트워크 설정 개선

Datadog 에이전트의 메모리가 2배 증가(128MB → 256MB)하고 네트워크 모드가 "host"로 변경되어 향상된 모니터링 성능과 호스트 네트워크 접근성을 제공합니다.

@lvalentine6 lvalentine6 changed the title [Refactor] 인스턴스 스케일업 및 동작 방식 변경 -1 [Refactor] API 지연 개선을 위한 인스턴스 스케일업 및 동작 방식 변경 -1 Aug 10, 2025
Copy link
Member

@leegwichan leegwichan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다! 인스턴스 증가 및 중단 배포로 전환 확인했습니다

@lvalentine6 lvalentine6 merged commit 33537e1 into develop Aug 11, 2025
12 checks passed
@lvalentine6 lvalentine6 deleted the refactor/latency branch August 11, 2025 11:23
@github-actions
Copy link

🎉 This PR is included in version 1.4.0-develop.72 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 1.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants