Skip to content

Conversation

@lvalentine6
Copy link
Member

@lvalentine6 lvalentine6 commented Dec 1, 2025

✨ 개요

  • 개발 서버에서 테스트한 기능을 프로덕션에 적용합니다.

🧾 관련 이슈

Close #195

🔍 참고 사항 (선택)

Summary by CodeRabbit

릴리스 노트

  • 새로운 기능

    • 월간 서버 리포트 자동 생성 및 Discord 알림 기능 추가
    • Datadog 기반 서버 모니터링 (CPU, 메모리 사용량)
    • 가용성 및 지연시간 Service Level Objective(SLO) 설정
    • 주요 지표 임계값 초과 시 자동 알림 기능
  • Chores

    • 모니터링 및 보고 인프라 구성

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 1, 2025

Walkthrough

GitHub Actions 워크플로우 및 Python 스크립트를 추가하여 월간 서버 리포트 자동화를 구현하고, Datadog 모니터링 설정을 Terraform으로 관리하는 인프라 코드를 도입했습니다.

Changes

Cohort / File(s) 변경 요약
GitHub Actions 워크플로우
.github/workflows/monthly-server-report.yml
매월 1일 자정에 실행되는 GitHub Actions 워크플로우 추가. Python 3.10 설정, 의존성 설치, 월간 리포트 스크립트 실행 및 시크릿 환경변수 주입
월간 리포트 스크립트
scripts/monthly-server-report.py
Datadog SLO 메트릭, AWS WAF 통계, AWS Cost Explorer 데이터를 수집하여 Korean 형식의 월간 리포트를 작성하고 Discord 웹훅으로 전송하는 Python 스크립트 추가
Terraform 공급자 및 백엔드
terraform/datadog/providers.tf, terraform/datadog/backend.tf
Terraform 공급자 설정 (AWS 6.23.0, Datadog 3.80) 및 S3 백엔드 상태 관리 구성
Terraform 로컬 변수 및 데이터
terraform/datadog/locals.tf
AWS SSM Parameter Store에서 Datadog 및 Discord 시크릿 파라미터 읽기, 알림 푸터 템플릿 정의
Datadog 통합 및 웹훅
terraform/datadog/integrations.tf
Discord 알림 채널용 Datadog 웹훅 3개 리소스 (경고, 경고, 복구) 추가
Datadog 모니터
terraform/datadog/monitors.tf
CPU 사용률, 메모리 사용률, 가용성 SLO, 지연시간 SLO 모니터 4개 추가
Datadog SLOs
terraform/datadog/slos.tf
지연시간 (P95 < 500ms) 및 가용성 (99%) 기반 2개 SLO 리소스 추가
Terraform 메타데이터
terraform/datadog/.terraform.lock.hcl, terraform/datadog/outputs.tf, terraform/datadog/variables.tf, terraform/datadog/terraform.tfvars
Terraform 락 파일, 출력, 변수, 값 파일 추가

Sequence Diagram

sequenceDiagram
    actor GitHub as GitHub Actions<br/>(Monthly Schedule)
    participant WF as monthly-server-report.yml
    participant Script as monthly-server-report.py
    participant DD as Datadog API
    participant AWS as AWS<br/>(CloudWatch/Cost Explorer)
    participant Discord as Discord Webhook

    GitHub->>WF: Trigger (1st of month)
    WF->>WF: Setup Python 3.10
    WF->>WF: Install dependencies
    WF->>Script: Execute with env vars
    
    Script->>DD: Fetch Availability SLO
    DD-->>Script: SLO value
    Script->>DD: Fetch Latency SLO
    DD-->>Script: SLO value
    Script->>DD: Count alert events
    DD-->>Script: Event count
    
    Script->>AWS: Query WAF metrics<br/>(CloudWatch)
    AWS-->>Script: Allowed/Blocked counts
    Script->>AWS: Query monthly cost<br/>(Cost Explorer)
    AWS-->>Script: Unblended cost
    
    Script->>Script: Compute deltas vs<br/>previous month
    Script->>Script: Format Korean report<br/>(Datadog/WAF/Cost sections)
    
    Script->>Discord: POST webhook payload
    Discord-->>Script: Success/Failure response
    Script->>Script: Log result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • 세부 검토 영역:
    • scripts/monthly-server-report.py: 에러 처리 로직 및 외부 API 통합 검증 필요
    • terraform/datadog/monitors.tf: 모니터 설정의 쿼리 정확도 및 임계값 적절성 확인
    • terraform/datadog/slos.tf: SLO 쿼리 및 대상 설정 유효성 검증
    • Terraform 상태 관리: 백엔드 및 잠금 테이블 설정 검증
    • AWS SSM Parameter 참조: 파라미터 경로 및 접근 권한 확인

Possibly related PRs

Suggested labels

feat

Suggested reviewers

  • leegwichan

Poem

🐰 달마다 새로운 리포트를 쏙쏙,
Datadog과 AWS 데이터를 모아모아,
Discord 채널로 슝슝 날려보내,
서버의 건강함을 한눈에 팍,
Terraform으로 깔끔하게 정리됐네! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경사항의 주요 내용(Datadog 테라폼 적용 및 월간 서버 리포트)을 명확하게 요약하고 있습니다.
Linked Issues check ✅ Passed PR의 모든 변경사항이 이슈 #195의 요구사항을 충족합니다. Terraform으로 Datadog 설정 관리 및 월간 서버 리포트 기능이 완전히 구현되었습니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 이슈 #195의 범위 내에 있으며, Datadog Terraform 설정 및 월간 리포트 기능과 직접적으로 관련됩니다.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

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.

@github-actions
Copy link

github-actions bot commented Dec 1, 2025

📄 Terraform Plan Summary

🛡️ Common Infrastructure


No plan summary

Status: ✅ No Changes


🚀 Production Environment


No plan summary

Status: ✅ No Changes


📋 Full Results: View in Actions

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 1, 2025

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: 4

🧹 Nitpick comments (6)
scripts/monthly-server-report.py (1)

60-88: 너무 넓은 except Exception 사용으로 버그가 조용히 숨겨질 수 있습니다.

Datadog, WAF, Cost Explorer 호출부에서 모두 except Exception으로 전체를 감싸고 있어서, 코드 결함(예: 타입 오류, 키 오타)까지 조용히 삼켜질 수 있습니다. 운영 리포트 성격상 일부 API 실패를 무시하고 진행하는 전략은 이해되지만, 예외 범위를 좁히는 쪽이 디버깅에 유리합니다.

예시 방향입니다.

  • Datadog: ApiError 또는 datadog 클라이언트에서 제공하는 예외 타입 위주로 캐치
  • AWS: botocore.exceptions.ClientError 또는 BotoCoreError 계열 위주로 캐치
  • 그 외 예기치 못한 예외는 상위로 올리거나, 최소한 별도 로그 구분(예: "Unexpected internal error")으로 남기기

필수 수정 사항은 아니지만, 장기적으로는 각 외부 API별로 더 구체적인 예외 타입을 쓰는 쪽을 추천드립니다.

Also applies to: 95-118, 125-138

.github/workflows/monthly-server-report.yml (1)

20-32: 의존성 버전 고정 및 시크릿/스케줄 설정 한 번만 더 점검하면 좋겠습니다.

  • pip install boto3 datadog-api-client requests python-dateutil가 모두 latest라, 시간이 지나면서 버전이 바뀌면 리포트 스크립트 동작이 달라질 수 있습니다. 월 1회 잡이라도 아래처럼 최소한 메이저/마이너 버전 정도는 고정해 두는 걸 추천드립니다.
      - name: Install Dependencies
        run: |
          pip install \
            boto3==1.x.y \
            datadog-api-client==2.x.y \
            requests==2.x.y \
            python-dateutil==2.x.y
  • DD_API_KEY, DD_APP_KEY, DISCORD_MONTHLY_SERVER_REPORT_WEBHOOK, AWS_* 시크릿들이 main 환경에도 모두 설정되어 있는지 한 번만 더 확인해 주세요.
  • cron: '30 0 1 * *'는 UTC 기준이라 KST 기준으로는 매월 1일 09:30에 실행됩니다. 월간 집계 기준 시점과 맞는지 의도와 일치하는지만 검토해 보시면 좋겠습니다.
terraform/datadog/outputs.tf (1)

1-1: Add outputs for Datadog resource IDs to improve maintainability. The monthly-server-report.py script hardcodes SLO IDs (SLO_AVAILABILITY_ID, SLO_LATENCY_ID), which makes them difficult to maintain if the SLO definitions change. Consider exporting SLO IDs, monitor IDs, and webhook IDs as Terraform outputs so they can be dynamically referenced instead of hardcoded.

terraform/datadog/providers.tf (1)

15-19: API URL을 변수로 정의하여 유연성을 높이세요.

Line 18의 Datadog API URL이 하드코드되어 있습니다. 향후 리전 변경이 필요할 때 코드 수정이 불가피합니다. variables.tf에 변수로 정의하고 기본값을 설정하는 것을 권장합니다.

다음과 같이 변수를 추가할 수 있습니다:

# variables.tf
variable "datadog_api_url" {
  description = "Datadog API URL"
  type        = string
  default     = "https://api.us5.datadoghq.com/"
}

# providers.tf
provider "datadog" {
  api_key = data.aws_ssm_parameter.datadog_api.value
  app_key = data.aws_ssm_parameter.datadog_app.value
  api_url = var.datadog_api_url
}

이렇게 하면 환경별로 terraform.tfvars에서 쉽게 변경할 수 있습니다.

terraform/datadog/slos.tf (1)

1-37: 불필요한 null 할당을 제거하여 코드를 간결하게 하세요.

Lines 3-5, 41-43에서 force_delete = null, groups = null, monitor_ids = null 등이 명시적으로 할당되어 있습니다. 이들은 Terraform의 기본값과 동일하므로 제거해도 동작이 변하지 않습니다. 코드 가독성을 위해 제거하는 것을 권장합니다.

 resource "datadog_service_level_objective" "eatda_latency" {
   description       = "30일간 P95가 500ms 이내로 유지되는 SLO"
-  force_delete      = null
   groups            = null
-  monitor_ids       = null
   name              = "[Eatda-prod-api] Latency (P95 < 500ms)"

이렇게 정리하면 실제로 중요한 설정만 명확하게 보입니다.

Also applies to: 39-60

terraform/datadog/monitors.tf (1)

34-34: on_missing_data 설정이 시스템 모니터 간에 일관성이 없습니다.

  • Line 34 (cpu_usage): on_missing_data = null (기본값)
  • Line 87 (memory_usage): on_missing_data = "default"

시스템 메트릭 부재 시 모니터 동작을 명확히 정의하고 두 모니터에 동일하게 적용하세요.

 resource "datadog_monitor" "cpu_usage" {
   ...
-  on_missing_data = null
+  on_missing_data = "default"
   ...
 }

또는 둘 다 명시적으로 설정하지 않으려면 on_missing_data 라인을 제거하세요.

Also applies to: 87-87

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05516ed and 1997898.

📒 Files selected for processing (12)
  • .github/workflows/monthly-server-report.yml (1 hunks)
  • scripts/monthly-server-report.py (1 hunks)
  • terraform/datadog/.terraform.lock.hcl (1 hunks)
  • terraform/datadog/backend.tf (1 hunks)
  • terraform/datadog/integrations.tf (1 hunks)
  • terraform/datadog/locals.tf (1 hunks)
  • terraform/datadog/monitors.tf (1 hunks)
  • terraform/datadog/outputs.tf (1 hunks)
  • terraform/datadog/providers.tf (1 hunks)
  • terraform/datadog/slos.tf (1 hunks)
  • terraform/datadog/terraform.tfvars (1 hunks)
  • terraform/datadog/variables.tf (1 hunks)
🧰 Additional context used
🪛 Ruff (0.14.6)
scripts/monthly-server-report.py

67-67: Do not catch blind exception: Exception

(BLE001)


73-73: Do not catch blind exception: Exception

(BLE001)


84-84: Do not catch blind exception: Exception

(BLE001)


86-86: Do not catch blind exception: Exception

(BLE001)


114-114: Consider moving this statement to an else block

(TRY300)


115-115: Do not catch blind exception: Exception

(BLE001)


135-135: Consider moving this statement to an else block

(TRY300)


136-136: Do not catch blind exception: Exception

(BLE001)


157-157: Multiple statements on one line (colon)

(E701)


178-178: Probable use of requests call without timeout

(S113)


187-187: Do not catch blind exception: Exception

(BLE001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (12)
terraform/datadog/terraform.tfvars (1)

1-1: No actionable concerns. The empty terraform.tfvars file is appropriate for this configuration.

No Terraform variables are declared in variables.tf, so there is nothing for the tfvars file to populate. Sensitive values (Datadog API keys, Discord webhook URLs) are correctly sourced from AWS SSM Parameter Store as data sources in locals.tf and integrations.tf, not from tfvars files. This is the proper pattern for managing secrets in Terraform—external secret stores rather than variable files.

terraform/datadog/variables.tf (1)

1-1: 빈 variables.tf 파일의 의도 확인 필요.

이 파일이 비어있는 것으로 보입니다. Terraform 모듈에서 variables.tf는 일반적으로 다른 파일에서 사용되는 입력 변수들을 선언하는 역할을 합니다.

terraform/datadog/ 디렉토리의 다른 Terraform 파일들(backend, provider, integrations, monitors, SLIs)에서 변수가 필요한지 확인하고, 필요하다면 여기에 변수 선언을 추가하는 것이 좋습니다. 혹은 변수들이 의도적으로 다른 위치에서 관리되고 있다면, 그 설계 의도를 확인해 주세요.

terraform/datadog/backend.tf (1)

1-9: ✅ S3 백엔드 설정이 잘 구성되었습니다.

원격 상태 저장소 설정, 암호화, 상태 잠금이 모두 적절히 활성화되어 있습니다. 팀 협업 환경에서 상태 파일 충돌을 방지할 수 있습니다.

terraform/datadog/.terraform.lock.hcl (1)

1-47: ✅ Terraform 잠금 파일이 올바르게 구성되었습니다.

공급자 버전이 명시적으로 지정되어 있고 해시값이 포함되어 일관된 빌드를 보장합니다.

terraform/datadog/providers.tf (1)

3-6: AWS 공급자 버전이 정확하게 지정되었습니다.

AWS 공급자를 정확한 버전(6.23.0)으로 고정하는 것은 좋은 관행입니다. Datadog 공급자의 범위 지정(~> 3.80)도 적절합니다.

terraform/datadog/slos.tf (1)

14-30: SLO 정의가 명확하고 일관성 있게 설정되었습니다.

  • 레이턴시 SLO: P95 < 500ms 목표가 합리적
  • 가용성 SLO: 5xx 에러 제외 로직이 올바름
  • 모두 service:eatda-api-prod 태그로 서비스 추적 가능
terraform/datadog/locals.tf (2)

21-40: Datadog 알림 템플릿이 명확하게 구조화되었습니다.

Handlebars 스타일 조건문을 사용하여 CRITICAL, WARNING, RECOVERY 상황별로 다른 메시지를 전송할 수 있습니다. 각 섹션에서 해당 Discord 채널을 멘션하는 구조도 효과적입니다.


1-19: AWS SSM parameters and notification template are properly structured.

The code correctly externalizes sensitive credentials (Datadog API/APP keys and Discord webhook URLs) using AWS SSM Parameter Store with clear naming conventions. The notification footer template appropriately uses Handlebars conditionals to customize alerts by severity level.

No changes required.

terraform/datadog/monitors.tf (3)

109-162: ✅ 가용성 SLO 모니터 구성이 적절합니다.

burn_rate 쿼리와 SLO 임계값이 일관성 있게 설정되어 있고, 메시지에 상세한 조치 사항을 포함하고 있습니다.


164-217: ✅ 레이턴시 SLO 모니터 구성이 적절합니다.

P95 < 500ms 목표에 맞게 burn_rate 쿼리가 설정되었고, 장시간 윈도우(6h)와 단기 윈도우(30m)로 다양한 수준의 성능 저하를 감지할 수 있습니다.


11-27: ✅ 모니터 메시지 템플릿이 상세하고 실행 가능합니다.

각 모니터가 문제 상황을 한국어로 명확히 설명하고, 영향도와 구체적인 조치 방법을 포함하고 있습니다. 이는 온콜 엔지니어가 빠르게 대응하는 데 도움이 됩니다.

Also applies to: 66-82, 119-135, 174-190

terraform/datadog/integrations.tf (1)

1-44: Discord webhook integrations are correctly configured.

The three webhook resources use the proper Datadog webhook template variables ($EVENT_MSG, $EVENT_TITLE, $LINK), which are standard syntax for webhook payloads as documented in Datadog's webhooks integration guide. The resources are well-structured with appropriate color coding, consistent payload formatting, and secure URL retrieval from SSM parameters. No changes are required.

@lvalentine6 lvalentine6 merged commit e66d104 into main Dec 1, 2025
18 of 19 checks passed
@github-actions
Copy link

🎉 This PR is included in version 1.9.4 🎉

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants