-
Notifications
You must be signed in to change notification settings - Fork 0
[Infra] - MDC 로깅 구현 및 프롬테일 추가 #11
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
Changes from all commits
b08e529
1e520b8
6ec5cf5
cc5b94b
0a4f5d8
8d893c4
e02998b
6cb1096
cc6567b
532c275
bcadbe9
efc8534
f961150
ff7465a
ee093d6
2d275e4
39f9415
eee3518
4fb9b2c
d400bd5
3b27421
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| name: CD API DEV | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
| branches: [ develop ] | ||
|
|
||
| jobs: | ||
|
|
@@ -78,10 +78,10 @@ jobs: | |
| [ -d kokomen-notification ] || git clone --filter=blob:none --no-checkout https://github.com/samhap-soft/kokomen-notification.git | ||
| cd kokomen-notification | ||
| git sparse-checkout init --cone | ||
| git fetch origin develop | ||
| git checkout develop | ||
| git fetch origin feature/#10 | ||
| git checkout feature/#10 | ||
| git sparse-checkout set docker/dev | ||
| git pull origin develop | ||
| git pull origin feature/#10 | ||
|
Comment on lines
-81
to
+84
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 머지하기 전에는 원복해야겠네요! |
||
|
|
||
| - name: Docker Image pull | ||
| run: sudo docker pull samhap/kokomen-notification-api:dev | ||
|
|
@@ -95,4 +95,4 @@ jobs: | |
| run: | | ||
| export HOSTNAME=$(hostname) | ||
| cd kokomen-notification/docker/dev | ||
| sudo -E docker compose -f docker-compose-dev.yml up -d kokomen-notification-dev-api | ||
| sudo -E docker compose -f docker-compose-dev.yml up -d kokomen-notification-dev-api kokomen-notification-mysql-dev | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| name: CD INTERNAL DEV | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
| branches: [ develop ] | ||
|
Comment on lines
-4
to
5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 머지하기 전에는 원복해야겠네요! |
||
|
|
||
| jobs: | ||
|
|
@@ -78,10 +78,10 @@ jobs: | |
| [ -d kokomen-notification ] || git clone --filter=blob:none --no-checkout https://github.com/samhap-soft/kokomen-notification.git | ||
| cd kokomen-notification | ||
| git sparse-checkout init --cone | ||
| git fetch origin develop | ||
| git checkout develop | ||
| git fetch origin feature/#10 | ||
| git checkout feature/#10 | ||
| git sparse-checkout set docker/dev | ||
| git pull origin develop | ||
| git pull origin feature/#10 | ||
|
Comment on lines
80
to
+84
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 머지하기 전에는 원복해야겠네요! |
||
|
|
||
| - name: Docker Image pull | ||
| run: sudo docker pull samhap/kokomen-notification-internal:dev | ||
|
|
@@ -95,4 +95,4 @@ jobs: | |
| run: | | ||
| export HOSTNAME=$(hostname) | ||
| cd kokomen-notification/docker/dev | ||
| sudo -E docker compose -f docker-compose-dev.yml up -d kokomen-notification-dev-internal | ||
| sudo -E docker compose -f docker-compose-dev.yml up -d kokomen-notification-dev-internal kokomen-notification-mysql-dev | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package com.samhap.kokomen.global.logging; | ||
|
|
||
| import jakarta.servlet.FilterChain; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import jakarta.servlet.http.HttpSession; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.slf4j.MDC; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.util.AntPathMatcher; | ||
| import org.springframework.util.StopWatch; | ||
| import org.springframework.web.filter.OncePerRequestFilter; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| public class LoggingFilter extends OncePerRequestFilter { | ||
|
|
||
| private static final List<String> WHITE_LIST = List.of( | ||
| "/favicon.ico", | ||
| "/docs/index.html", | ||
| "/metrics", | ||
| "/actuator/**"); | ||
|
|
||
| @Override | ||
| protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
| throws ServletException, IOException { | ||
| StopWatch stopWatch = new StopWatch(); | ||
| stopWatch.start(); | ||
|
|
||
| String requestId = readRequestId(request); | ||
| MDC.put("requestId", requestId); | ||
|
|
||
| try { | ||
| filterChain.doFilter(request, response); | ||
| } finally { | ||
| stopWatch.stop(); | ||
| log.info("{} {} {} ({}) - {}ms", | ||
| readMemberId(request), | ||
| request.getMethod(), | ||
| request.getRequestURI(), | ||
| HttpStatus.valueOf(response.getStatus()), | ||
| stopWatch.getTotalTimeMillis()); | ||
|
|
||
| MDC.clear(); | ||
| } | ||
| } | ||
|
|
||
| private String readRequestId(HttpServletRequest request) { | ||
| String requestId = request.getHeader("X-RequestID"); | ||
| if (requestId != null && !requestId.isEmpty()) { | ||
| return requestId; | ||
| } | ||
| return UUID.randomUUID().toString(); | ||
| } | ||
|
|
||
| private String readMemberId(HttpServletRequest request) { | ||
| HttpSession session = request.getSession(false); | ||
| if (session != null) { | ||
| Long memberId = (Long) session.getAttribute("MEMBER_ID"); | ||
| if (memberId != null) { | ||
| return "memberId=" + memberId; | ||
| } | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { | ||
| String requestURI = request.getRequestURI(); | ||
| AntPathMatcher antPathMatcher = new AntPathMatcher(); | ||
| return WHITE_LIST.stream().anyMatch(path -> antPathMatcher.match(path, requestURI)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <configuration> | ||
| <include resource="org/springframework/boot/logging/logback/defaults.xml"/> | ||
|
|
||
| <springProperty scope="context" name="springAppName" source="spring.application.name"/> | ||
|
|
||
| <!-- 공통 Appender 정의 --> | ||
| <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
| <encoder> | ||
| <pattern> | ||
| <![CDATA[[%X{requestId:-noRequest}] %d{yyyy-MM-dd HH:mm:ss.SSS} ${springAppName:-kokomen-notification} [%thread] %-5level %logger{36} - %msg%n]]> | ||
| </pattern> | ||
| </encoder> | ||
| </appender> | ||
|
|
||
| <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
| <file>./logs/app.log</file> | ||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
| <fileNamePattern>./logs/app.%d{yyyy-MM-dd}.log</fileNamePattern> | ||
| <maxHistory>30</maxHistory> | ||
| </rollingPolicy> | ||
| <encoder> | ||
| <pattern> | ||
| <![CDATA[[%X{requestId:-noRequest}] %d{yyyy-MM-dd HH:mm:ss.SSS} ${springAppName:-kokomen-notification} [%thread] %-5level %logger{36} - %msg%n]]> | ||
| </pattern> | ||
| </encoder> | ||
| </appender> | ||
|
|
||
| <!-- local 환경: 콘솔만 사용 --> | ||
| <springProfile name="local"> | ||
| <root level="INFO"> | ||
| <appender-ref ref="CONSOLE"/> | ||
| </root> | ||
| </springProfile> | ||
|
|
||
| <!-- dev 환경: FILE 저장 --> | ||
| <springProfile name="dev"> | ||
| <root level="INFO"> | ||
| <appender-ref ref="FILE"/> | ||
| </root> | ||
| </springProfile> | ||
|
|
||
| <!-- prod 환경: FILE 저장 --> | ||
| <springProfile name="prod"> | ||
| <root level="INFO"> | ||
| <appender-ref ref="FILE"/> | ||
| </root> | ||
| </springProfile> | ||
|
|
||
| <!-- test 환경: 콘솔만 사용 --> | ||
| <springProfile name="test"> | ||
| <root level="INFO"> | ||
| <appender-ref ref="CONSOLE"/> | ||
| </root> | ||
| </springProfile> | ||
| </configuration> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| server: | ||
| http_listen_port: 9080 | ||
|
|
||
| positions: | ||
| filename: /tmp/positions.yaml | ||
|
|
||
| clients: | ||
| - url: http://loki:3100/loki/api/v1/push | ||
|
|
||
| scrape_configs: | ||
| - job_name: kokomen-notification-api-dev | ||
| static_configs: | ||
| - labels: | ||
| job: kokomen-notification-api | ||
| app: kokomen-notification-api | ||
| host: ${HOSTNAME} | ||
| __path__: /logs/api/app.log | ||
| pipeline_stages: | ||
| - regex: | ||
| expression: '\[.*?\] [\d\-:.\s]+ [^\[\]]+ \[.*?\]\s+(?P<level>[A-Z]+)\s+[^\s]+' | ||
| - labels: | ||
| level: | ||
| - job_name: kokomen-notification-internal-dev | ||
| static_configs: | ||
| - labels: | ||
| job: kokomen-notification-internal | ||
| app: kokomen-notification-internal | ||
| host: ${HOSTNAME} | ||
| __path__: /logs/internal/app.log | ||
| pipeline_stages: | ||
| - regex: | ||
| expression: '\[.*?\] [\d\-:.\s]+ [^\[\]]+ \[.*?\]\s+(?P<level>[A-Z]+)\s+[^\s]+' | ||
| - labels: | ||
| level: |
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.
머지하기 전에는 원복해야겠네요!