Skip to content

DEPLOY - v1.0.2#31

Merged
youyeon11 merged 6 commits intomainfrom
develop
Oct 2, 2025
Merged

DEPLOY - v1.0.2#31
youyeon11 merged 6 commits intomainfrom
develop

Conversation

@youyeon11
Copy link
Contributor

πŸ“Œ μž‘μ—… λͺ©μ 


πŸ—‚ μž‘μ—… μœ ν˜•

  • κΈ°λŠ₯ μΆ”κ°€ (Feature)
  • 버그 μˆ˜μ • (Bug Fix)
  • λ¦¬νŒ©ν„°λ§ (Refactor)
  • μ„±λŠ₯ κ°œμ„  (Performance)
  • ν…ŒμŠ€νŠΈ μΆ”κ°€/μˆ˜μ • (Test)
  • λΉŒλ“œ/배포/ν™˜κ²½ μ„€μ • (Chore)
  • λ¬Έμ„œ μˆ˜μ • (Docs)

πŸ”¨ μ£Όμš” μž‘μ—… λ‚΄μš©

  • λͺ¨λ‹ˆν„°λ§ ν™˜κ²½μ„ μΆ”κ°€ν•˜μ˜€μŠ΅λ‹ˆλ‹€

πŸ“Ž κ΄€λ ¨ 이슈


@gemini-code-assist
Copy link

Summary of Changes

Hello @youyeon11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— 포괄적인 λͺ¨λ‹ˆν„°λ§ κΈ°λŠ₯을 λ„μž…ν•˜μ—¬ Prometheus와 Grafanaλ₯Ό ν†΅ν•©ν•©λ‹ˆλ‹€. FastAPI μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ κ³„μΈ‘ν•˜μ—¬ μ„±λŠ₯ λ©”νŠΈλ¦­μ„ λ…ΈμΆœν•˜κ³ , 배포 ν”„λ‘œμ„ΈμŠ€λ₯Ό μ—…λ°μ΄νŠΈν•˜λ©°, λͺ¨λ‹ˆν„°λ§ μŠ€νƒμ— ν•„μš”ν•œ ꡬ성 νŒŒμΌμ„ μΆ”κ°€ν•©λ‹ˆλ‹€. μ΄λŠ” μ‹œμŠ€ν…œμ˜ κ°€μ‹œμ„±μ„ ν–₯μƒμ‹œν‚€κ³  잠재적인 문제λ₯Ό 사전에 κ°μ§€ν•˜λŠ” 데 도움이 될 κ²ƒμž…λ‹ˆλ‹€.

Highlights

  • λͺ¨λ‹ˆν„°λ§ ν™˜κ²½ μΆ”κ°€: μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— Prometheus와 Grafanaλ₯Ό ν¬ν•¨ν•œ 포괄적인 λͺ¨λ‹ˆν„°λ§ ν™˜κ²½μ΄ μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
  • FastAPI λ©”νŠΈλ¦­ 계츑: FastAPI μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— prometheus-fastapi-instrumentator 라이브러리λ₯Ό μ‚¬μš©ν•˜μ—¬ /actuator/prometheus μ—”λ“œν¬μΈνŠΈμ— λ©”νŠΈλ¦­μ„ λ…ΈμΆœν•˜λ„λ‘ κ³„μΈ‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
  • 배포 슀크립트 μ—…λ°μ΄νŠΈ: deploy.sh μŠ€ν¬λ¦½νŠΈκ°€ docker-compose.yml νŒŒμΌμ„ λͺ…μ‹œμ μœΌλ‘œ μ°Έμ‘°ν•˜λ„λ‘ μ—…λ°μ΄νŠΈλ˜μ–΄ μ»¨ν…Œμ΄λ„ˆ ν’€ 및 μž¬κ΅¬μΆ• ν”„λ‘œμ„ΈμŠ€μ˜ λͺ…확성을 λ†’μ˜€μŠ΅λ‹ˆλ‹€.
  • μƒˆλ‘œμš΄ λͺ¨λ‹ˆν„°λ§ ꡬ성 파일: Prometheus 및 Grafanaλ₯Ό μœ„ν•œ docker-compose.monitoring.yml, Prometheus κ²½κ³  κ·œμΉ™μ„ μœ„ν•œ prometheus-rule.yml, 그리고 Prometheus μ„œλ²„ ꡬ성을 μœ„ν•œ prometheus.yml 파일이 μƒˆλ‘œ μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
  • 쒅속성 μ—…λ°μ΄νŠΈ: requirements.txt νŒŒμΌμ— prometheus-client와 prometheus-fastapi-instrumentatorκ°€ μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/workflow.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with πŸ‘ and πŸ‘Ž on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@youyeon11
Copy link
Contributor Author

πŸ€– Gemini μ½”λ“œ 리뷰 κ²°κ³Ό

1) PR μ˜λ„ μš”μ•½

이번 PR은 μ‹œμŠ€ν…œμ˜ μ•ˆμ •μ„±κ³Ό κ΄€μΈ‘ κ°€λŠ₯μ„±(Observability)을 높이기 μœ„ν•΄ Prometheus와 Grafana 기반의 λͺ¨λ‹ˆν„°λ§ ν™˜κ²½μ„ λ„μž…ν•˜λŠ” 것을 λͺ©ν‘œλ‘œ ν•©λ‹ˆλ‹€. 이λ₯Ό μœ„ν•΄ FastAPI μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— λ©”νŠΈλ¦­ μˆ˜μ§‘ μ—”λ“œν¬μΈνŠΈλ₯Ό μΆ”κ°€ν•˜κ³ , λͺ¨λ‹ˆν„°λ§ μŠ€νƒμ„ Docker Compose둜 μ •μ˜ν•˜μ˜€μŠ΅λ‹ˆλ‹€. λ˜ν•œ, μΈμŠ€ν„΄μŠ€ λ‹€μš΄μ΄λ‚˜ API μ§€μ—°κ³Ό 같은 상황에 λŒ€ν•œ κ²½κ³ (Alert) κ·œμΉ™μ„ μ„€μ •ν•˜μ—¬ μž₯애에 μ‹ μ†ν•˜κ²Œ λŒ€μ‘ν•  수 μžˆλŠ” κΈ°λ°˜μ„ λ§ˆλ ¨ν–ˆμŠ΅λ‹ˆλ‹€.

2) μ „λ°˜μ  평가 (ν’ˆμ§ˆ/가독성/ν…ŒμŠ€νŠΈ/μ•„ν‚€ν…μ²˜)

  • μ»¨λ²€μ…˜: μ „λ°˜μ μœΌλ‘œ μ½”λ“œμ™€ μ„€μ • νŒŒμΌλ“€μ΄ 각 λ„κ΅¬μ˜ ν‘œμ€€ μ»¨λ²€μ…˜μ„ 잘 λ”°λ₯΄κ³  μžˆμŠ΅λ‹ˆλ‹€. Python μ½”λ“œλŠ” PEP8을 μ€€μˆ˜ν•˜λ©°, YAML 섀정도 ꡬ쑰적으둜 λͺ…ν™•ν•©λ‹ˆλ‹€.
  • 넀이밍/λͺ¨λ“ˆ 경계: docker-compose.monitoring.yml, prometheus.yml λ“± 파일λͺ…이 역할을 λͺ…ν™•ν•˜κ²Œ λ‚˜νƒ€λ‚΄μ–΄ μ΄ν•΄ν•˜κΈ° μ‰½μŠ΅λ‹ˆλ‹€. λͺ¨λ‹ˆν„°λ§κ³Ό μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 둜직의 뢄리도 잘 μ΄λ£¨μ–΄μ‘ŒμŠ΅λ‹ˆλ‹€.
  • μ˜μ‘΄μ„±: λͺ¨λ‹ˆν„°λ§μ„ μœ„ν•œ μ˜μ‘΄μ„±(prometheus-fastapi-instrumentator)이 requirements.txt에 λͺ…ν™•νžˆ μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
  • ν…ŒμŠ€νŠΈ μ „λž΅: 인프라 μ„€μ • 변경이 주된 λ‚΄μš©μ΄λ―€λ‘œ μžλ™ν™”λœ ν…ŒμŠ€νŠΈλŠ” μ—†μ§€λ§Œ, 배포 ν›„ μ‹€μ œ λͺ¨λ‹ˆν„°λ§ λŒ€μ‹œλ³΄λ“œ 및 μ•Œλ¦Ό κΈ°λŠ₯이 정상 λ™μž‘ν•˜λŠ”μ§€μ— λŒ€ν•œ μˆ˜λ™ 검증이 λ°˜λ“œμ‹œ ν•„μš”ν•©λ‹ˆλ‹€.

3) μš°μ„ μˆœμœ„λ³„ ν”Όλ“œλ°± λͺ©λ‘

[P2] ν•˜λ“œμ½”λ”©λœ 경둜λ₯Ό μ‚¬μš©ν•˜μ—¬ 이식성 및 μœ μ§€λ³΄μˆ˜μ„± μ €ν•˜

  • 파일/μœ„μΉ˜: deployment/docker-compose.monitoring.yml:6, deployment/docker-compose.monitoring.yml:23, .github/workflows/workflow.yml:48

  • κ·Όκ±°(μ™œ λ¬Έμ œμΈμ§€): docker-compose.monitoring.yml 파일 λ‚΄ λ³Όλ₯¨ κ²½λ‘œκ°€ /home/ubuntu/... 와 같이 μ ˆλŒ€ 경둜둜 ν•˜λ“œμ½”λ”©λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. μ΄λŠ” νŠΉμ • μ‚¬μš©μž(ubuntu)와 νŠΉμ • 디렉토리 ꡬ쑰(dearbelly)에 κ°•ν•˜κ²Œ μ˜μ‘΄ν•˜κ²Œ λ§Œλ“­λ‹ˆλ‹€. GitHub Actions μ›Œν¬ν”Œλ‘œμš°μ˜ target κ²½λ‘œλ„ λ§ˆμ°¬κ°€μ§€μž…λ‹ˆλ‹€.

  • 영ν–₯(버그/λ³΄μ•ˆ/μ„±λŠ₯/μœ μ§€λ³΄μˆ˜ λ“±):

    • μœ μ§€λ³΄μˆ˜μ„±: ν–₯ν›„ μ„œλ²„ ν™˜κ²½(예: μ‚¬μš©μž 이름 λ³€κ²½, ν”„λ‘œμ νŠΈ 경둜 λ³€κ²½)이 λ°”λ€” 경우, μ—¬λŸ¬ μ„€μ • νŒŒμΌμ„ μ°Ύμ•„ 직접 μˆ˜μ •ν•΄μ•Ό ν•˜λ―€λ‘œ 번거둭고 μ‹€μˆ˜λ₯Ό μœ λ°œν•˜κΈ° μ‰½μŠ΅λ‹ˆλ‹€.
    • 이식성: λ‹€λ₯Έ κ°œλ°œμžκ°€ 둜컬 ν™˜κ²½μ—μ„œ ν…ŒμŠ€νŠΈν•˜κ±°λ‚˜, λ‹€λ₯Έ μ„œλ²„μ— λ™μΌν•œ ꡬ성을 λ°°ν¬ν•˜κΈ° μ–΄λ ΅κ²Œ λ§Œλ“­λ‹ˆλ‹€.
  • μ œμ•ˆ(ꡬ체적 쑰치, λŒ€μ•ˆ, μ°Έκ³  λ§ν¬λŠ” 선택):

    1. Docker Named Volumes μ‚¬μš©: 데이터 μ €μž₯ λ³Όλ₯¨(prometheus/volume, grafana/volume)은 Dockerκ°€ κ΄€λ¦¬ν•˜λŠ” Named Volume으둜 λ³€κ²½ν•˜λŠ” 것을 적극 ꢌμž₯ν•©λ‹ˆλ‹€. μ΄λ ‡κ²Œ ν•˜λ©΄ 호슀트 경둜 μ˜μ‘΄μ„±μ΄ μ‚¬λΌμ§‘λ‹ˆλ‹€.
    2. μ„€μ • νŒŒμΌμ€ μƒλŒ€ 경둜 μ‚¬μš©: prometheus.ymlκ³Ό 같은 μ„€μ • νŒŒμΌμ€ docker-compose 파일 μœ„μΉ˜ κΈ°μ€€μœΌλ‘œ μƒλŒ€ 경둜λ₯Ό μ‚¬μš©ν•˜λ„λ‘ μˆ˜μ •ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.
    3. GitHub Actions κ²½λ‘œλŠ” Secret/Variable μ‚¬μš©: 배포 κ²½λ‘œλŠ” GitHub Actions의 Secretμ΄λ‚˜ Variable둜 κ΄€λ¦¬ν•˜λ©΄ μœ μ—°μ„±μ΄ 크게 ν–₯μƒλ©λ‹ˆλ‹€.

    μˆ˜μ • μ œμ•ˆ (docker-compose.monitoring.yml):

    services:
      prometheus:
        user: ${PROMETHEUS_USER}
        image: prom/prometheus:latest
        container_name: prometheus
        volumes:
    -     - /home/ubuntu/dearbelly/deployment/prometheus.yml:/etc/prometheus/prometheus.yml:ro
    -     - /home/ubuntu/prometheus/volume:/prometheus/data
    +     - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
    +     - prometheus-data:/prometheus/data
        ports:
          - 9090:9090
        # ... (μ΄ν•˜ μƒλž΅)
    
      grafana:
        user: ${GRAFANA_USER}
        image: grafana/grafana:latest
        container_name: grafana
        ports:
          - 3000:3000
        volumes:
    -     - /home/ubuntu/grafana/volume:/var/lib/grafana
    +     - grafana-data:/var/lib/grafana
        restart: always
        networks:
          - mynetwork
    
    networks:
      mynetwork:
        driver: bridge
    
    +volumes:
    +  prometheus-data:
    +  grafana-data:

[P2] λͺ¨λ‹ˆν„°λ§ μŠ€νƒ 배포 μžλ™ν™” λˆ„λ½

  • 파일/μœ„μΉ˜: deployment/deploy.sh

  • κ·Όκ±°(μ™œ λ¬Έμ œμΈμ§€): deploy.sh μŠ€ν¬λ¦½νŠΈλŠ” docker-compose.yml νŒŒμΌμ„ μ‚¬μš©ν•˜μ—¬ μ• ν”Œλ¦¬μΌ€μ΄μ…˜(app-blue/app-green)만 λ°°ν¬ν•˜λ„λ‘ κ΅¬μ„±λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. μƒˆλ‘œ μΆ”κ°€λœ docker-compose.monitoring.yml 파일의 μ„œλΉ„μŠ€(Prometheus, Grafana)λ₯Ό μ‹€ν–‰ν•˜λŠ” 둜직이 ν¬ν•¨λ˜μ–΄ μžˆμ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

  • 영ν–₯(버그/λ³΄μ•ˆ/μ„±λŠ₯/μœ μ§€λ³΄μˆ˜ λ“±):

    • 배포 λΆˆμ™„μ „μ„±: ν˜„μž¬ 배포 슀크립트λ₯Ό 싀행해도 λͺ¨λ‹ˆν„°λ§ ν™˜κ²½μ€ μ‹€ν–‰λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 맀번 μˆ˜λ™μœΌλ‘œ docker compose -f docker-compose.monitoring.yml up -d 와 같은 λͺ…령을 μ‹€ν–‰ν•΄μ•Ό ν•˜λ―€λ‘œ, 배포 과정이 번거둭고 μ‹€μˆ˜κ°€ λ°œμƒν•  수 μžˆμŠ΅λ‹ˆλ‹€.
  • μ œμ•ˆ(ꡬ체적 쑰치, λŒ€μ•ˆ, μ°Έκ³  λ§ν¬λŠ” 선택):
    배포 μŠ€ν¬λ¦½νŠΈκ°€ λͺ¨λ‹ˆν„°λ§ μŠ€νƒμ˜ 싀행도 μ±…μž„μ§€λ„λ‘ μˆ˜μ •ν•΄μ•Ό ν•©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, deploy.sh 상단에 λͺ¨λ‹ˆν„°λ§ μ„œλΉ„μŠ€λ₯Ό μ‹€ν–‰(λ˜λŠ” μ—…λ°μ΄νŠΈ)ν•˜λŠ” ꡬ문을 μΆ”κ°€ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

    μˆ˜μ • μ œμ•ˆ (deploy.sh):

    #!/bin/bash
    
    +echo "Starting monitoring services..."
    +docker compose -f docker-compose.monitoring.yml up -d
    +
     EXIST_BLUE=$(docker compose -f docker-compose.yml ps -q app-blue)
     # ... (μ΄ν•˜ κΈ°μ‘΄ 슀크립트)

    λ˜λŠ”, ν•˜λ‚˜μ˜ 슀크립트둜 μ—¬λŸ¬ compose νŒŒμΌμ„ κ΄€λ¦¬ν•˜λŠ” 것이 λ³΅μž‘ν•˜λ‹€λ©΄, λ³„λ„μ˜ deploy-monitoring.sh 슀크립트λ₯Ό λ§Œλ“€κ³  λ¬Έμ„œν™”ν•˜λŠ” 방법도 κ³ λ €ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

[P3] ν™˜κ²½ λ³€μˆ˜ 섀정에 λŒ€ν•œ μ„€λͺ… λΆ€μ‘±

  • 파일/μœ„μΉ˜: deployment/docker-compose.monitoring.yml:3, deployment/docker-compose.monitoring.yml:19, deployment/prometheus.yml:18 λ“±

  • κ·Όκ±°(μ™œ λ¬Έμ œμΈμ§€): docker-compose.monitoring.yml κ³Ό prometheus.ymlμ—μ„œ ${PROMETHEUS_USER}, ${GRAFANA_USER}, ${REMOTE_HOST} 와 같은 ν™˜κ²½ λ³€μˆ˜λ₯Ό μ‚¬μš©ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. ν•˜μ§€λ§Œ 이 λ³€μˆ˜λ“€μ΄ μ–΄λ””μ„œ μ–΄λ–»κ²Œ μ„€μ •λ˜μ–΄μ•Ό ν•˜λŠ”μ§€μ— λŒ€ν•œ μ„€λͺ…(예: .env 파일 ν•„μš”μ„±)이 PR λ³Έλ¬Έμ΄λ‚˜ μ½”λ“œ λ‚΄ 주석에 μ—†μŠ΅λ‹ˆλ‹€.

  • 영ν–₯(버그/λ³΄μ•ˆ/μ„±λŠ₯/μœ μ§€λ³΄μˆ˜ λ“±):

    • μ‹€ν–‰ 였λ₯˜: ν•΄λ‹Ή ν™˜κ²½ λ³€μˆ˜ 없이 μ‹€ν–‰ν•˜λ©΄ μ„œλΉ„μŠ€κ°€ κΆŒν•œ 문제둜 μ‹œμž‘μ— μ‹€νŒ¨ν•˜κ±°λ‚˜, ν”„λ‘œλ©”ν…Œμš°μŠ€κ°€ μ˜¬λ°”λ₯Έ λŒ€μƒμ„ μŠ€ν¬λž©ν•˜μ§€ λͺ»ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
    • ν˜‘μ—… λΉ„νš¨μœ¨: λ‹€λ₯Έ νŒ€μ›μ΄ 이 ν”„λ‘œμ νŠΈλ₯Ό μƒˆλ‘œ μ„€μ •ν•  λ•Œ, μ–΄λ–€ ν™˜κ²½ λ³€μˆ˜κ°€ ν•„μš”ν•œμ§€ λͺ°λΌ μ‹œκ°„μ„ λ‚­λΉ„ν•˜κ±°λ‚˜ 섀정에 μ‹€νŒ¨ν•  κ°€λŠ₯성이 λ†’μŠ΅λ‹ˆλ‹€.
  • μ œμ•ˆ(ꡬ체적 쑰치, λŒ€μ•ˆ, μ°Έκ³  λ§ν¬λŠ” 선택):
    ν”„λ‘œμ νŠΈ λ£¨νŠΈμ— .env.example νŒŒμΌμ„ μΆ”κ°€ν•˜μ—¬ ν•„μš”ν•œ ν™˜κ²½ λ³€μˆ˜ λͺ©λ‘κ³Ό κ·Έ 역할을 μ„€λͺ…ν•΄μ£Όμ„Έμš”. 이λ₯Ό 톡해 λ‹€λ₯Έ κ°œλ°œμžλ“€μ΄ μ†μ‰½κ²Œ 둜컬 ν™˜κ²½μ„ ꡬ성할 수 μžˆμŠ΅λ‹ˆλ‹€.

    .env.example 파일 μ˜ˆμ‹œ:

    # docker-compose.monitoring.yml: Prometheus & Grafana services user ID/group ID
    # Example: 1000:1000 or ubuntu user's id
    PROMETHEUS_USER=1000:1000
    GRAFANA_USER=472:472
    
    # prometheus.yml: Host IP for Prometheus to scrape itself and node-exporter
    REMOTE_HOST=127.0.0.1
    

[P3] API λ©”νŠΈλ¦­ μˆ˜μ§‘ μ£ΌκΈ° κ³Όλ‹€

  • 파일/μœ„μΉ˜: deployment/prometheus.yml:28, deployment/prometheus.yml:32

  • κ·Όκ±°(μ™œ λ¬Έμ œμΈμ§€): FastAPI μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ λ©”νŠΈλ¦­μ„ μˆ˜μ§‘ν•˜λŠ” scrape_interval이 1m(1λΆ„)으둜 μ„€μ •λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

  • 영ν–₯(버그/λ³΄μ•ˆ/μ„±λŠ₯/μœ μ§€λ³΄μˆ˜ λ“±):

    • μž₯μ•  감지 μ§€μ—°: νŠΈλž˜ν”½ κΈ‰μ¦μ΄λ‚˜ 응닡 μ‹œκ°„ μ§€μ—°κ³Ό 같은 μˆœκ°„μ μΈ λ¬Έμ œκ°€ λ°œμƒν–ˆμ„ λ•Œ, 이λ₯Ό κ°μ§€ν•˜λŠ” 데 μ΅œλŒ€ 1뢄이 μ†Œμš”λ  수 μžˆμŠ΅λ‹ˆλ‹€. μ΄λŠ” μž₯μ•  λŒ€μ‘μ˜ κ³¨λ“ νƒ€μž„μ„ λ†“μΉ˜κ²Œ ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
  • μ œμ•ˆ(ꡬ체적 쑰치, λŒ€μ•ˆ, μ°Έκ³  λ§ν¬λŠ” 선택):
    μ• ν”Œλ¦¬μΌ€μ΄μ…˜ λ©”νŠΈλ¦­ μˆ˜μ§‘ μ£ΌκΈ°λ₯Ό 일반적인 μˆ˜μ€€μΈ 15s λ˜λŠ” 30s둜 μ€„μ΄λŠ” 것을 μ œμ•ˆν•©λ‹ˆλ‹€. μ΄λ ‡κ²Œ ν•˜λ©΄ μ‹œμŠ€ν…œ μƒνƒœ λ³€ν™”λ₯Ό 더 λΉ λ₯΄κ²Œ νŒŒμ•…ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

    μˆ˜μ • μ œμ•ˆ (prometheus.yml):

    # ...
      - job_name: 'fastapi-actuator-blue'
        metrics_path: '/actuator/prometheus'
    -   scrape_interval: 1m
    +   scrape_interval: 15s
        static_configs:
          - targets: [ 'app-blue:8000' ]
      - job_name: 'fastapi-actuator-green'
        metrics_path: '/actuator/prometheus'
    -   scrape_interval: 1m
    +   scrape_interval: 15s
        static_configs:
          - targets: [ 'app-green:8001' ]

[P4] λΆˆν•„μš”ν•œ μ˜μ‘΄μ„± 포함

  • 파일/μœ„μΉ˜: requirements.txt:14

  • κ·Όκ±°(μ™œ λ¬Έμ œμΈμ§€): logging λΌμ΄λΈŒλŸ¬λ¦¬κ°€ requirements.txt에 ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. logging은 Python의 ν‘œμ€€ 라이브러리둜, λ³„λ„λ‘œ μ„€μΉ˜ν•  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.

  • 영ν–₯(버그/λ³΄μ•ˆ/μ„±λŠ₯/μœ μ§€λ³΄μˆ˜ λ“±):

    • 가독성/μœ μ§€λ³΄μˆ˜μ„±: pip μ„€μΉ˜ μ‹œ λ¬΄μ‹œλ˜λ―€λ‘œ κΈ°λŠ₯적 λ¬Έμ œλŠ” μ—†μ§€λ§Œ, λΆˆν•„μš”ν•œ ν•­λͺ©μ΄ ν¬ν•¨λ˜μ–΄ μžˆμ–΄ μ˜μ‘΄μ„± λͺ©λ‘μ„ ν˜Όλž€μŠ€λŸ½κ²Œ λ§Œλ“­λ‹ˆλ‹€.
  • μ œμ•ˆ(ꡬ체적 쑰치, λŒ€μ•ˆ, μ°Έκ³  λ§ν¬λŠ” 선택):
    requirements.txt νŒŒμΌμ—μ„œ logging 라인을 μ‚­μ œν•˜μ—¬ μ˜μ‘΄μ„± λͺ©λ‘μ„ κΉ”λ”ν•˜κ²Œ μœ μ§€ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

    μˆ˜μ • μ œμ•ˆ (requirements.txt):

    - logging
    prometheus-client==0.19.0
    prometheus-fastapi-instrumentator==6.1.0

[P5] λ©”νŠΈλ¦­ μ΄ˆκΈ°ν™” 둜직 뢄리 μ œμ•ˆ

  • 파일/μœ„μΉ˜: app/main.py:14-15

  • κ·Όκ±°(μ™œ λ¬Έμ œμΈμ§€): Prometheus Instrumentatorλ₯Ό μ΄ˆκΈ°ν™”ν•˜κ³  μ μš©ν•˜λŠ” μ½”λ“œκ°€ main.py의 μ΅œμƒμœ„ λ ˆλ²¨μ— 직접 μž‘μ„±λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

  • 영ν–₯(버그/λ³΄μ•ˆ/μ„±λŠ₯/μœ μ§€λ³΄μˆ˜ λ“±):

    • 가독성: ν˜„μž¬λŠ” μ½”λ“œκ°€ μ§§μ•„ λ¬Έμ œκ°€ μ—†μ§€λ§Œ, ν–₯ν›„ λ―Έλ“€μ›¨μ–΄λ‚˜ 이벀트 ν•Έλ“€λŸ¬ λ“± μ•± μ΄ˆκΈ°ν™” 둜직이 λ³΅μž‘ν•΄μ§€λ©΄ main.py 파일의 가독성이 λ–¨μ–΄μ§ˆ 수 μžˆμŠ΅λ‹ˆλ‹€.
  • μ œμ•ˆ(ꡬ체적 쑰치, λŒ€μ•ˆ, μ°Έκ³  λ§ν¬λŠ” 선택):
    μ•±μ˜ νŠΉμ • κΈ°λŠ₯을 μ„€μ •ν•˜λŠ” λ‘œμ§μ€ λ³„λ„μ˜ ν•¨μˆ˜λ‘œ λΆ„λ¦¬ν•˜λ©΄ ꡬ쑰가 더 λͺ…ν™•ν•΄μ§‘λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄ setup_monitoring 같은 ν•¨μˆ˜λ₯Ό λ§Œλ“€μ–΄ κ΄€λ¦¬ν•˜λŠ” 것을 κ³ λ €ν•΄λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€.

    μˆ˜μ • μ œμ•ˆ (app/main.py):

    from fastapi import FastAPI
    from app.core.lifespan import lifespan
    from app.api.endpoints import predictions
    from app.core.logging_config import setup_logging
    from prometheus_fastapi_instrumentator import Instrumentator
    
    def setup_monitoring(app: FastAPI):
        """Sets up the Prometheus instrumentator."""
        instrumentator = Instrumentator().instrument(app)
        instrumentator.expose(app, include_in_schema=False, endpoint="/actuator/prometheus")
    
    setup_logging()
    app = FastAPI(
        title="My App",
        description="FastAPI App",
        version="1.0.0",
        lifespan=lifespan
    )
    
    setup_monitoring(app)
    app.include_router(predictions.router, prefix="/api/v1", tags=["Prediction"])
    
    @app.get("/health")
    # ...

