Skip to content

Commit

Permalink
refactor: actuator health 엔드포인트 설정 변경 (#303)
Browse files Browse the repository at this point in the history
* feat: actuator health 엔드포인트 설정 변경

* refactor: AdminInterceptor log level 변경

---------

Co-authored-by: Juhwan Kim <[email protected]>
  • Loading branch information
kunsanglee and 3Juhwan authored Aug 12, 2024
1 parent 15ab738 commit 85add2d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
public class HaengdongApplication {

public static void main(String[] args) {
log.error("################### 안녕하세요. CI/CD 테스트입니다. ###################");
SpringApplication.run(HaengdongApplication.class, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public AdminInterceptor(AuthService authService, AuthenticationExtractor authent

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
log.trace("login request = {}", request.getRequestURI());
log.debug("login request = {}", request.getRequestURI());

String requestURI = request.getRequestURI();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,35 @@ public class GlobalExceptionHandler {

@ExceptionHandler(AuthenticationException.class)
public ResponseEntity<ErrorResponse> authenticationException(AuthenticationException e) {
log.warn(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.body(ErrorResponse.of(e.getErrorCode()));
}

@ExceptionHandler({HttpRequestMethodNotSupportedException.class, NoResourceFoundException.class})
public ResponseEntity<ErrorResponse> noResourceException() {
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<ErrorResponse> noResourceException(HttpRequestMethodNotSupportedException e) {
log.warn(e.getMessage(), e);
return ResponseEntity.badRequest()
.body(ErrorResponse.of(HaengdongErrorCode.REQUEST_METHOD_NOT_SUPPORTED));
}

@ExceptionHandler(NoResourceFoundException.class)
public ResponseEntity<ErrorResponse> noResourceException(NoResourceFoundException e) {
log.warn(e.getMessage(), e);
return ResponseEntity.badRequest()
.body(ErrorResponse.of(HaengdongErrorCode.NO_RESOURCE_REQUEST));
}

@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ErrorResponse> httpMessageNotReadableException() {
public ResponseEntity<ErrorResponse> httpMessageNotReadableException(HttpMessageNotReadableException e) {
log.warn(e.getMessage(), e);
return ResponseEntity.badRequest()
.body(ErrorResponse.of(HaengdongErrorCode.MESSAGE_NOT_READABLE));
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
log.info(e.getMessage(), e);
log.warn(e.getMessage(), e);
String errorMessage = e.getFieldErrors().stream()
.map(error -> error.getField() + " " + error.getDefaultMessage())
.collect(Collectors.joining(", "));
Expand All @@ -46,7 +56,7 @@ public ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(Metho

@ExceptionHandler(HaengdongException.class)
public ResponseEntity<ErrorResponse> haengdongException(HaengdongException e) {
log.info(e.getMessage(), e);
log.warn(e.getMessage(), e);
return ResponseEntity.badRequest()
.body(ErrorResponse.of(e.getErrorCode()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public enum HaengdongErrorCode {
/* System */,

MESSAGE_NOT_READABLE("읽을 수 없는 요청입니다."),
REQUEST_METHOD_NOT_SUPPORTED("지원하지 않는 요청 메서드입니다."),
NO_RESOURCE_REQUEST("존재하지 않는 자원입니다."),
INTERNAL_SERVER_ERROR("서버 내부에서 에러가 발생했습니다.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class EventController {

@PostMapping("/api/events")
public ResponseEntity<EventResponse> saveEvent(@Valid @RequestBody EventSaveRequest request) {
log.error("################### 안녕하세요. CI/CD 테스트입니다. ###################");

EventResponse eventResponse = EventResponse.of(eventService.saveEvent(request.toAppRequest()));

String jwtToken = authService.createToken(eventResponse.eventId());
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ management:
endpoints:
web:
exposure:
include: logfile, metrics
include: health, metrics, logfile

logging:
level:
Expand Down
3 changes: 2 additions & 1 deletion server/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} - %msg%n</pattern>
<!-- 날짜, 시간, 로그 레벨, 스레드 이름, 로거 이름, 메시지 형식 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

Expand Down

0 comments on commit 85add2d

Please sign in to comment.