Skip to content

feat: Prometheus 스크랩 타겟을 EC2 프라이빗 IP로 변경#767

Merged
Hexeong merged 2 commits into
developfrom
feat/766-prometheus-target-private-ip
Jun 17, 2026
Merged

feat: Prometheus 스크랩 타겟을 EC2 프라이빗 IP로 변경#767
Hexeong merged 2 commits into
developfrom
feat/766-prometheus-target-private-ip

Conversation

@Hexeong

@Hexeong Hexeong commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

작업 내용

prod-cd.yml / dev-cd.yml의 Prometheus 타겟 파일 갱신 시 사용하는 app 서버 IP를 퍼블릭 IP(HOST / DEV_HOST 시크릿)에서 EC2 프라이빗 IP로 변경했습니다.

프라이빗 IP는 EC2 IMDS(Instance Metadata Service) 엔드포인트를 통해 조회합니다.

PRIVATE_IP=$(ssh -i deploy_key.pem -o StrictHostKeyChecking=no \
  "$USERNAME@$HOST" \
  "curl -sf http://169.254.169.254/latest/meta-data/local-ipv4")

작업 근거

기존 방식은 monitoring 서버와 app 서버가 동일 VPC에 있음에도 퍼블릭 IP를 Prometheus 타겟으로 사용하고 있었습니다. 이 경우 Prometheus 스크랩 트래픽이 인터넷 게이트웨이를 경유하게 되어 아래 문제가 발생합니다.

  • 네트워크 비용: AWS는 인터넷 게이트웨이를 통한 아웃바운드 트래픽에 데이터 전송 비용을 부과합니다. Prometheus는 기본 15~30초 주기로 스크랩하므로 장기적으로 불필요한 비용이 누적됩니다.
  • 성능: 외부망을 경유하면 VPC 백본 네트워크 직접 통신 대비 레이턴시가 높아지고, 인터넷 게이트웨이를 통한 라우팅 경로가 추가됩니다.

프라이빗 IP를 사용하면 트래픽이 VPC 내부에서만 통신하므로 두 문제 모두 해결됩니다.

특이 사항

IMDS 주소(169.254.169.254) 하드코딩에 대해

169.254.x.x는 link-local 주소 대역으로 인터넷 라우팅이 불가능하며, EC2 인스턴스 내부에서만 접근할 수 있습니다. 또한 모든 EC2 인스턴스에 동일하게 적용되는 AWS 공식 문서 공개 엔드포인트이므로, 코드에 노출되어도 특정 인프라 정보가 드러나지 않아 보안상 문제없습니다.

조회 경로를 /latest/meta-data/local-ipv4로 한정하므로 반환값은 프라이빗 IP뿐이며, IAM 자격증명 등 민감 정보와는 무관합니다.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Hexeong, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 47 minutes and 22 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2b6d99a3-637c-4e8c-8460-67935fb7fe88

📥 Commits

Reviewing files that changed from the base of the PR and between 6729f22 and 26cb49f.

📒 Files selected for processing (2)
  • .github/workflows/dev-cd.yml
  • .github/workflows/prod-cd.yml

워크스루

이번 PR은 GitHub Actions CD 워크플로우 두 곳에서 Prometheus 스크랩 타겟 설정 방식을 변경했습니다.

  1. dev-cd.yml — stage 환경 스크랩 타겟 변경

    • 기존에는 secrets.DEV_HOST를 직접 사용했습니다.
    • 변경 후에는 원격 서버에서 169.254.169.254 메타데이터 API를 호출해 PRIVATE_IP를 조회합니다.
    • stage.jsontargets 값을 ${PRIVATE_IP}:${NEW_MGMT_PORT} 형태로 기록합니다.
    • 완료 로그도 동일한 값으로 출력됩니다.
  2. prod-cd.yml — prod 환경 스크랩 타겟 변경

    • 기존에는 secrets.HOST를 하드코딩하여 사용했습니다.
    • 변경 후에는 메타데이터 API로 PRIVATE_IP를 동적으로 조회합니다.
    • prod.jsontargets 값을 ${PRIVATE_IP}:${NEW_MGMT_PORT} 형태로 기록합니다.
    • 성공 로그 출력도 동일한 방식으로 통일되었습니다.

