Skip to content

Conversation

@hyh1016
Copy link
Collaborator

@hyh1016 hyh1016 commented Aug 20, 2025

📌 관련 이슈

#67

📝 작업 개요

metrics 확인할 수 있는 dashboard 추가

✅ 작업 사항

  • metrics 확인할 수 있는 dashboard 추가

💭 고민한 점들(필수 X)

JVM 프로그램의 기본적인 요소들을 포함한 대시보드에 HTTP 웹서버 애플리케이션을 위한 일부 metrics 대시보드를 추가하여 만들었음.
loki는 후속 PR로..

Summary by CodeRabbit

  • 신기능

    • Prometheus + Grafana 모니터링 스택 추가로 애플리케이션 메트릭 시각화 지원
    • Grafana 기본 데이터소스/대시보드 자동 프로비저닝
    • Spring Actuator 메트릭 수집 및 일부 메트릭 필터링 적용
    • 메트릭에 application 태그 자동 포함
  • 작업(Chores)

    • 모니터링 배포용 GitHub Actions 워크플로 도입: 수동/메인 브랜치 트리거, 원격 서버로 아티팩트 업로드, Docker Compose pull/up 자동 실행
    • 시크릿을 활용한 Grafana 자격 증명 및 Prometheus 설정 경로 주입
    • 환경 변수(.env) 기본값 추가

@hyh1016 hyh1016 requested a review from pythonstrup August 20, 2025 15:08
@hyh1016 hyh1016 self-assigned this Aug 20, 2025
@hyh1016 hyh1016 added the enhancement New feature or request label Aug 20, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 20, 2025

Walkthrough

모니터링 스택(Prometheus·Grafana) 구성과 Spring 앱 메트릭 태그 추가가 도입되었고, 원격 서버에 Docker Compose로 스택을 배포하는 GitHub Actions 워크플로가 추가되었습니다. Grafana 데이터소스/대시보드 프로비저닝과 Prometheus 스크레이프 설정이 포함되며, 환경변수 파일과 docker-compose 설정이 신규로 추가되었습니다.

Changes

Cohort / File(s) Summary of Changes
CI/CD: Deploy Monitoring
.github/workflows/deploy-monitoring.yml
새 GitHub Actions 워크플로 추가: main/dispatch 트리거, 코드 체크아웃, monitoring/.env 생성(시크릿 주입), monitoring 디렉터리 원격 SCP 업로드, 원격에서 docker compose pull/up 실행.
Monitoring stack configs
monitoring/docker-compose.yml, monitoring/.env, monitoring/grafana/provisioning/..., monitoring/prometheus/*
Docker Compose로 Prometheus(9090)와 Grafana(3000) 서비스 정의. Grafana 프로비저닝: Prometheus 데이터소스, 파일 기반 대시보드 경로 설정. Prometheus 스크레이프: 자체(9090)와 Spring Actuator(/actuator/prometheus) 타깃 정의, 일부 메트릭 드롭 규칙 추가. 환경변수(Grafana 관리자, Prometheus 설정 경로) 도입.
Application metrics tag
src/main/resources/application.yml
관리 메트릭 태그에 application=${spring.application.name} 추가.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer
  participant GH as GitHub Actions<br/>(Deploy Monitoring)
  participant RS as Remote Server
  participant DC as Docker Compose

  Dev->>GH: Push to main / workflow_dispatch
  GH->>GH: Create monitoring/.env (from secrets)
  GH->>RS: SCP monitoring/ directory
  GH->>RS: SSH: mkdir -p deploy && cd deploy
  GH->>DC: SSH: docker compose pull
  GH->>DC: SSH: docker compose up -d
  DC-->>GH: Status logs
Loading
sequenceDiagram
  autonumber
  participant Prom as Prometheus
  participant App as Spring App
  participant Graf as Grafana

  Prom->>App: Scrape /actuator/prometheus (15s)
  Prom->>Prom: metric_relabel_configs apply (drop uri:/actuator.*, UNKNOWN)
  Graf->>Prom: Query metrics (proxy)
  Graf-->>Graf: Provision dashboards + datasource (on start)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

달빛 아래 깡충깡충, 배포 버튼 톡—
프로메는 긁고, 그라파나는 뽐뿌 쏙!
토끼는 귀 세워 로그를 훑지요.
대시보드 반짝, 지표는 졸졸—
오늘 밤도 안정! 모니터링 굿럭 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

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

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.
    • 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.
  • 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 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/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@hyh1016 hyh1016 requested review from pythonstrup and removed request for pythonstrup August 20, 2025 15:10
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: 2

🧹 Nitpick comments (14)
src/main/resources/application.yml (1)

33-35: 애플리케이션 공통 태그 추가 굿. 환경/인스턴스 태그도 함께 노출 권장

여러 인스턴스/환경을 동시에 모니터링할 때 필터링/그룹화가 좋아집니다. 아래처럼 instance, profile 태그를 추가하는 것을 권장합니다.

 management:
   metrics:
     tags:
       application: ${spring.application.name}
+      instance: ${HOSTNAME:unknown}
+      profile: ${spring.profiles.active:default}
monitoring/prometheus/prometheus.yml (1)

9-13: 타깃 app:8080 네트워크 해석 확인 필요
Prometheus 컨테이너가 동일 도커 네트워크에서 서비스명 app:8080을 DNS로 해석 가능해야 합니다. 모니터링 스택만 띄우는 경우 앱 컨테이너가 같은 네트워크에 없으면 스크레이프가 실패합니다. 운영/원격 환경에서 이 파일을 실제로 사용하는지(혹은 local용만 사용하는지)도 명확히 해두면 혼선이 줄어듭니다.

권장:

  • 운영에서 실제로 참조되는 설정만 남기거나, README에 각 파일의 용도를 명시
  • 앱 컨테이너를 같은 네트워크에 붙이거나, 리버스 프록시/게이트웨이 DNS를 사용하도록 타깃을 조정
monitoring/prometheus/prometheus.local.yml (1)

9-13: host.docker.internal 타깃은 Linux 서버에서 동작 보장되지 않음
Linux 환경의 Docker에서는 host.docker.internal이 기본 미해결일 수 있습니다. docker-compose에 extra_hosts로 host-gateway를 추가하거나, 앱을 같은 네트워크의 서비스명으로 스크레이프하는 구성을 고려해 주세요.

예) docker-compose.yml의 grafana/prometheus 서비스 하위에 다음 추가:

extra_hosts:
  - "host.docker.internal:host-gateway"

또는 앱 컨테이너를 같은 네트워크에 붙이고 타깃을 app:8080으로 통일.

monitoring/grafana/provisioning/dashboards/dashboards.yml (1)

1-11: EOF 개행 누락
YAML 린터 에러(new-line-at-end-of-file)를 해소하기 위해 파일 끝에 개행을 추가해 주세요.

-      path: /var/lib/grafana/dashboards
+      path: /var/lib/grafana/dashboards
+
monitoring/grafana/provisioning/datasources/datasources.yml (1)

3-8: Grafana 데이터소스 프로비저닝 구성은 적절합니다 (+ 편집 잠금 권장).

구성 자체는 바로 작동 가능해 보입니다. 운영에서 의도치 않은 변경을 막기 위해 editable: false를 추가하는 것을 권장합니다.

다음과 같이 보완 가능합니다:

 datasources:
   - name: Prometheus
     type: prometheus
     access: proxy
     url: http://prometheus:9090
     isDefault: true
+    editable: false
.github/workflows/deploy-monitoring.yml (4)

15-15: actions/checkout 버전 확인 및 고정 권장

actions/checkout@v5는 현재 사용 가능 여부가 불명확합니다. CI 실패를 피하려면 안정적인 메이저 버전으로 고정하세요(예: v4).

권장 수정:

-        uses: actions/checkout@v5
+        uses: actions/checkout@v4

27-31: SSH/SCP 인증 방식 중복 지정 제거 (password와 key 동시 사용)

password와 key를 동시에 전달하면 혼선/오류 가능성이 높습니다. 키 기반 1가지만 남기는 것을 권장합니다.

다음과 같이 password 제거를 제안합니다:

       - name: Upload Monitoring Files to Server
         uses: appleboy/scp-action@v1
         with:
           host: ${{ secrets.SERVER_HOST }}
           username: ${{ secrets.SERVER_USERNAME }}
-          password: ${{ secrets.SERVER_PASSWORD }}
           key: ${{ secrets.SSH_PRIVATE_KEY }}
           source: "monitoring/"
           target: "~/monitoring/"
           overwrite: true
           debug: true
       - name: Apply Docker Compose Configuration
         uses: appleboy/ssh-action@v1
         with:
           host: ${{ secrets.SERVER_HOST }}
           username: ${{ secrets.SERVER_USERNAME }}
-          password: ${{ secrets.SERVER_PASSWORD }}
           key: ${{ secrets.SSH_PRIVATE_KEY }}
           script: |
             DEPLOY_DIR=~/monitoring
             mkdir -p $DEPLOY_DIR
             cd $DEPLOY_DIR

Also applies to: 39-42


43-51: 원격 실행 스크립트에 실패 즉시 중단 및 구성 검증 추가 권장

배포 신뢰성을 위해 set -euo pipefail과 docker compose config -q 검증을 추가하세요.

           script: |
+            set -euo pipefail
             DEPLOY_DIR=~/monitoring
             mkdir -p $DEPLOY_DIR
             cd $DEPLOY_DIR

             echo "Applying docker-compose configuration for monitoring..."
+            docker compose config -q
             docker compose pull
             docker compose up -d
             echo "Monitoring services deployed successfully."

9-12: 중복 실행 방지를 위한 concurrency/권한 최소화 권장

main에 다수 커밋이 연속 푸시될 때 중복 배포를 방지하기 위해 concurrency를 추가하고, 워크플로 permissions를 최소화하세요.

 jobs:
   deploy-monitoring:
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
+    concurrency:
+      group: deploy-monitoring
+      cancel-in-progress: true
monitoring/docker-compose.yml (5)

3-3: 이미지 태그 latest 사용 지양 (재현성/안정성)

latest는 예기치 않은 업그레이드/깨짐을 유발할 수 있습니다. 구체 버전 태깅(또는 다이제스트 고정)을 권장합니다.

버전 선택이 정책에 따라 다르므로 여기서는 예시만 제안합니다: prom/prometheus:v2.x, grafana/grafana:10.x 등.

Also applies to: 16-16


7-11: Prometheus 데이터 영속성 및 보존 설정 추가 권장

현재 데이터 볼륨이 없어 컨테이너 재시작 시 시계열 데이터가 유실됩니다. 로컬 볼륨과 보존기간/저장경로를 명시하세요.

   prometheus:
     image: prom/prometheus:latest
     container_name: gamchi-prometheus
     ports:
       - "9090:9090"
     volumes:
-      - ${PROMETHEUS_CONFIG_FILE_PATH}:/etc/prometheus/prometheus.yml
+      - ${PROMETHEUS_CONFIG_FILE_PATH}:/etc/prometheus/prometheus.yml
+      - prometheus-data:/prometheus
     command:
-      - '--config.file=/etc/prometheus/prometheus.yml'
+      - '--config.file=/etc/prometheus/prometheus.yml'
+      - '--storage.tsdb.path=/prometheus'
+      - '--storage.tsdb.retention.time=15d'

파일 하단에 볼륨 선언 추가:

 networks:
   gamchi-network:
     driver: bridge
+
+volumes:
+  prometheus-data:
+  grafana-data:

20-26: Grafana 상태 영속화 및 프로비저닝 경로 정합성 점검

Grafana도 상태(DB)를 유지하려면 /var/lib/grafana를 볼륨으로 마운트하는 것이 좋습니다. 대시보드 폴더와 중첩 마운트가 되더라도 동작합니다.

   grafana:
     image: grafana/grafana:latest
     container_name: gamchi-grafana
     ports:
       - "3000:3000"
     volumes:
+      - grafana-data:/var/lib/grafana
       - ./grafana/provisioning:/etc/grafana/provisioning
       - ./grafana/dashboards:/var/lib/grafana/dashboards

비고: 대시보드 폴더는 프로비저닝(dashboards.yml의 options.path)과 일치해야 합니다. 현재 설정(/var/lib/grafana/dashboards)과 일관되면 OK입니다.


4-4: container_name 사용은 스케일링/이식성에 제약

container_name은 배포 환경마다 이름 충돌을 유발하거나 서비스 스케일링을 막을 수 있습니다. 특별한 이유가 없다면 제거를 권장합니다(서비스명 기반 DNS로 접근).

-    container_name: gamchi-prometheus
+    # container_name: gamchi-prometheus
-    container_name: gamchi-grafana
+    # container_name: gamchi-grafana

Also applies to: 17-17


12-13: 헬스체크 추가로 가시성과 복원력 향상

단순하지만 유용합니다. 컨테이너 상태 판단 및 오케스트레이션(재시작 등)에 도움됩니다.

     networks:
       - gamchi-network
     restart: unless-stopped
+    healthcheck:
+      test: ["CMD-SHELL", "wget -qO- localhost:9090/-/ready >/dev/null 2>&1"]
+      interval: 20s
+      timeout: 3s
+      retries: 3
     networks:
       - gamchi-network
     restart: unless-stopped
+    healthcheck:
+      test: ["CMD-SHELL", "wget -qO- localhost:3000/api/health | grep -q '\"database\":\"ok\"'"]
+      interval: 20s
+      timeout: 3s
+      retries: 5

Also applies to: 29-31

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 946b81d and 803c756.

📒 Files selected for processing (8)
  • .github/workflows/deploy-monitoring.yml (1 hunks)
  • monitoring/.env (1 hunks)
  • monitoring/docker-compose.yml (1 hunks)
  • monitoring/grafana/provisioning/dashboards/dashboards.yml (1 hunks)
  • monitoring/grafana/provisioning/datasources/datasources.yml (1 hunks)
  • monitoring/prometheus/prometheus.local.yml (1 hunks)
  • monitoring/prometheus/prometheus.yml (1 hunks)
  • src/main/resources/application.yml (1 hunks)
🧰 Additional context used
🪛 dotenv-linter (3.3.0)
monitoring/.env

[warning] 2-2: [UnorderedKey] The GRAFANA_ADMIN_PASSWORD key should go before the GRAFANA_ADMIN_USER key

(UnorderedKey)


[warning] 3-3: [EndingBlankLine] No blank line at the end of the file

(EndingBlankLine)

🪛 YAMLlint (1.37.1)
monitoring/grafana/provisioning/dashboards/dashboards.yml

[error] 11-11: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (2)
src/main/resources/application.yml (1)

33-35: 의존성 확인 완료: Actuator 및 Prometheus Registry 포함됨

  • build.gradle.kts 라인 97–98에서
    • org.springframework.boot:spring-boot-starter-actuator
    • io.micrometer:micrometer-registry-prometheus
    가 이미 implementation 의존성으로 선언되어 있습니다.

추가 작업 없이 메트릭 수집 준비가 완료되었습니다.

monitoring/grafana/provisioning/dashboards/dashboards.yml (1)

11-11: 볼륨 마운트 설정 확인됨

  • monitoring/docker-compose.yml:22
    - ./grafana/dashboards:/var/lib/grafana/dashboards 매핑이 존재하여 Grafana 컨테이너가 대시보드 디렉터리를 올바르게 마운트합니다.

따라서 별도 조치가 필요 없습니다.

@hyh1016 hyh1016 merged commit 8547cf1 into main Aug 21, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants