Skip to content
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

#338 [feat] Observability 개선 #339

Merged
merged 9 commits into from
Jan 19, 2025
Merged

#338 [feat] Observability 개선 #339

merged 9 commits into from
Jan 19, 2025

Conversation

KWY0218
Copy link
Member

@KWY0218 KWY0218 commented Jan 19, 2025

✒️ 관련 이슈번호

Key Changes 🔑

1. MDC Filter 추가
로그가 섞여도 특정 스레드의 행동을 파악할 수 있도록 MDC 정보를 추가했습니다.
metric 시 타 스레드로 동작하기 때문에 mdc 내용이 전파되지 않아, TaskDecorator를 추가해 async 시에도 mdc 내용이 전파되도록 구현했습니다.

2. 요청 및 응답 값 로깅
aop를 통해 요청에 대한 요청 값과 응답 값을 로깅하도록 구현했습니다.
controller 에 들어온 아규먼트를 추출해 요청 값을 로깅했고, returnValue를 통해 응답 값을 로깅했습니다.
비즈니스 중 에러가 발생했을 때 controllerAdvice에서 응답 값을 반환하기 때문에 controllerAdvice에 대한 pointCut을 만들어 에러 시 응답 값을 로깅했습니다.

3. p6spy dependency 추가
sql에 대한 로깅을 하고 싶어 p6spy 라이브러리를 추가했습니다.
p6spy의 메시지 툴도 괜찮은 것 같다고 생각해 별도의 커스텀은 하지 않았습니다..!

4. rolling file appender로 수정
요일 단위로 로그를 수집하도록 file appender -> rolling file appender로 수정했습니다.

To Reviewers 📢

as-is

[2025-01-18T15:13:12:36674] [http-nio-8080-exec-10] INFO  [com.asap.server.presentation.config.aspect.LoggingAspect.requestInfoLevelLogging:38] - ================================================NEW===============================================
[2025-01-18T15:13:12:36674] [http-nio-8080-exec-10] INFO  [com.asap.server.presentation.config.aspect.LoggingAspect.requestInfoLevelLogging:39] - ====> Request: POST http://localhost:8080/meeting (303ms) *Header = {}
[2025-01-18T15:13:12:36674] [http-nio-8080-exec-10] INFO  [com.asap.server.presentation.config.aspect.LoggingAspect.requestInfoLevelLogging:41] - ====> Body: {"title": "string","availableDates": ["2024/7/9/MON"],"place": "ONLINE","placeDetail": "string","duration": "HALF","name": "김아삽","password": "0808","additionalInfo": "string"}
[2025-01-18T15:13:12:36674] [http-nio-8080-exec-10] INFO  [com.asap.server.presentation.config.aspect.LoggingAspect.requestInfoLevelLogging:44] - ====> Response: SuccessResponse(code=201, message=회의가 성공적으로 생성되었습니다., data=MeetingSaveResponseDto(url=Mw==, accessToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhY2Nlc3NfdG9rZW4iLCJpYXQiOjE3MzcxODA3OTIsImV4cCI6MTczNzI2NzE5MiwidXNlcklkIjoiNDYyIiwicm9sZSI6IkhPU1QifQ.gtlN5f4Tqms0SrfU0JxwNJ8SMAO5rAT_KHXgOC6fmoHjPp9peSoVT40F8hBbBIhsKe0JnrHaGdVZ4J-4YIKNRw))
[2025-01-18T15:13:12:36677] [http-nio-8080-exec-10] INFO  [com.asap.server.presentation.config.aspect.LoggingAspect.requestInfoLevelLogging:46] - ================================================END===============================================

to-be

[2025-01-19T16:13:01:12367] - [0f47bd91-f6d4-4b9b-9355-80ed7bf873fe] [http-nio-8080-exec-1] INFO - URI : /internal/metrics | Request : [from : 2000-08-12, to : 2024-08-15]
[2025-01-19T16:13:02:12881] - [0f47bd91-f6d4-4b9b-9355-80ed7bf873fe] [http-nio-8080-exec-1] INFO - #1737270782431 | took 4ms | statement | connection 4| url
select count(m1_0.id) from meeting m1_0 where m1_0.created_at between ? and ?
select count(m1_0.id) from meeting m1_0 where m1_0.created_at between '2000-08-12T00:00:00.000+0900' and '2024-08-15T00:00:00.000+0900';
[2025-01-19T16:13:02:12892] - [0f47bd91-f6d4-4b9b-9355-80ed7bf873fe] [http-nio-8080-exec-1] INFO - #1737270782441 | took 1ms | statement | connection 4| url
select count(u1_0.id) from user u1_0 where u1_0.created_at between ? and ?
select count(u1_0.id) from user u1_0 where u1_0.created_at between '2000-08-12T00:00:00.000+0900' and '2024-08-15T00:00:00.000+0900';
[2025-01-19T16:13:02:12907] - [0f47bd91-f6d4-4b9b-9355-80ed7bf873fe] [http-nio-8080-exec-1] INFO - #1737270782457 | took 1ms | statement | connection 4| url
select count(m1_0.id) from meeting m1_0 where m1_0.confirmed_start_time is not null and m1_0.created_at between ? and ?
select count(m1_0.id) from meeting m1_0 where m1_0.confirmed_start_time is not null and m1_0.created_at between '2000-08-12T00:00:00.000+0900' and '2024-08-15T00:00:00.000+0900';
[2025-01-19T16:13:07:18371] - [0f47bd91-f6d4-4b9b-9355-80ed7bf873fe] [http-nio-8080-exec-1] INFO - URI : /internal/metrics | Response : SuccessResponse(code=200, message=메트릭 정보 조회 성공입니다., data=null)
[2025-01-19T16:13:08:18658] - [0f47bd91-f6d4-4b9b-9355-80ed7bf873fe] [threadPoolTaskExecutor-1] ERROR  throws java.io.IOException

@KWY0218 KWY0218 requested a review from sohyundoh January 19, 2025 07:17
@KWY0218 KWY0218 self-assigned this Jan 19, 2025
@sohyundoh
Copy link
Member

좋습니다-!

P6spy를 ec2 t2micro 환경에서 사용하면 메모리 부족도 있을 것 같아, 환경 분리도 고려해보면 좋을 것 같습니다~!

Copy link
Member

@sohyundoh sohyundoh left a comment

Choose a reason for hiding this comment

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

좋습니다

@KWY0218
Copy link
Member Author

KWY0218 commented Jan 19, 2025

@sohyundoh
prod, dev 환경에선 sql 로깅하지 않도록 yaml 파일 수정했습니다~!

메모리 부족도 있을 것 같아,

혹시 p6spy 관련 메모리릭 같은 이슈가 따로 있을까요???

@sohyundoh
Copy link
Member

@KWY0218
아뇨 p6spy 관련된 메모리 누수는 아는게 없지만, vm 저장공간 상 발생한 쿼리를 모두 prod 환경에서 관리할 경우 메모리를 과하게 차지할 것 같아 말씀드렸습니다-!
실제로 라이브 환경에서는 p6spy 쿼리로깅을 비활성화하더라고요!

@KWY0218 KWY0218 merged commit 5582718 into develop Jan 19, 2025
4 checks passed
@KWY0218 KWY0218 deleted the feat/#338 branch January 19, 2025 10:40
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.

[feat] Observability 개선
2 participants