Skip to content

feat: add API latency metrics (Micrometer + Prometheus) - #102

Merged
user983740 merged 1 commit into
mainfrom
feat/api-latency-metrics
Jul 4, 2026
Merged

feat: add API latency metrics (Micrometer + Prometheus)#102
user983740 merged 1 commit into
mainfrom
feat/api-latency-metrics

Conversation

@user983740

Copy link
Copy Markdown
Collaborator

변경 사항

주요 API 레이턴시(p95/p99)·트래픽·에러율을 Grafana에서 모니터링하기 위해, 모든 HTTP 엔드포인트를 Micrometer로 자동 계측하고 Prometheus 스크래핑 엔드포인트를 노출합니다.

  • micrometer-registry-prometheus 의존성 추가
  • management.endpoints.web.exposure.includeprometheus 추가 → /api/v1/prometheus 노출
  • http.server.requests 히스토그램 버킷 + SLO 버킷 활성화 → Grafana에서 p95/p99 계산 가능
  • 공통 태그 application=snuclear-server, 프로필별 env=dev|prod
  • SecurityConfig: /api/v1/prometheus permitAll (클러스터 내부 Prometheus scrape용)

계측 범위

Micrometer가 Spring MVC의 모든 요청uri(템플릿 경로)·method·status·outcome 태그로 자동 기록합니다. 별도 엔드포인트 지정 없이, 새 API도 자동으로 계측됩니다.

보안

/api/v1/prometheus는 permitAll이지만 클러스터 내부 scrape 전용입니다. 외부 노출은 인프라(waffle-world-oci)의 Istio VirtualService에서 차단합니다 (별도 PR).
/api/v1/health는 변경하지 않아 기존 liveness/readiness probe에 영향 없습니다.

검증

  • ./gradlew compileKotlin ktlintCheck 통과
  • 로컬 부팅 후 /api/v1/prometheus에서 http_server_requests_seconds_bucket(p95/p99용) 및 application/env 태그 정상 출력 확인

참고

이 PR은 앱 계측 부분입니다. 대시보드·스크래핑(ServiceMonitor)·외부차단은 인프라 레포(waffle-world-oci)에서 별도 PR로 진행합니다.

🤖 Generated with Claude Code

- micrometer-registry-prometheus 의존성 추가
- /api/v1/prometheus 엔드포인트 노출 (management exposure)
- http.server.requests 히스토그램 버킷 + SLO 버킷 활성화 (p95/p99 계산용)
- 공통 태그 application=snuclear-server, 프로필별 env=dev|prod
- SecurityConfig: /api/v1/prometheus permitAll (클러스터 내부 scrape용, 외부는 Istio에서 차단)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ea9520091

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"/api/leaderboard/weekly",
"/api/v1/health",
// Prometheus 스크래핑 — 클러스터 내부 접근만 허용, 외부는 Istio VirtualService에서 차단
"/api/v1/prometheus",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate Prometheus scrapes in the app

With src/main/resources/application.yaml:22 exposing prometheus, this permitAll matcher becomes the only application-level gate for /api/v1/prometheus; it does not actually restrict access to cluster-internal clients despite the comment. In any deployment where the public backend route forwards /api/v1/** before or without the separate Istio VirtualService change, anonymous users can scrape request/JVM metrics, so keep this authenticated or add an in-app network/token check unless the route block is deployed atomically.

Useful? React with 👍 / 👎.

@user983740

Copy link
Copy Markdown
Collaborator Author

셀프 리뷰 ✅

변경 검토

  • build.gradle.kts: micrometer-registry-prometheus — Spring Boot BOM 관리라 버전 명시 없음(정상), Maven Central 의존성
  • application.yaml: exposure에 prometheus 추가, 히스토그램 bracket 키 "[http.server.requests]"는 Spring 관계형 바인딩 정식 표기 확인
  • application-{dev,prod}.yaml: base management 블록과 merge되어 env 태그만 추가
  • SecurityConfig.kt: permitAll 목록에 /api/v1/prometheus 한 줄 추가, 나머지 규칙 불변

검증

  • CI: ktlint + 전체 테스트 통과
  • 로컬 부팅 → /api/v1/prometheus 200 + http_server_requests_seconds_bucket(p95/p99용) + application/env 태그 정상 확인
  • uri는 템플릿 경로(/api/courses/search)로 기록되어 카디널리티 안전

probe 영향 없음: /api/v1/health 미변경 → 관리 포트도 8080 유지(분리 안 함)해서 liveness/readiness 그대로.

머지합니다.

@user983740
user983740 merged commit 2a97334 into main Jul 4, 2026
1 check passed
@user983740
user983740 deleted the feat/api-latency-metrics branch July 4, 2026 05:24
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.

2 participants