-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 비즈니스 로직 호출 Counter 메트릭 AOP 추가 * refactor: 패키지 위치 및 클래스 네이밍 변경 * fix: Counter 메트릭에서 주요 비즈니스 로직이 아닌 api는 제외하도록 변경
- Loading branch information
Showing
2 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
backend/ddang/src/main/java/com/ddang/ddang/configuration/metric/LogicMetricAop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.ddang.ddang.configuration.metric; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import lombok.RequiredArgsConstructor; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
|
||
@Aspect | ||
@Component | ||
@RequiredArgsConstructor | ||
public class LogicMetricAop { | ||
|
||
private final MeterRegistry registry; | ||
|
||
@Pointcut("@within(org.springframework.web.bind.annotation.RestController)") | ||
private void restControllerAnnotatedClass() { | ||
} | ||
|
||
@Pointcut("within(com.ddang.ddang.image.presentation.ImageController)") | ||
private void imageControllerClass() { | ||
} | ||
|
||
@Pointcut("within(com.ddang.ddang.region.presentation.RegionController)") | ||
private void regionControllerClass() { | ||
} | ||
|
||
@Pointcut("within(com.ddang.ddang.category.presentation.CategoryController)") | ||
private void categoryControllerClass() { | ||
} | ||
|
||
@Pointcut("within(com.ddang.ddang.report.presentation.ReportController)") | ||
private void reportControllerClass() { | ||
} | ||
|
||
@Pointcut("within(com.ddang.ddang.device.presentation.DeviceTokenController)") | ||
private void deviceTokenControllerClass() { | ||
} | ||
|
||
@Pointcut("within(com.ddang.ddang.authentication.presentation.AuthenticationController)") | ||
private void authenticationControllerClass() { | ||
} | ||
|
||
@Around("restControllerAnnotatedClass() && !imageControllerClass() && !regionControllerClass() && " | ||
+ "!categoryControllerClass() && !reportControllerClass() && !deviceTokenControllerClass() && " | ||
+ "!authenticationControllerClass()") | ||
public Object doLog(final ProceedingJoinPoint joinPoint) throws Throwable { | ||
if (isRequestScope()) { | ||
final String className = findClassSimpleName(joinPoint); | ||
final String methodName = findMethodName(joinPoint); | ||
|
||
Counter.builder("logic") | ||
.tag("class", className) | ||
.tag("method", methodName) | ||
.tag("class.method", formattedTag(className, methodName)) | ||
.description("비즈니스 로직 메트릭") | ||
.register(registry) | ||
.increment(); | ||
} | ||
|
||
return joinPoint.proceed(); | ||
} | ||
|
||
private boolean isRequestScope() { | ||
return RequestContextHolder.getRequestAttributes() != null; | ||
} | ||
|
||
private String findClassSimpleName(final ProceedingJoinPoint joinPoint) { | ||
final Class<?> clazz = joinPoint.getTarget().getClass(); | ||
|
||
return clazz.getSimpleName(); | ||
} | ||
|
||
private String findMethodName(final ProceedingJoinPoint joinPoint) { | ||
return joinPoint.getSignature().getName(); | ||
} | ||
|
||
private String formattedTag(final String className, final String methodName) { | ||
return className + "." + methodName; | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...onfiguration/MonitoringConfiguration.java → ...iguration/metric/MetricConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters