-
Notifications
You must be signed in to change notification settings - Fork 1
[#67] metrics 추가 #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#67] metrics 추가 #73
Conversation
Walkthrough모니터링 스택(Prometheus·Grafana) 구성과 Spring 앱 메트릭 태그 추가가 도입되었고, 원격 서버에 Docker Compose로 스택을 배포하는 GitHub Actions 워크플로가 추가되었습니다. Grafana 데이터소스/대시보드 프로비저닝과 Prometheus 스크레이프 설정이 포함되며, 환경변수 파일과 docker-compose 설정이 신규로 추가되었습니다. Changes
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
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)
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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_DIRAlso 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: truemonitoring/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-grafanaAlso 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: 3networks: - gamchi-network restart: unless-stopped + healthcheck: + test: ["CMD-SHELL", "wget -qO- localhost:3000/api/health | grep -q '\"database\":\"ok\"'"] + interval: 20s + timeout: 3s + retries: 5Also 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.
📒 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 컨테이너가 대시보드 디렉터리를 올바르게 마운트합니다.따라서 별도 조치가 필요 없습니다.
📌 관련 이슈
#67
📝 작업 개요
metrics 확인할 수 있는 dashboard 추가
✅ 작업 사항
💭 고민한 점들(필수 X)
JVM 프로그램의 기본적인 요소들을 포함한 대시보드에 HTTP 웹서버 애플리케이션을 위한 일부 metrics 대시보드를 추가하여 만들었음.
loki는 후속 PR로..
Summary by CodeRabbit
신기능
작업(Chores)