-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] Datadog 테라폼 적용 및 월간 서버 리포트 추가 Prod 적용 #215
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
Conversation
…m-1-BE into feat/PRODUCT-281
[Feat] Datadog 테라폼 적용 및 월간 서버 리포트 추가
WalkthroughGitHub Actions 워크플로우 및 Python 스크립트를 추가하여 월간 서버 리포트 자동화를 구현하고, Datadog 모니터링 설정을 Terraform으로 관리하는 인프라 코드를 도입했습니다. Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
📄 Terraform Plan Summary🛡️ Common InfrastructureStatus: ✅ No Changes 🚀 Production EnvironmentStatus: ✅ No Changes 📋 Full Results: View in Actions |
|
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: 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. Themonthly-server-report.pyscript 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
📒 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 emptyterraform.tfvarsfile 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 inlocals.tfandintegrations.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.
|
🎉 This PR is included in version 1.9.4 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |



✨ 개요
🧾 관련 이슈
Close #195
🔍 참고 사항 (선택)
Summary by CodeRabbit
릴리스 노트
새로운 기능
Chores
✏️ Tip: You can customize this high-level summary in your review settings.