Skip to content

[global] GraphQL 응답속도 Discord 알림 인터셉터 추가#53

Merged
jyx-07 merged 4 commits into
developfrom
feat/global-graphql-latency-discord-alert
Jul 20, 2026
Merged

[global] GraphQL 응답속도 Discord 알림 인터셉터 추가#53
jyx-07 merged 4 commits into
developfrom
feat/global-graphql-latency-discord-alert

Conversation

@jyx-07

@jyx-07 jyx-07 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

개요

모든 GraphQL 요청의 응답속도를 Discord로 알림 전송하는 WebGraphQlInterceptor를 신규 추가하였습니다. GraphQL은 모든 요청이 POST /graphql 하나로 들어와 URL만으로는 어떤 쿼리/뮤테이션인지 구분할 수 없어, 요청 단위로 가로채는 인터셉터가 필요했습니다.

변경 사항

  • global/graphql/interceptor/GraphQlLatencyDiscordInterceptor: WebGraphQlInterceptor 구현체 신규 추가. @Component로 등록하면 Spring Boot가 ObjectProvider<WebGraphQlInterceptor>로 자동 수집하여 별도 설정 클래스 없이 등록됩니다.
  • 응답속도에 따라 embed 색상/이모지를 구분하였습니다 (🟢<300ms / 🟡300~700ms / 🐢700ms 이상="느린 응답" / 🚨GraphQL 에러 발생 시 응답속도와 무관하게 강제 빨강).
  • embed 타이틀을 {이모지} [{환경}] {서비스명} — {상태 문구} 형식으로 표준화하였습니다. spring.application.name, spring.profiles.active를 주입받아 서비스명/환경을 표시합니다.
  • 에러 발생 시 첫 번째 에러 메시지를 embed description에 인라인 코드(`메시지`)로 강조 표시합니다.
  • embed에 응답시간, 요청자 정보(SecurityContextHolder에서 캡처한 인증 정보로 회원 이름/역할 조회), 쿼리 원문, 요청 변수, 에러 메시지를 담았습니다. 쿼리/변수/에러는 각각 graphql / json 코드블록으로 감싸 가독성을 높였고, 900자로 truncate하였습니다.
  • 요청 변수는 중첩된 객체(input 등)까지 재귀적으로 순회하며, 키 이름에 password/token/secret이 포함되면 값을 ***로 마스킹합니다.
  • Discord embed의 네이티브 timestamp 필드를 채워, Discord 클라이언트가 자동으로 로컬 타임존 기준 발송 시각을 표시하도록 하였습니다.
  • global/discord/DiscordEmbed, DiscordWebhookClient를 재사용 가능한 컴포넌트로 분리하였습니다. RestClient(신규 의존성 없음)로 전송하며, Schedulers.boundedElastic()에서 fire-and-forget으로 처리해 Discord 전송 지연/실패나 SecurityContext 조회 실패가 실제 GraphQL 응답에 전혀 영향을 주지 않도록 하였습니다.
  • global/config/RestClientConfigRestClient 빈을 신규 등록하였습니다.
  • application.yamldiscord.webhook.graphql-latency-url: ${DISCORD_GRAPHQL_LATENCY_WEBHOOK_URL}을 추가하였습니다.
  • 설계 문서(docs/plans/graphql-latency-discord-interceptor-plan.md)를 추가하였습니다.

Discord 메시지 예시

정상/지연 요청:

🟢 [local] GSMC-server-v4 — GraphQL 요청
─────────────────────────
서비스        환경        응답시간
GSMC-server-v4  local     128ms

요청자
홍길동 (STUDENT)

쿼리
```graphql
query { me { name } }
```

에러 발생 시:

🚨 [local] GSMC-server-v4 — GraphQL 에러
`Member를 찾을 수 없습니다`
─────────────────────────
서비스        환경        응답시간
GSMC-server-v4  local     1523ms

요청자
익명

쿼리
```graphql
mutation { ... }
```

에러
```
Member를 찾을 수 없습니다
```

느린 응답(700ms 이상, 에러 없음)일 때는 타이틀이 🐢 [local] GSMC-server-v4 — 느린 응답으로 표시됩니다.

참고 사항

  • 배포 전 DISCORD_GRAPHQL_LATENCY_WEBHOOK_URL 환경변수에 실제 Discord 웹훅 URL을 설정해야 합니다.
  • spring.profiles.active가 설정되지 않은 환경(로컬 등)에서는 기본값 local이 "환경" 필드/타이틀에 표시됩니다.
  • 로그인 후 실제 GraphQL 요청을 날려 요청자 필드(이름/역할)가 의도대로 채워지는지, 색상·이모지 구간별로 embed가 잘 오는지 실환경에서 한 번 확인이 필요합니다(계획 문서 §6 열린 이슈 참고).
  • 현재는 모든 요청을 전송하도록 결정하였습니다. 학교 인증관리 시스템 특성상 저트래픽으로 가정하였고, 트래픽이 늘어나면 Discord 웹훅 rate limit(2초당 5회) 재검토가 필요합니다.

체크리스트

  • 이 작업으로 인해 변경이 필요한 문서를 작성 또는 수정했나요? (e.g. README, .env.example)
  • 작업한 코드가 정상적으로 동작하는지 확인했나요?
  • 작업한 코드에 대한 테스트 코드를 작성하거나 수정했나요?
  • Merge 대상 브랜치를 올바르게 설정했나요?
  • 해당 PR과 관련 없는 작업이 포함되지는 않았나요?
  • PR의 올바른 라벨과 리뷰어를 설정했나요?

@jyx-07 jyx-07 added the 📩 Type: Feature/Function 새로운 기능 및 개선 사항 label Jul 17, 2026
@github-actions github-actions Bot added the 🌟 Status: Reviewing 리뷰 중인 이슈 label Jul 17, 2026
@jyx-07 jyx-07 self-assigned this Jul 17, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a GraphQL latency monitoring system that sends execution metrics and request details to a Discord channel via webhooks. It implements a WebGraphQlInterceptor to measure latency, a RestClient configuration, and a DiscordWebhookClient for asynchronous notification delivery. Key feedback from the review highlights critical improvements: capturing the SecurityContext synchronously before the reactive chain execution to prevent losing requester information on different threads, recursively masking nested variables to ensure sensitive data is not leaked, adding defensive checks for blank webhook URLs, and providing a default fallback value in application.yaml to avoid startup failures in local or test environments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/main/resources/application.yaml Outdated
@jyx-07
jyx-07 merged commit 0dac931 into develop Jul 20, 2026
7 of 8 checks passed
@jyx-07
jyx-07 deleted the feat/global-graphql-latency-discord-alert branch July 20, 2026 06:41
@github-actions github-actions Bot added 🌟 Status: Done 리뷰까지 완료된 이슈 and removed 🌟 Status: Reviewing 리뷰 중인 이슈 labels Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌟 Status: Done 리뷰까지 완료된 이슈 📩 Type: Feature/Function 새로운 기능 및 개선 사항

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants