[Spring Boot][Total-Back-Office Project] AOP, Annotation์„ ์ด์šฉํ•œ API ๋™์ž‘ ์‹œ๊ฐ„ ์ธก์ •

2023. 7. 15. 17:46ใ†Back-End ์ž‘์—…์‹ค/Spring Framework

728x90
๋ฐ˜์‘ํ˜•

 

 

 

 

 

์Šคํ”„๋ง ๋ถ€ํŠธ 3 ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž ๋˜๊ธฐ : ์ž๋ฐ” ํŽธ

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 



๐Ÿ—‚ ๋ชฉ์ฐจ

๐Ÿง‘‍๐Ÿ’ป ์ฝ”๋”ฉ

โœ…  [Spring Boot][Total-Back-Office Project] AOP, Annotation์„ ์ด์šฉํ•œ API ๋™์ž‘ ์‹œ๊ฐ„ ์ธก์ •
โœ… [Spring Boot][Total-Back-Office Project] AOP, Annotation์„ ์ด์šฉํ•œ API ์š”์ฒญ ์ด์šฉ์ž ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ feat.MyBatis & Test Code(JUnit 5) (https://junyharang.tistory.com/457
)

โœ… [Spring Boot][Total-Back-Office Project] Log Back์„ ์ด์šฉํ•œ Discord์— Exception ์ •๋ณด ๋ณด๋‚ด๊ธฐ ๋ฐ Data Base  ์ €์žฅ feat.MyBatis & Test Code(JUnit 5) - โ‘  Log Back ์„ค์ •
โœ… [Spring Boot][Total-Back-Office Project] Log Back์„ ์ด์šฉํ•œ Discord์— Exception ์ •๋ณด ๋ณด๋‚ด๊ธฐ ๋ฐ Data Base ์ €์žฅ feat.MyBatis & Test Code(JUnit 5) - โ‘ก ๋””์Šค์ฝ”๋“œ๋กœ ๋กœ๊ทธ ์ •๋ณด ๋ฐœ์†ก
โœ… [Spring Boot][Total-Back-Office Project] Log Back์„ ์ด์šฉํ•œ Discord์— Exception ์ •๋ณด ๋ณด๋‚ด๊ธฐ ๋ฐ Data Base ์ €์žฅ feat.MyBatis & Test Code(JUnit 5) - โ‘ข ๋กœ๊ทธ ๋ฐ ์š”์ฒญ ์ด์šฉ์ž, ์š”์ฒญ ์ •๋ณด ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค์— ์ €์žฅ

 

๐Ÿšš ๋ฐฐํฌ

โš ๏ธ ์•„๋ž˜ ๋ชฉ์ฐจ ์ค‘ ๋ช‡๋ช‡๊ฐœ์˜ ๋งํฌ๊ฐ€ ๊ฑธ๋ฆฌ์ง€ ์•Š๋Š” ๋ฌธ์ œ๋กœ ๊ธ€ ๋งจ ํ•˜๋‹จ์— ๋‹ค์Œ ๊ธ€๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด ๋‘์—ˆ์Šต๋‹ˆ๋‹ค.

โœ… [CI/CD] Jenkins์™€ Gitea ์—ฐ๋™
โœ… [CI/CD] Jenkins Trigger ์ •๋ณด Discord๋กœ ๋ณด๋‚ด๊ธฐ
โœ… [CI/CD] ์ •์  ์ฝ”๋“œ ๋ถ„์„ ํˆด SonarQube์™€ Jenkins ์—ฐ๋™
โœ… [CI/CD] SonarQube๋ฅผ ํ†ตํ•ด Code Convention ์ ์šฉ
โœ… [DevOps] JAVA Gradle JaCoCo (Code coverage) ์„ค์ •ํ•˜๊ธฐ 
โœ… [DevOps] JAVA Gradle JaCoCo (Code coverage) ์„ค์ •ํ•˜๊ธฐ (์ถ”๊ฐ€)(https://junyharang.tistory.com/392)

โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘  Application Linuxt(Ubuntu)์— SSH๋ฅผ ์ด์šฉํ•œ ํŒŒ์ผ ์ „์†ก
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ก Create Docker Image And BackUp
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘  Application ๋„์ปค ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ก Application Docker Run)(https://junyharang.tistory.com/406)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ข Application Docker Health Check)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘  NGINX ๊ฐ ์ข… ์„ค์ •) 
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ก NGINX Docker ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ) 
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ข NGINX Docker Run & Health Check)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ข NGINX ์žฌ ์„ค์ •)

 

 

 

 

๐Ÿ’พ Git Hub Repository : https://github.com/junyharang-personal-project/junyss-total-back-office

 

GitHub - junyharang-personal-project/junyss-total-back-office: [Back-Office] ๋””์Šค์ฝ”๋“œ ๋ด‡๊ณผ Logback, AOP ๋“ฑ์„ ์ด์šฉํ•˜

[Back-Office] ๋””์Šค์ฝ”๋“œ ๋ด‡๊ณผ Logback, AOP ๋“ฑ์„ ์ด์šฉํ•˜์—ฌ ์ด์šฉ์ž ์ ‘์† ์ •๋ณด, Exception ์ •๋ณด ๋“ฑ์„ ๋””์Šค์ฝ”๋“œ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ์„œ๋น„์Šค - GitHub - junyharang-personal-project/junyss-total-back-office: [Back-Office] ๋””์Šค์ฝ”๋“œ

github.com

 

 

 

โ€จ

 

 

๐Ÿš€ AOP, Annotation์„ ์ด์šฉํ•œ API ๋™์ž‘ ์‹œ๊ฐ„ ์ธก์ •

    ๐Ÿ”ฝ  ๊ฐœ์š”

        ๐Ÿ“ฆ ์†Œ๊ฐœ

์ตœ๊ทผ ์ฃผ๋‹ˆ๊ฐ€ ์ง„ํ–‰ํ•œ ํ”„๋กœ์ ํŠธ์—์„œ AOP์™€ Annotation์„ ๋งŒ๋“ค์–ด API ๋™์ž‘ ์‹œ๊ฐ„์„ ์ธก์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค์–ด ๋ณด์•˜์–ด์š”.
์ด์— ๋Œ€ํ•ด ์ •๋ฆฌํ•˜๊ณ , ๊ณต์œ ํ•ด๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

 

AOP๋ž€?

AOP์— ๋Œ€ํ•œ ๋‚ด์šฉ์€ ์ด ๊ณณ๊ณผ ์ด ๊ณณ์— ์ •๋ฆฌํ•ด ๋‘์—ˆ์–ด์š”.

 

[Spring] Spring AOP; ์Šคํ”„๋ง AOP ๊ฐœ๋… ์ •๋ฆฌ

๐Ÿš€ ์Šคํ”„๋ง AOP ๊ฐœ๋… ์ •๋ฆฌ ๐Ÿ”ฝ ์ด๋ก  ๐Ÿ“ฆ AOP๋ž€? AOP๋Š” Aspect Oriented Programming์˜ ์•ฝ์ž๋กœ ๊ด€์  ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด๋ผ๊ณ  ๋ถ€๋ฅด๊ณ  ์žˆ์–ด์š”. ์ด๊ฒƒ์€ ์–ด๋–ค ๋กœ์ง ๊ธฐ์ค€ ํ•ต์‹ฌ์ ์ธ ๊ด€์ ๊ณผ ๋ถ€๊ฐ€์ ์ธ ๊ด€์ ์„ ๋‚˜๋ˆ„๊ณ ,

junyharang.tistory.com

๋ฐ˜์‘ํ˜•
 

[Spring Boot] AOP

์•ˆ๋…•ํ•˜์„ธ์š”? ์ฃผ๋‹ˆํ•˜๋ž‘ ์ž…๋‹ˆ๋‹ค. ์˜ค๋Š˜์€ AOP์— ๋Œ€ํ•ด ๊ณต๋ถ€ ํ•ด ๋ณด๋„๋ก ํ•  ๊ฒƒ์ด์—์š”. ๋ฐ”๋กœ ์‹œ์ž‘ ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! ์ฝ”๋“œ์— ๊ด€๋ จํ•œ ๋‚ด์šฉ์€ ์ฃผ๋‹ˆํ•˜๋ž‘์˜ Github์—์„œ ํ™•์ธ ํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค! ๐Ÿ“‹ ๋ชฉ์ฐจ 01.[Spring Boo

junyharang.tistory.com

 

Annotation์ด๋ž€?

์–ด๋…ธํ…Œ์ด์…˜์— ๋Œ€ํ•œ ๋‚ด์šฉ์€ ์ด ๊ณณ์— ์ •๋ฆฌํ•ด ๋‘์—ˆ์–ด์š”.

 

[Java] Annotation (์–ด๋…ธํ…Œ์ด์…˜) ์ด๋ž€?

์Šคํ”„๋ง ๋ถ€ํŠธ 3 ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž ๋˜๊ธฐ : ์ž๋ฐ” ํŽธ COUPANG www.coupang.com "์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค." ๐Ÿš€ Annotaion (์–ด๋…ธํ…Œ์ด์…˜) ์ด๋ž€? ๐Ÿ”ฝ ๊ฐœ

junyharang.tistory.com

 

 

 

 

    ๐Ÿ”ฝ  ์†Œ์Šค ์ฝ”๋“œ ๋ถ„์„

        ๐Ÿ“ฆ TimeTraceAop.java

์ตœ์ดˆ AOP Class๋ฅผ ๋จผ์ € ํ™•์ธํ•ด ๋ณผ๊ฒŒ์š”.

TimeTraceAop.java 1 ~ 23๋ฒˆ์งธ ์ค„

์ตœ์ดˆ 21๋ฒˆ์งธ ์ค„ Annotation์€ ๋ถ€๊ฐ€์  ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ๋‚ด์šฉ๋“ค์„ ๋ชจ๋“ˆํ™” ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๊ณตํ†ต์œผ๋กœ ์ ์šฉํ•  ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•  ๋•Œ ๋ช…์‹œํ•ด ์ฃผ๊ณ  ์žˆ์–ด์š”. ์ฆ‰, ํ•ด๋‹น Class๊ฐ€ ๋ถ€๊ฐ€ ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ Class๋ผ๋Š” ๊ฒƒ์„ ์•Œ๋ ค์ฃผ๋Š” Annotaion์ด์—์š”.

๊ทธ๋ฆฌ๊ณ  @Component๋Š” AOP๋ฅผ Spring Bean์— ๋“ฑ๋กํ•˜๊ธฐ ์œ„ํ•ด ๋ช…์‹œํ•ด ์ฃผ์—ˆ์–ด์š”. ์ด๋Š” @Aspect๋ฅผ ๋ช…์‹œํ–ˆ๋‹ค๊ณ  ํ•ด์„œ
์ž๋™์œผ๋กœ Spring Bean์— ๋“ฑ๋ก๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋”ฐ๋กœ Bean ๋“ฑ๋ก์„ ์œ„ํ•ด ์‚ฌ์šฉํ•ด ์ค€ ๊ฒƒ์ด์—์š”. ์ด ๋ฐฉ๋ฒ• ์™ธ์—๋„ SpringConfig์˜ @Bean์„ ์‚ฌ์šฉํ•˜์—ฌ ๋“ฑ๋กํ•  ์ˆ˜๋„ ์žˆ์–ด์š”.

 

 

TimeTraceAop.java 25 ~ 56๋ฒˆ์งธ ์ค„


32๋ฒˆ์งธ ์ค„์— @Around ์–ด๋…ธํ…Œ์ด์…˜์€ ๋Œ€์ƒ Entity Method ์‹คํ–‰ ์ „, ํ›„ ๋˜๋Š” ์˜ˆ์™ธ ๋ฐœ์ƒ ์‹œ์ ์— ๊ณตํ†ต ๊ธฐ๋Šฅ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๋ช…์‹œํ•œ ๊ฒƒ์ด์—์š”. ์ด ๋ถ€๋ถ„์€ Advice์˜ ํ•œ ์ข…๋ฅ˜๋กœ ํ•ต์‹ฌ ๊ด€์‹ฌ์‚ฌ์˜ ์‹คํŒจ ์—ฌ๋ถ€์™€ ์ƒ๊ด€์—†์ด ์‹คํ–‰๋˜๋„๋ก ํ•˜๋Š” Advice๋ฅผ ์˜๋ฏธํ•ด์š”.

๋งŒ์•ฝ ํŠน์ • Directory ์ „์ฒด์— ์ ์šฉํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
@Around์˜ execution

// hello.hellospring ๋ฐ‘์— ๋ชจ๋“  ๋‚ด์šฉ์— ์•„๋ž˜ Method ๋ชจ๋‘ ์ ์šฉ
@Around("execution(* hello.hellospring..*(..))")


์—ฌ๊ธฐ์„œ execution์€ ์ ‘๊ทผ ์ œ์–ด์ž, ๋ฐ˜ํ™˜ํ˜• Package๋ฅผ ํฌํ•จํ•œ Class ๊ฒฝ๋กœ์— ๋Œ€ํ•œ ๋ฉ”์†Œ๋“œ ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ๋„ฃ์–ด ์ค„ ์ˆ˜ ์žˆ์–ด์š”.

์ฒซ๋ฒˆ์งธ์— ๋ช…์‹œ ๋œ [*]์€ ์ ‘๊ทผ ์ œ์–ด์ž์™€ ๋ฐ˜ํ™˜ํ˜• ๋ชจ๋‘ ์ƒ๊ด€ํ•˜์ง€ ์•Š๊ณ , ์ ์šฉํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์ด๊ณ , hello๋Š” Project Directory ์ค‘ java ๋ฐ‘์— ์žˆ๋Š” Package ์ด๋ฆ„์ด๋ฉฐ, ๊ทธ ๋‹ค์Œ์€ hellospring์ผ ๋•Œ, hello ๋ฐ‘์— ๋ชจ๋“  Directory์— ๋Œ€ํ•ด ์•„๋ž˜ ๋ช…์‹œ๋œ ๊ธฐ๋Šฅ์„ ์‹คํ–‰ํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์ด๊ณ , [(..)]์€ Method Parameter๊ฐ€ ๋ช‡ ๊ฐœ๊ฐ€ ์กด์žฌํ•˜๋˜์ง€ ์ƒ๊ด€ ์—†์ด ์‹คํ–‰ํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์—์š”.

728x90


@annotion(....) ์˜๋ฏธ๋Š” ํ•ด๋‹น ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•œ ๋ฉ”์†Œ๋“œ์— @Around๋ฅผ ์ ์šฉ ์‹œํ‚ค๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์—์š”.
์ฆ‰, ์ฃผ๋‹ˆ๊ฐ€ ์ •์˜ํ•œ ....ExecutionTimeCheck์ด๋ผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜์œผ๋กœ ๋ฉ”์†Œ๋“œ์˜ ์‹คํ–‰ ์‹œ๊ฐ„์„ ์ฒดํฌํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์—์š”.

excute() ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ ProceedingJoinPoint ๊ฐ์ฒด๋ฅผ ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌํ•ด ์ฃผ์—ˆ์–ด์š”.
ProceedingJoinPoint๋Š” ์Šคํ”„๋ง AOP์—์„œ ์‚ฌ์šฉ๋˜๋Š” Interface๋กœ AOP ์ ์šฉ ๋ฉ”์†Œ๋“œ์˜ ์‹คํ–‰์„ ์ œ์–ดํ•˜๊ณ ,
์ถ”๊ฐ€ ๋™์ž‘์„ ์‚ฝ์ž…ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณต
ํ•ด์š”.

ProceedingJoinPoint ๊ฐ์ฒด๋Š” @Around๊ฐ€ ์ ์šฉ๋œ ๋ฉ”์†Œ๋“œ์— ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ๋˜๋Š”๋ฐ, ์ด ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด AOP๊ฐ€ ์ ์šฉ๋œ ๋ฉ”์†Œ๋“œ์˜ ์‹คํ–‰์„ ์ง์ ‘ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.

ProceedingJoinPoint ์ธํ„ฐํŽ˜์ด์Šค์—๋Š” ๋‹ค์–‘ํ•œ ๋ฉ”์†Œ๋“œ๊ฐ€ ์žˆ์–ด์š”.
๊ทธ ์ค‘์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ฉ”์†Œ๋“œ๋Š” proceed()์ธ๋ฐ, ์ด ์นœ๊ตฌ๋Š” AOP๊ฐ€ ์ ์šฉ๋œ ๋ฉ”์†Œ๋“œ์˜ ์‹ค์ œ ์‹คํ–‰์„ ํ˜ธ์ถœํ•˜๋Š” ์—ญํ• ์„ ํ•˜๊ณ  ์žˆ์–ด์š”. ๋˜ํ•œ, object๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ , AOP๊ฐ€ ์ ์šฉ๋œ ๋ฉ”์†Œ๋“œ์˜ ๋ฐ˜ํ™˜๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜๋„ ์žˆ๋„๋ก ํ•ด์ค€๋‹ต๋‹ˆ๋‹ค.
๋˜ํ•œ, ProceedingJoinPoint ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด AOP๊ฐ€ ์ ์šฉ๋œ ๋ฉ”์†Œ๋“œ์˜ ๋งค๊ฐœ ๋ณ€์ˆ˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ฑฐ๋‚˜, ๋ณ€๊ฒฝํ•  ์ˆ˜๋„ ์žˆ์–ด์š”.
์˜ˆ๋ฅผ ๋“ค์–ด joinPoint.getArgs()๋ฅผ ํ†ตํ•ด ๋ฉ”์†Œ๋“œ์˜ ๋งค๊ฐœ ๋ณ€์ˆ˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜๋„ ์žˆ๋‹ต๋‹ˆ๋‹ค.

์ •๋ฆฌํ•˜๋ฉด ProceedingJoinPoint ๊ฐ์ฒด๋Š” AOP๊ฐ€ ์ ์šฉ๋œ ๋ฉ”์†Œ๋“œ์˜ ์‹คํ–‰์„ ์ œ์–ดํ•˜๊ณ , ํ•ด๋‹น ๋ฉ”์†Œ๋“œ์˜ ๋งค๊ฐœ ๋ณ€์ˆ˜ ๊ฐ’์ด๋‚˜,
๋ฐ˜ํ™˜๊ฐ’ ๋“ฑ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณต
ํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ž๋‹ˆ๋‹ค.


34๋ฒˆ์งธ ์ค„์—์„œ ์ตœ์ดˆ ๋ฉ”์†Œ๋“œ ๋™์ž‘ ์‹œ๊ฐ„์„ ์žก๊ธฐ ์œ„ํ•ด System.currentTimeMillis()๋ฅผ ํ†ตํ•ด ms ๋‹จ์œ„์˜ ์‹œ์ž‘ ์‹œ๊ฐ„์„ startTime ๋ณ€์ˆ˜์— ๋‹ด์•„ ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋Ÿฐ ๋’ค joinPoint.toString()๋ฅผ ํ†ตํ•ด ProceedingJoinPoint ๊ฐ์ฒด์˜ ๋ฌธ์ž์—ด ํ‘œํ˜„ ๋ฐ˜ํ™˜์„ ๋ฐ›๊ฒŒ ๋˜๋Š”๋ฐ, ์ด๋ฅผ ํ†ตํ•ด ProceedingJoinPoint ๊ฐ์ฒด์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ํฌํ•จ๋œ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ ๋ฐ›์„ ์ˆ˜ ์žˆ์–ด์š”.

์ฆ‰, ์ฃผ๋‹ˆ๋Š” AOP๊ฐ€ ์ ์šฉ๋œ ๋ฉ”์†Œ๋“œ์˜ ์‹œ๊ทธ๋‹ˆ์ฒ˜ ๋ฐ ๋งค๊ฐœ ๋ณ€์ˆ˜๊ฐ’์„ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜์—ฌ ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋Ÿฐ ๋’ค 41๋ฒˆ์งธ ์ค„์—์„œ proceed()์˜ ๋‚ด์šฉ์„ ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ํ•ด ์ฃผ์–ด AOP๊ฐ€ ์ ์šฉ๋œ ๋ฉ”์†Œ๋“œ์˜ ์‹คํ–‰์„ ํ˜ธ์ถœํ•˜๊ณ , ํ•ด๋‹น ๋ฉ”์†Œ๋“œ์˜ ๋ฐ˜ํ™˜๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ํ•ด ์ฃผ์—ˆ์–ด์š”.

44๋ฒˆ์งธ ์ค„์—์„œ๋Š” ์ž„์˜๋กœ ์ •ํ•œ 500ms๊ฐ€ ๋„˜์œผ๋ฉด ๋™์ž‘ ์‹œ๊ฐ„์ด ์˜ค๋ž˜ ๊ฑธ๋ฆฐ๋‹ค๋Š” ํŒ๋‹จ์„ ํ•˜๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜์ด๊ณ , 45๋ฒˆ์งธ ์ค„์€ 5000ms๋ฅผ ๋„˜์œผ๋ฉด ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง์ด ํ•„์š”ํ•˜๋‹ค๊ณ  ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ์ค€๊ฐ’์„ ์žก์•„์ค€ ๋ณ€์ˆ˜์—์š”.

๊ทธ๋Ÿฐ ๋’ค 46๋ฒˆ์งธ ์ค„์—์„œ ๋™์ž‘์ด ๋๋‚œ ms๋ฅผ ์žก๊ฒŒ ํ•ด์ฃผ๊ณ , 47๋ฒˆ์งธ ์ค„์—์„œ ๋๋‚œ ms์—์„œ ์‹œ์ž‘ ms๋ฅผ ๋นผ progressMethodMsTime ๋ณ€์ˆ˜์— ๋‹ด์•„ ์ฃผ์—ˆ์–ด์š”.

48๋ฒˆ์งธ ์ค„์—์„œ๋Š” ํ˜„์žฌ ๊ธฐ๋™๋˜๊ณ  ์žˆ๋Š” Application ๊ตฌ๋™ ํ™˜๊ฒฝ์„ ์ฒดํฌํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ ๋ถ€๋ถ„์ด์—์š”.

๊ทธ๋ฆฌ๊ณ , 50 ~ 56๋ฒˆ์งธ ์ค„์„ ํ†ตํ•ด ๋™์ž‘ ์†Œ์š” ์‹œ๊ฐ„์„ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋„๋ก ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.
55๋ฒˆ์งธ ์ค„์—์„œ๋Š” ์†Œ์ˆ˜์  3๋ฒˆ์งธ ์ž๋ฆฌ๊นŒ์ง€ ms ๋‹จ์œ„๋ฅผ ๋ฐ˜์˜ฌ๋ฆผ ํ•œ ๋’ค 1000์œผ๋กœ ๋‚˜๋ˆ„์–ด ์ฆ‰, ์ดˆ ๋‹จ์œ„๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ถœ๋ ฅ๋  ์ˆ˜ ์žˆ๋„๋ก ํ•œ ๊ฒƒ์ด์—์š”.

 

TimeTraceAop.java 58 ~ 80๋ฒˆ์งธ ์ค„


58๋ฒˆ์งธ ์ค„์—์„œ ๋™์ž‘ ์†Œ์š” ms ๊ธฐ์ค€ ๋ณด๋‹ค ํ˜„์žฌ ๊ตฌ๋™ ์†Œ์š” ์‹œ๊ฐ„์ด ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ฑฐ๋‚˜, ํ˜น์€ ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง์ด ํ•„์š”ํ•œ ๊ธฐ์ค€ ms ๋ณด๋‹ค ์ž‘์œผ๋ฉด ํ•ด๋‹น ๋ถ„๊ธฐ๋ฌธ์ด ์ง„ํ–‰๋˜๋„๋ก ํ•˜์˜€์–ด์š”.

๊ทธ๋Ÿฐ ๋’ค 60๋ฒˆ์งธ ์ค„์—์„œ Application ๊ตฌ๋™ ํ™˜๊ฒฝ์ด ๋กœ์ปฌ์ธ์ง€ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์ธ์ง€๋ฅผ ์ฒดํฌํ•˜๊ณ , ๋งž๋‹ค๋ฉด longTimeExceptionHandler() ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ProceedingJoinPoint ๊ฐ์ฒด์™€ ๊ตฌ๋™ ์†Œ์š” ์‹œ๊ฐ„ ๊ฐ’์„ ์ „๋‹ฌํ•ด ์ค๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์šด์˜ ํ™˜๊ฒฝ์ด๋ผ๋ฉด longTimeExceptionHandler()๋Š” ํ˜ธ์ถœ๋˜์ง€ ์•Š๊ณ ,
ํ•ด๋‹น ๋‚ด์šฉ๋งŒ log์˜ warnning Level๋กœ ์ถœ๋ ฅํ•˜๊ฒŒ ์ฒ˜๋ฆฌ ํ•ด ์ฃผ์—ˆ์–ด์š”.


TimeTraceAop.java 82 ~ 103๋ฒˆ์งธ ์ค„


์ด ๊ณณ์—์„œ๋Š” ๊ตฌ๋™ ์†Œ์š” ์‹œ๊ฐ„์ด ์œ„ํ—˜ ๊ธฐ์ค€ ์‹œ๊ฐ„ ๋ณด๋‹ค ๋†’๋‹ค๋ฉด log์˜ error Level๋กœ ์ถœ๋ ฅํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•œ ๊ณณ์ด๊ณ , ์—ญ์‹œ ์šด์˜ ํ™˜๊ฒฝ์ด๊ฑฐ๋‚˜, ๋กœ์ปฌ ํ™˜๊ฒฝ์—์„œ๋งŒ veryLongTimeExceptionHanlder()๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ProceedingJoinPoint ๊ฐ์ฒด์™€ ๊ตฌ๋™ ์†Œ์š” ์‹œ๊ฐ„ ๊ฐ’์„ ์ „๋‹ฌํ•ด ์ฃผ์—ˆ์–ด์š”.




TimeTraceAop.java 117 ~ 149๋ฒˆ์งธ ์ค„


์œ„์—์„œ ๊ฐ๊ฐ ํ˜ธ์ถœํ–ˆ๋˜ ๋ฉ”์†Œ๋“œ๋“ค์ด์—์š”.

์ตœ์ดˆ longTimeExceptionHanlder()๋Š” Exception์„ ๋˜์ง€๊ฒŒ ๋˜๋Š”๋ฐ, TimeTraceException์„ ํ„ฐํŠธ๋ฆฌ๊ฒŒ ๋˜๊ณ ,
ํ•ด๋‹น ๋ฉ”์†Œ๋“œ ๋™์ž‘ ์†Œ์š” ์‹œ๊ฐ„์ด 500ms ์ด์ƒ ์†Œ์š”๋œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๋ ค์ฃผ๊ธฐ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ์—์š”.


๋งˆ์ฐฌ๊ฐ€์ง€๋กœ veryLongTimeExceptionHandler() TimeTraceException์„ ํ„ฐํŠธ๋ ค์„œ
์œ„ํ—˜์ด๋ผ๊ณ  ํŒ๋‹จ๋  ์†Œ์š” ์‹œ๊ฐ„ ๋ณด๋‹ค ๋” ์˜ค๋ž˜ ๊ฑธ๋ฆผ์„ ์•Œ๋ ค์ฃผ๊ธฐ ์œ„ํ•ด ์ฒ˜๋ฆฌํ•œ ๋ถ€๋ถ„์ด์—์š”.

๋‹ค๋ฅธ ๊ธ€์—์„œ ์ž‘์„ฑํ•  ์˜ˆ์ •์ธ Log Back์„ ์ด์šฉํ•˜์—ฌ ์ฃผ๋‹ˆ๋Š” Exception์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ๋””์Šค์ฝ”๋“œ๋กœ ๋ฐ›๊ณ  ์žˆ๋Š”๋ฐ,
์ด๋ฅผ ์œ„ํ•ด์„œ ์ฒ˜๋ฆฌํ•ด ์ค€ ๋ถ€๋ถ„์ด์—์š”.

 

 

 

        ๐Ÿ“ฆ ExecutionTimeCheck.java

ExecutionTimeCheck.java


์–ด๋…ธํ…Œ์ด์…˜์„ ์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.

@Target์„ ํ†ตํ•ด ๋ฉ”์†Œ๋“œ์—์„œ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค๊ณ  ์ •์˜ ํ•ด์ฃผ๊ณ , @Retention์„ ํ†ตํ•ด
ํ•ด๋‹น ์–ด๋…ธํ…Œ์ด์…˜์ด Runtime ๊นŒ์ง€ ์œ ์ง€ ๋˜๋„๋ก ์„ค์ •ํ•˜์—ฌ ์‹œ๊ฐ„ ์ธก์ •์„ ์›ํ•˜๋Š” Method์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.










        ๐Ÿ“ฆ ์–ด๋…ธํ…Œ์ด์…˜ ๋ช…์‹œ

 

๊ทธ๋Ÿฐ ๋’ค 22๋ฒˆ์งธ ์ค„๊ณผ ๊ฐ™์ด Controller Method์— ํ•ด๋‹น ์–ด๋…ธํ…Œ์ด์…˜์„ ๋ช…์‹œํ•ด ์ฃผ๋ฉด LogbackTest()๊ฐ€ ๋™์ž‘ํ•  ๋•Œ,
API ๋™์ž‘ ์‹œ๊ฐ„์„ ์ธก์ •ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.



[2023-07-15] [17:36:04.472] [INFO] 3735 [DirectJDKLog.java] log (173) : Initializing Spring DispatcherServlet 'dispatcherServlet'
[2023-07-15] [17:36:04.473] [INFO] 3735 [FrameworkServlet.java] initServletBean (525) : Initializing Servlet 'dispatcherServlet'
[2023-07-15] [17:36:04.474] [INFO] 3735 [FrameworkServlet.java] initServletBean (547) : Completed initialization in 1 ms
[2023-07-15] [17:36:04.478] [INFO] 3735 [ServletWrappingFilter.java] doFilterInternal (25) : url : /api/test/web-hook
[2023-07-15] [17:36:05.143] [INFO] 3735 [TimeTraceAop.java] execute (36) : Method ๋™์ž‘ ์‹œ๊ฐ„ ํ™•์ธ ์‹œ์ž‘ : execution(String com.giggalpeople.backoffice.api.webhook.test.WebHookTestController.logbackTest())์˜ ๋™์ž‘ ์‹œ๊ฐ„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
[2023-07-15] [17:36:05.146] [INFO] 3735 [WebHookTestController.java] logbackTest (29) : Discord ๋ฐ Console LogBack Test ์ค‘ ์ž…๋‹ˆ๋‹ค! ์ถœ๋ ฅ Error ๋‹จ๊ณ„๋ฅผ ํ™•์ธ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค! 
Info ๋‹จ๊ณ„ Log ์ถœ๋ ฅ์ž…๋‹ˆ๋‹ค! 
[2023-07-15] [17:36:05.146] [WARN] 3735 [WebHookTestController.java] logbackTest (31) : Discord ๋ฐ Console LogBack Test ์ค‘ ์ž…๋‹ˆ๋‹ค! ์ถœ๋ ฅ Error ๋‹จ๊ณ„๋ฅผ ํ™•์ธ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค! 
warning ๋‹จ๊ณ„ Log ์ถœ๋ ฅ ์ž…๋‹ˆ๋‹ค!
[2023-07-15] [17:36:05.148] [ERROR] 3735 [WebHookTestController.java] logbackTest (32) : Discord ๋ฐ Console LogBack Test ์ค‘ ์ž…๋‹ˆ๋‹ค! ์ถœ๋ ฅ Error ๋‹จ๊ณ„๋ฅผ ํ™•์ธ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค! 
error ๋‹จ๊ณ„ Log ์ถœ๋ ฅ ์ž…๋‹ˆ๋‹ค!
[2023-07-15] [17:36:05.152] [INFO] 3735 [TimeTraceAop.java] execute (50) : Method ๋™์ž‘ ์‹œ๊ฐ„ ๊ฒ€์ฆ ์™„๋ฃŒ : execution(String com.giggalpeople.backoffice.api.webhook.test.WebHookTestController.logbackTest()) Method ๋™์ž‘ ์‹œ๊ฐ„์€ 6ms (0.006)์ดˆ ์ž…๋‹ˆ๋‹ค.
[2023-07-15] [17:36:05.153] [INFO] 3735 [TimeTraceAop.java] execute (106) : Method ๋™์ž‘ ์‹œ๊ฐ„ ๊ฒ€์ฆ ์™„๋ฃŒ : execution(String com.giggalpeople.backoffice.api.webhook.test.WebHookTestController.logbackTest()) Method ๋™์ž‘ ์‹œ๊ฐ„์€ 6ms (0.006)์ดˆ ์ž…๋‹ˆ๋‹ค.

 
์œ„์™€ ๊ฐ™์ด ์ฝ˜์†”์—์„œ ์ถœ๋ ฅ๋˜๋Š” ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

 

 

 

 

 

 

์Šคํ”„๋ง ๋ถ€ํŠธ 3 ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž ๋˜๊ธฐ : ์ž๋ฐ” ํŽธ

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•