예상 코드 리뷰 노력

🎯 2 (Simple) | ⏱️ ~5 minutes

제안 리뷰어

  • wibaek
  • JAEHEE25
  • lsy1307
  • sukangpunch
  • Gyuhyeok99
  • whqtker
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 주요 변경사항(EC2 프라이빗 IP를 사용하도록 Prometheus 스크랩 타겟 변경)을 정확하고 명확하게 설명하고 있습니다.
Linked Issues check ✅ Passed 두 워크플로우 파일 변경사항이 이슈 #766의 요구사항(prod-cd.yml, dev-cd.yml의 EC2 메타데이터 기반 프라이빗 IP 조회 구현)을 모두 충족하고 있습니다.
Out of Scope Changes check ✅ Passed PR의 모든 변경사항이 이슈 #766 범위 내에 있으며, 보안 그룹 변경(인프라 레포 별도 작업)은 설명된 후속 작업으로 명확히 구분되어 있습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed PR 설명이 템플릿의 모든 필수 섹션을 포함하고 있으며, 작업 내용, 근거, 특이사항이 상세하게 기술되어 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/766-prometheus-target-private-ip

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6729f22193

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .github/workflows/prod-cd.yml Outdated
@Hexeong Hexeong self-assigned this Jun 17, 2026
@Hexeong Hexeong added 인프라 진행 중 자유롭게 merge 가능 labels Jun 17, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/dev-cd.yml:
- Around line 197-205: The PRIVATE_IP variable assignment on lines 197-200 lacks
error handling, so if the ssh/curl command fails or returns empty, the
subsequent Prometheus target update on lines 203-205 will still execute with an
invalid or empty PRIVATE_IP value, creating malformed targets in stage.json. Add
a validation check after the PRIVATE_IP assignment to ensure the variable is not
empty, and only proceed with the Prometheus target update command if PRIVATE_IP
contains a valid value. If PRIVATE_IP is empty or invalid, the workflow should
fail fast to prevent corrupted monitoring configuration.

In @.github/workflows/prod-cd.yml:
- Around line 208-216: The workflow retrieves PRIVATE_IP from the IMDS endpoint
but does not validate that the value was successfully obtained before using it
to update the Prometheus target configuration in prod.json. Add validation after
the IMDS curl command to check that PRIVATE_IP is not empty, and fail the
workflow with an appropriate error message if the IMDS query fails or returns an
empty value. The ssh command that updates prod.json should only execute after
successful PRIVATE_IP validation to prevent saving invalid monitoring targets in
the production environment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2d4f85eb-5c49-4263-9c51-3f36b4056cf8

📥 Commits

Reviewing files that changed from the base of the PR and between 8977b28 and 6729f22.

📒 Files selected for processing (2)
  • .github/workflows/dev-cd.yml
  • .github/workflows/prod-cd.yml

Comment thread .github/workflows/dev-cd.yml
Comment thread .github/workflows/prod-cd.yml

@lsy1307 lsy1307 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

수고하셨습니다! 보안그룹 설정은 변경안해도 되는지 궁금하네요..?

@Hexeong

Hexeong commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

수고하셨습니다! 보안그룹 설정은 변경안해도 되는지 궁금하네요..?

해당 인바운드 규칙은 기존에 이미 보안그룹을 대상으로 동작하기에 변경 없이도 동작합니다!

@Hexeong Hexeong merged commit c3e9521 into develop Jun 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

인프라 진행 중 자유롭게 merge 가능

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Prometheus 스크랩 타겟을 EC2 프라이빗 IP로 변경

2 participants