μ „λ°˜μ μœΌλ‘œ λͺ¨λ‹ˆν„°λ§ ν™˜κ²½μ„ λ„μž…ν•˜μ—¬ μ‹œμŠ€ν…œμ˜ μ•ˆμ •μ„±κ³Ό κ΄€μΈ‘ κ°€λŠ₯성을 크게 λ†’μ΄λŠ” μ€‘μš”ν•œ PR이라고 μƒκ°ν•©λ‹ˆλ‹€. λͺ‡ κ°€μ§€ μ œμ•ˆ 사항을 λ°˜μ˜ν•˜λ©΄ 더 κ²¬κ³ ν•˜κ³  μœ μ§€λ³΄μˆ˜ν•˜κΈ° 쒋은 ꡬ쑰가 될 것 κ°™μŠ΅λ‹ˆλ‹€. μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€! πŸ‘

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 Prometheus와 Grafanaλ₯Ό μ‚¬μš©ν•˜μ—¬ λͺ¨λ‹ˆν„°λ§ ν™˜κ²½μ„ μΆ”κ°€ν•˜λŠ” 것을 λͺ©ν‘œλ‘œ ν•©λ‹ˆλ‹€. FastAPI μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— λ©”νŠΈλ¦­ μ—”λ“œν¬μΈνŠΈλ₯Ό μΆ”κ°€ν•˜κ³ , λͺ¨λ‹ˆν„°λ§ μŠ€νƒμ„ μœ„ν•œ Docker Compose μ„€μ • 및 Prometheus μ„€μ • νŒŒμΌμ„ μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€. μ „λ°˜μ μœΌλ‘œ 쒋은 λ°©ν–₯μ΄μ§€λ§Œ, Docker λ„€νŠΈμ›Œν‚Ή μ„€μ • 였λ₯˜λ‘œ 인해 λͺ¨λ‹ˆν„°λ§μ΄ μ •μƒμ μœΌλ‘œ λ™μž‘ν•˜μ§€ μ•Šμ„ 수 있으며, Docker 이미지 νƒœκ·Έμ™€ λ³Όλ₯¨ 섀정에 κ°œμ„ μ΄ ν•„μš”ν•©λ‹ˆλ‹€. μ•„λž˜μ— μžμ„Έν•œ 리뷰 μ˜κ²¬μ„ λ‚¨κ²ΌμŠ΅λ‹ˆλ‹€.

Comment on lines +25 to +34
- job_name: 'fastapi-actuator-blue'
metrics_path: '/actuator/prometheus'
scrape_interval: 1m
static_configs:
- targets: [ 'app-blue:8000' ]
- job_name: 'fastapi-actuator-green'
metrics_path: '/actuator/prometheus'
scrape_interval: 1m
static_configs:
- targets: [ 'app-green:8001' ] No newline at end of file

Choose a reason for hiding this comment

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

critical

fastapi-actuator-blue와 fastapi-actuator-green job이 app-blue:8000, app-green:8001을 νƒ€κ²ŸμœΌλ‘œ ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. ν•˜μ§€λ§Œ docker-compose.monitoring.ymlκ³Ό docker-compose.yml이 λ³„λ„μ˜ 파일둜 κ΄€λ¦¬λ˜κ³  μžˆμ–΄, Prometheus μ»¨ν…Œμ΄λ„ˆμ™€ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ»¨ν…Œμ΄λ„ˆλ“€μ΄ μ„œλ‘œ λ‹€λ₯Έ Docker λ„€νŠΈμ›Œν¬μ— μ†ν•˜κ²Œ 될 κ°€λŠ₯성이 λ†’μŠ΅λ‹ˆλ‹€. 이 경우 Prometheusκ°€ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ λ©”νŠΈλ¦­μ„ μˆ˜μ§‘ν•  수 μ—†μŠ΅λ‹ˆλ‹€. λͺ¨λ“  μ»¨ν…Œμ΄λ„ˆκ°€ λ™μΌν•œ Docker λ„€νŠΈμ›Œν¬μ— μžˆλ„λ‘ docker-compose.ymlκ³Ό docker-compose.monitoring.yml의 λ„€νŠΈμ›Œν¬ 섀정을 λ§žμΆ°μ£Όμ–΄μ•Ό ν•©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, 곡톡 μ™ΈλΆ€ λ„€νŠΈμ›Œν¬(external network)λ₯Ό μ‚¬μš©ν•˜λ„λ‘ μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

services:
prometheus:
user: ${PROMETHEUS_USER}
image: prom/prometheus:latest

Choose a reason for hiding this comment

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

high

prom/prometheus:latest와 같이 :latest νƒœκ·Έλ₯Ό μ‚¬μš©ν•˜λŠ” 것은 ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œ 예기치 μ•Šμ€ 버전 λ³€κ²½μœΌλ‘œ μΈν•œ 문제λ₯Ό μΌμœΌν‚¬ 수 μžˆμŠ΅λ‹ˆλ‹€. μ•ˆμ •μ μΈ μš΄μ˜μ„ μœ„ν•΄ νŠΉμ • 버전(예: v2.51.2)을 λͺ…μ‹œν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

    image: prom/prometheus:v2.51.2


grafana:
user: ${GRAFANA_USER}
image: grafana/grafana:latest

Choose a reason for hiding this comment

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

high

grafana/grafana:latest와 같이 :latest νƒœκ·Έλ₯Ό μ‚¬μš©ν•˜λŠ” 것은 ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œ 예기치 μ•Šμ€ 버전 λ³€κ²½μœΌλ‘œ μΈν•œ 문제λ₯Ό μΌμœΌν‚¬ 수 μžˆμŠ΅λ‹ˆλ‹€. μ•ˆμ •μ μΈ μš΄μ˜μ„ μœ„ν•΄ νŠΉμ • 버전(예: 11.0.0)을 λͺ…μ‹œν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

    image: grafana/grafana:11.0.0

Comment on lines +22 to +24
- job_name: 'node'
static_configs:
- targets: ['${REMOTE_HOST}:9090']

Choose a reason for hiding this comment

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

high

node job의 targetsκ°€ Prometheus μžμ‹ μ„ κ°€λ¦¬ν‚€λŠ” '${REMOTE_HOST}:9090'으둜 μ„€μ •λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. nodeλΌλŠ” μ΄λ¦„μœΌλ‘œ 보아 Node Exporter λ©”νŠΈλ¦­μ„ μˆ˜μ§‘ν•˜λ €λŠ” μ˜λ„λ‘œ λ³΄μ΄μ§€λ§Œ, ν¬νŠΈκ°€ 잘λͺ»λ˜μ—ˆμŠ΅λ‹ˆλ‹€. Node ExporterλŠ” 보톡 9100 포트λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€. λ§Œμ•½ Node Exporterλ₯Ό μ‚¬μš©ν•˜μ§€ μ•ŠλŠ”λ‹€λ©΄ 이 job은 λΆˆν•„μš”ν•˜κ²Œ Prometheus λ©”νŠΈλ¦­μ„ 쀑볡 μˆ˜μ§‘ν•˜λ―€λ‘œ μ œκ±°ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

  - job_name: 'node'
    static_configs:
      - targets: ['${REMOTE_HOST}:9100']

Comment on lines +7 to +8
- /home/ubuntu/dearbelly/deployment/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- /home/ubuntu/prometheus/volume:/prometheus/data

Choose a reason for hiding this comment

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

medium

Prometheus λ³Όλ₯¨ κ²½λ‘œκ°€ /home/ubuntu/...와 같이 μ ˆλŒ€ 경둜둜 ν•˜λ“œμ½”λ”©λ˜μ–΄ μžˆμ–΄ λ‹€λ₯Έ ν™˜κ²½μ—μ„œμ˜ μž¬μ‚¬μš©μ„± 및 이식성이 λ–¨μ–΄μ§‘λ‹ˆλ‹€. μ„€μ • νŒŒμΌμ€ μƒλŒ€ 경둜 (./prometheus.yml)λ₯Ό μ‚¬μš©ν•˜κ³ , 데이터 λ³Όλ₯¨μ€ Docker의 named volume을 μ‚¬μš©ν•˜λŠ” 것을 ꢌμž₯ν•©λ‹ˆλ‹€. 파일 ν•˜λ‹¨μ— volumes μ„Ήμ…˜μ„ μΆ”κ°€ν•˜μ—¬ prometheus-data named volume을 μ •μ˜ν•΄μ•Ό ν•©λ‹ˆλ‹€.

      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-data:/prometheus/data

ports:
- 3000:3000
volumes:
- /home/ubuntu/grafana/volume:/var/lib/grafana

Choose a reason for hiding this comment

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

medium

Grafana 데이터 λ³Όλ₯¨ κ²½λ‘œκ°€ /home/ubuntu/grafana/volume와 같이 μ ˆλŒ€ 경둜둜 ν•˜λ“œμ½”λ”©λ˜μ–΄ μžˆμ–΄ 이식성이 λ–¨μ–΄μ§‘λ‹ˆλ‹€. Docker의 named volume을 μ‚¬μš©ν•˜μ—¬ κ΄€λ¦¬ν•˜λŠ” 것을 ꢌμž₯ν•©λ‹ˆλ‹€. 파일 ν•˜λ‹¨μ— volumes μ„Ήμ…˜μ„ μΆ”κ°€ν•˜μ—¬ grafana-data named volume을 μ •μ˜ν•΄μ•Ό ν•©λ‹ˆλ‹€.

      - grafana-data:/var/lib/grafana

@youyeon11 youyeon11 merged commit 797f3b9 into main Oct 2, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant