From 8f3c34f1ce25eef240a6b4fa27778e9c9dd8dd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=A7=80=EC=9B=90?= Date: Fri, 1 Nov 2024 16:17:15 +0900 Subject: [PATCH] refactor : clean up code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - final 클래스 및 변수 --- .../com/univ/tracedin/api/alert/AlertApi.java | 4 +++ .../com/univ/tracedin/api/auth/AuthApi.java | 8 +++-- .../exception/AuthenticationException.java | 2 +- .../auth/exception/ExpiredTokenException.java | 2 +- .../auth/exception/InvalidTokenException.java | 2 +- .../auth/exception/NoPermissionException.java | 2 +- .../tracedin/api/global/aop/LogAspect.java | 31 +++++++++-------- .../api/global/config/ModuleConfig.java | 2 +- .../exception/GlobalControllerAdvice.java | 4 +-- .../security/JwtAuthenticationEntryPoint.java | 2 +- .../security/JwtAuthenticationFilter.java | 20 +++++------ .../api/global/security/JwtTokenizer.java | 34 +++++++++---------- .../global/security/SecurityConstants.java | 2 ++ .../global/security/SecurityProperties.java | 16 ++++----- .../tracedin/api/global/sse/SseConnector.java | 2 +- .../tracedin/api/global/sse/SseSender.java | 2 +- .../sse/exception/SseConnectionException.java | 2 +- .../api/global/util/GrpcMappingUtils.java | 4 ++- .../tracedin/api/global/util/TokenUtils.java | 8 +++-- .../api/metric/ServiceMetricsApi.java | 3 +- .../api/metric/grpc/ServiceMetricsGrpc.java | 7 ++-- .../com/univ/tracedin/api/span/SpanApi.java | 6 ++-- .../univ/tracedin/api/span/grpc/SpanGrpc.java | 6 ++-- .../common/constants/TracedInConstants.java | 4 ++- .../tracedin/common/dto/SearchResult.java | 2 +- .../com/univ/tracedin/domain/alert/Alert.java | 2 +- .../tracedin/domain/alert/AlertMethod.java | 2 +- .../domain/alert/AlertMethodManager.java | 2 +- .../tracedin/domain/alert/AlertSender.java | 2 +- .../tracedin/domain/alert/AlertService.java | 6 ++-- .../tracedin/domain/anomaly/AnomalyTrace.java | 2 +- .../domain/anomaly/AnomalyTraceProcessor.java | 8 ++--- .../tracedin/domain/auth/AuthConstants.java | 4 ++- .../domain/auth/UserAuthenticator.java | 4 +-- .../univ/tracedin/domain/global/BaseId.java | 9 ++++- .../metric/ServiceMetricsCollectedEvent.java | 2 +- .../ServiceMetricsMessageProcessor.java | 2 +- .../domain/metric/ServiceMetricsReader.java | 12 ------- .../univ/tracedin/domain/project/HttpTps.java | 2 +- .../univ/tracedin/domain/project/Project.java | 5 +-- .../domain/project/ProjectAppender.java | 4 +-- .../domain/project/ProjectMember.java | 2 +- .../domain/project/ProjectMemberManager.java | 2 +- .../domain/project/ProjectReader.java | 4 +-- .../tracedin/domain/span/SpanService.java | 2 +- .../univ/tracedin/domain/span/SpanStatus.java | 2 +- .../univ/tracedin/domain/span/SpanTree.java | 4 +-- .../tracedin/domain/span/SpanTreeBuilder.java | 8 +++-- .../com/univ/tracedin/domain/span/Trace.java | 2 +- .../com/univ/tracedin/domain/user/User.java | 2 +- .../tracedin/domain/user/UserService.java | 12 ------- .../infra/alert/client/SlackAlertClient.java | 18 +++++----- .../infra/alert/entity/AlertEntity.java | 4 +-- .../infra/alert/entity/AlertMethodEntity.java | 5 +-- .../AlertMethodNotFoundException.java | 2 +- .../alert/exception/AlertSendException.java | 2 +- .../infra/anomaly/client/AnomalyDetector.java | 4 +-- .../listener/AnomalyTraceKafkaListener.java | 2 +- .../AnomalyTraceKafkaStreamsConfig.java | 2 +- .../streams/AnomalyTraceStreamProcessor.java | 16 ++++----- .../auth/cache/RefreshTokenCacheAdapter.java | 8 +++-- .../infra/auth/config/TokenRedisConfig.java | 2 +- .../infra/elasticsearch/ESSupplier.java | 1 + .../tracedin/infra/elasticsearch/ESUtils.java | 4 ++- .../config/ElasticSearchConfig.java | 6 ++-- .../infra/kafka/KafkaMessageHelper.java | 5 ++- .../metric/config/MetricRedisConfig.java | 4 +-- .../document/ServiceMetricsDocument.java | 2 +- .../listener/ServiceMetricsKafkaListener.java | 2 +- .../listener/ServiceMetricsRedisListener.java | 2 +- .../publish/ServiceMetricsKafkaPublisher.java | 1 + .../ServiceMetricsCoreRepository.java | 3 +- ...ricsElasticSearchRepositoryCustomImpl.java | 15 -------- .../infra/project/entity/ProjectEntity.java | 4 +-- .../project/entity/ProjectMemberEntity.java | 2 +- .../ProjectMemberNotFoundException.java | 2 +- .../exception/ProjectNotFoundException.java | 2 +- .../repository/ProjectRepositoryAdapter.java | 2 +- .../infra/span/document/SpanDocument.java | 2 +- .../exception/ElasticSearchException.java | 2 +- .../messaging/listener/SpanKafkaListener.java | 2 +- .../infra/user/entity/UserEntity.java | 2 +- .../user/exception/UserNotFoundException.java | 2 +- 83 files changed, 207 insertions(+), 210 deletions(-) delete mode 100644 tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsReader.java delete mode 100644 tracedin-domain/src/main/java/com/univ/tracedin/domain/user/UserService.java delete mode 100644 tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/repository/ServiceMetricsElasticSearchRepositoryCustomImpl.java diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/alert/AlertApi.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/alert/AlertApi.java index 3f61cbd..e83a1e4 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/alert/AlertApi.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/alert/AlertApi.java @@ -25,23 +25,27 @@ public class AlertApi implements AlertApiDocs { private final AlertService alertService; + @Override @PostMapping("/methods") public Response appendAlertMethod(AppendAlertMethodRequest request) { alertService.appendMethod(request.toAlertInfo()); return Response.success(); } + @Override @GetMapping("/methods") public Response> getAllAlertMethods(Long projectId) { return Response.success(alertService.readAllMethods(ProjectId.from(projectId))); } + @Override @PatchMapping("/methods/{alertMethodId}/deactivate") public Response deactivateAlertMethod(@PathVariable Long alertMethodId) { alertService.deactivateMethod(AlertMethodId.from(alertMethodId)); return Response.success(); } + @Override @PatchMapping("/methods/{alertMethodId}/activate") public Response activateAlertMethod(@PathVariable Long alertMethodId) { alertService.activateMethod(AlertMethodId.from(alertMethodId)); diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/AuthApi.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/AuthApi.java index cfd35f1..c4e1e8c 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/AuthApi.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/AuthApi.java @@ -25,16 +25,18 @@ public class AuthApi implements AuthApiDocs { private final AuthService authService; + @Override @PostMapping("/sign-up") public Response signup(@RequestBody SignUpRequest request) { - User signUpUser = authService.signUp(request.toUserProfile(), request.password()); + final User signUpUser = authService.signUp(request.toUserProfile(), request.password()); return Response.success(UserResponse.from(signUpUser)); } + @Override @PostMapping("/login") public ResponseEntity login(@RequestBody LoginRequest request) { - Tokens tokens = authService.login(request.toLoginInfo()); - HttpHeaders tokenHeaders = TokenUtils.createTokenHeaders(tokens); + final Tokens tokens = authService.login(request.toLoginInfo()); + final HttpHeaders tokenHeaders = TokenUtils.createTokenHeaders(tokens); return ResponseEntity.ok().headers(tokenHeaders).build(); } } diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/AuthenticationException.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/AuthenticationException.java index 7b8694f..4809e1a 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/AuthenticationException.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/AuthenticationException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.WebException; import com.univ.tracedin.domain.auth.exception.AuthErrorCode; -public class AuthenticationException extends WebException { +public final class AuthenticationException extends WebException { public static final AuthenticationException EXCEPTION = new AuthenticationException(); diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/ExpiredTokenException.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/ExpiredTokenException.java index a069440..f97d8a5 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/ExpiredTokenException.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/ExpiredTokenException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.WebException; import com.univ.tracedin.domain.auth.exception.AuthErrorCode; -public class ExpiredTokenException extends WebException { +public final class ExpiredTokenException extends WebException { public static final ExpiredTokenException EXCEPTION = new ExpiredTokenException(); diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/InvalidTokenException.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/InvalidTokenException.java index e54765e..9417fd3 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/InvalidTokenException.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/InvalidTokenException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.WebException; import com.univ.tracedin.domain.auth.exception.AuthErrorCode; -public class InvalidTokenException extends WebException { +public final class InvalidTokenException extends WebException { public static final InvalidTokenException EXCEPTION = new InvalidTokenException(); diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/NoPermissionException.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/NoPermissionException.java index 1af96de..11f472c 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/NoPermissionException.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/auth/exception/NoPermissionException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.WebException; import com.univ.tracedin.domain.auth.exception.AuthErrorCode; -public class NoPermissionException extends WebException { +public final class NoPermissionException extends WebException { public static final NoPermissionException EXCEPTION = new NoPermissionException(); diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/aop/LogAspect.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/aop/LogAspect.java index b7b8474..64f6408 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/aop/LogAspect.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/aop/LogAspect.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.regex.Pattern; import jakarta.servlet.http.HttpServletRequest; @@ -27,6 +28,8 @@ @RequiredArgsConstructor public class LogAspect { + private static final Pattern PATTERN = Pattern.compile("\\."); + @Pointcut( "execution(* com.univ.tracedin.domain..*(..)) || execution(* com.univ.tracedin.infra..*(..)) && !execution(* com.univ.tracedin.common..*(..))") public void all() {} @@ -37,29 +40,29 @@ public void controller() {} @Around("all()") public Object logging(ProceedingJoinPoint joinPoint) throws Throwable { - long start = System.currentTimeMillis(); + final long start = System.currentTimeMillis(); try { return joinPoint.proceed(); } finally { - long end = System.currentTimeMillis(); - long timeinMs = end - start; + final long end = System.currentTimeMillis(); + final long timeinMs = end - start; log.info("{} | time = {}ms", joinPoint.getSignature(), timeinMs); } } @Around("controller()") public Object loggingBefore(ProceedingJoinPoint joinPoint) throws Throwable { - HttpServletRequest request = + final HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())) .getRequest(); - String controllerName = joinPoint.getSignature().getDeclaringType().getName(); - String methodName = joinPoint.getSignature().getName(); - Map params = new HashMap<>(); + final String controllerName = joinPoint.getSignature().getDeclaringType().getName(); + final String methodName = joinPoint.getSignature().getName(); + final Map params = new HashMap<>(); try { - String decodedURI = URLDecoder.decode(request.getRequestURI(), "UTF-8"); + final String decodedURI = URLDecoder.decode(request.getRequestURI(), "UTF-8"); params.put("controller", controllerName); params.put("method", methodName); @@ -75,17 +78,15 @@ public Object loggingBefore(ProceedingJoinPoint joinPoint) throws Throwable { log.info("method: {}.{}", params.get("controller"), params.get("method")); log.info("params: {}", params.get("params")); - Object result = joinPoint.proceed(); - - return result; + return joinPoint.proceed(); } private static JSONObject getParams(HttpServletRequest request) throws JSONException { - JSONObject jsonObject = new JSONObject(); - Enumeration params = request.getParameterNames(); + final JSONObject jsonObject = new JSONObject(); + final Enumeration params = request.getParameterNames(); while (params.hasMoreElements()) { - String param = params.nextElement(); - String replaceParam = param.replaceAll("\\.", "-"); + final String param = params.nextElement(); + final String replaceParam = PATTERN.matcher(param).replaceAll("-"); jsonObject.put(replaceParam, request.getParameter(param)); } return jsonObject; diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/config/ModuleConfig.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/config/ModuleConfig.java index 771899a..61b7936 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/config/ModuleConfig.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/config/ModuleConfig.java @@ -12,7 +12,7 @@ public class ModuleConfig { @Bean public ObjectMapper objectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); + final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); return objectMapper; diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/exception/GlobalControllerAdvice.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/exception/GlobalControllerAdvice.java index b3e5711..562877b 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/exception/GlobalControllerAdvice.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/exception/GlobalControllerAdvice.java @@ -16,7 +16,7 @@ @RestControllerAdvice public class GlobalControllerAdvice { - @ExceptionHandler(value = CustomException.class) + @ExceptionHandler(CustomException.class) public ResponseEntity customError(CustomException e, HttpServletRequest request) { return ResponseEntity.status(e.getStatus()) .body( @@ -26,7 +26,7 @@ public ResponseEntity customError(CustomException e, HttpServletRequest reque e.getMessage())); } - @ExceptionHandler(value = Exception.class) + @ExceptionHandler(Exception.class) public ResponseEntity error(Exception e, HttpServletRequest request) { log.error("error", e); return ResponseEntity.status(500) diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtAuthenticationEntryPoint.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtAuthenticationEntryPoint.java index 1ba122f..72c4e7e 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtAuthenticationEntryPoint.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtAuthenticationEntryPoint.java @@ -36,7 +36,7 @@ public void commence( com.univ.tracedin.api.auth.exception.AuthenticationException.EXCEPTION); } - private boolean isExceptionInSecurityFilter(HttpServletRequest request) { + private static boolean isExceptionInSecurityFilter(HttpServletRequest request) { return request.getAttribute("exception") != null; } } diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtAuthenticationFilter.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtAuthenticationFilter.java index a793a12..1975ee2 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtAuthenticationFilter.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtAuthenticationFilter.java @@ -38,10 +38,10 @@ protected void doFilterInternal( throws ServletException, IOException { try { - Optional refreshToken = JwtTokenizer.extractRefreshToken(request); + final Optional refreshToken = JwtTokenizer.extractRefreshToken(request); if (refreshToken.isPresent()) { - UserPrincipal principal = JwtTokenizer.extractPrincipal(refreshToken.get()); + final UserPrincipal principal = JwtTokenizer.extractPrincipal(refreshToken.get()); validateRefreshToken(principal, refreshToken.get()); reIssueToken(principal, response); return; @@ -49,7 +49,7 @@ protected void doFilterInternal( JwtTokenizer.extractAccessToken(request) .map(JwtTokenizer::extractPrincipal) - .ifPresent(this::saveAuthentication); + .ifPresent(JwtAuthenticationFilter::saveAuthentication); } catch (Exception e) { log.error(e.toString()); @@ -60,28 +60,28 @@ protected void doFilterInternal( } public void validateRefreshToken(UserPrincipal principal, String givenRefreshToken) { - RefreshToken validRefreshToken = tokenCache.get(principal.userId()); + final RefreshToken validRefreshToken = tokenCache.get(principal.userId()); if (validRefreshToken.notEquals(givenRefreshToken)) { throw InvalidTokenException.EXCEPTION; } } private void reIssueToken(UserPrincipal principal, HttpServletResponse response) { - String reIssuedAccessToken = JwtTokenizer.generateAccessToken(principal); - String reIssuedRefreshToken = JwtTokenizer.generateRefreshToken(principal); + final String reIssuedAccessToken = JwtTokenizer.generateAccessToken(principal); + final String reIssuedRefreshToken = JwtTokenizer.generateRefreshToken(principal); tokenCache.cache(RefreshToken.of(principal.userId(), reIssuedRefreshToken)); JwtTokenizer.setInHeader(response, reIssuedAccessToken, reIssuedRefreshToken); response.setStatus(HttpServletResponse.SC_CREATED); } - private void saveAuthentication(UserPrincipal principal) { - UsernamePasswordAuthenticationToken authentication = + private static void saveAuthentication(UserPrincipal principal) { + final UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(principal, null, getAuthorities(principal)); SecurityContextHolder.getContext().setAuthentication(authentication); } - private List getAuthorities(UserPrincipal principal) { - List authorities = new ArrayList<>(); + private static List getAuthorities(UserPrincipal principal) { + final List authorities = new ArrayList<>(); authorities.add(new SimpleGrantedAuthority("ROLE_" + principal.role().name())); return authorities; } diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtTokenizer.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtTokenizer.java index 690eaee..47c5639 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtTokenizer.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/JwtTokenizer.java @@ -31,7 +31,7 @@ public class JwtTokenizer implements TokenGenerator { public static String generateAccessToken(UserPrincipal principal) { - Key key = getKeyFromSecretKey(SECRET_KEY); + final Key key = getKeyFromSecretKey(secretKey); return Jwts.builder() .setSubject(String.valueOf(principal.userId())) @@ -43,7 +43,7 @@ public static String generateAccessToken(UserPrincipal principal) { } public static String generateRefreshToken(UserPrincipal principal) { - Key key = getKeyFromSecretKey(SECRET_KEY); + final Key key = getKeyFromSecretKey(secretKey); return Jwts.builder() .setSubject(String.valueOf(principal.userId())) @@ -54,45 +54,45 @@ public static String generateRefreshToken(UserPrincipal principal) { public static void setInHeader( HttpServletResponse response, String accessToken, String refreshToken) { - response.setHeader(ACCESS_TOKEN_HEADER, accessToken); - response.setHeader(REFRESH_TOKEN_HEADER, refreshToken); + response.setHeader(accessTokenHeader, accessToken); + response.setHeader(refreshTokenHeader, refreshToken); } public static Key getKeyFromSecretKey(String secretKey) { - byte[] keyBytes = secretKey.getBytes(StandardCharsets.UTF_8); + final byte[] keyBytes = secretKey.getBytes(StandardCharsets.UTF_8); return Keys.hmacShaKeyFor(keyBytes); } public static Date getTokenExpiration() { - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.SECOND, ACCESS_TOKEN_EXPIRATION); + final Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.SECOND, accessTokenExpiration); return calendar.getTime(); } public static Optional extractAccessToken(HttpServletRequest request) { - return Optional.ofNullable(request.getHeader(ACCESS_TOKEN_HEADER)) - .filter(accessToken -> accessToken.startsWith(BEARER)) - .map(accessToken -> accessToken.replace(BEARER, "")); + return Optional.ofNullable(request.getHeader(accessTokenHeader)) + .filter(accessToken -> accessToken.startsWith(bearer)) + .map(accessToken -> accessToken.replace(bearer, "")); } public static Optional extractRefreshToken(HttpServletRequest request) { - return Optional.ofNullable(request.getHeader(REFRESH_TOKEN_HEADER)) - .filter(refreshToken -> refreshToken.startsWith(BEARER)) - .map(refreshToken -> refreshToken.replace(BEARER, "")); + return Optional.ofNullable(request.getHeader(refreshTokenHeader)) + .filter(refreshToken -> refreshToken.startsWith(bearer)) + .map(refreshToken -> refreshToken.replace(bearer, "")); } public static UserPrincipal extractPrincipal(String token) { try { // JWT 파싱 및 유효성 검사 - Claims claims = + final Claims claims = Jwts.parserBuilder() - .setSigningKey(getKeyFromSecretKey(SECRET_KEY)) + .setSigningKey(getKeyFromSecretKey(secretKey)) .build() .parseClaimsJws(token) .getBody(); - long userId = Long.parseLong(claims.getSubject()); - UserRole role = UserRole.valueOf(claims.get("role", String.class)); + final long userId = Long.parseLong(claims.getSubject()); + final UserRole role = UserRole.valueOf(claims.get("role", String.class)); return UserPrincipal.of(UserId.from(userId), role); } catch (ExpiredJwtException e) { diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/SecurityConstants.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/SecurityConstants.java index 7a17aee..7d2b306 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/SecurityConstants.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/SecurityConstants.java @@ -25,4 +25,6 @@ public class SecurityConstants { public static String[] getPermittedURIs() { return Stream.of(SWAGGER_URIS, SYSTEM_URIS).flatMap(Stream::of).toArray(String[]::new); } + + private SecurityConstants() {} } diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/SecurityProperties.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/SecurityProperties.java index d396843..9a1e9e2 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/SecurityProperties.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/security/SecurityProperties.java @@ -8,24 +8,24 @@ @Component public class SecurityProperties { - public static String SECRET_KEY; - public static int ACCESS_TOKEN_EXPIRATION; - public static String ACCESS_TOKEN_HEADER = AUTHORIZATION; - public static String REFRESH_TOKEN_HEADER; - public static String BEARER = "Bearer "; + public static String secretKey; + public static int accessTokenExpiration; + public static String accessTokenHeader = AUTHORIZATION; + public static String refreshTokenHeader; + public static String bearer = "Bearer "; @Value("${jwt.secret-key}") public void setSecretKey(String secretKey) { - SecurityProperties.SECRET_KEY = secretKey; + SecurityProperties.secretKey = secretKey; } @Value("${jwt.access-token.expiration}") public void setAccessTokenExpiration(int accessTokenExpiration) { - SecurityProperties.ACCESS_TOKEN_EXPIRATION = accessTokenExpiration; + SecurityProperties.accessTokenExpiration = accessTokenExpiration; } @Value("${jwt.refresh-token.header}") public void setRefreshToken(String refreshToken) { - SecurityProperties.REFRESH_TOKEN_HEADER = refreshToken; + SecurityProperties.refreshTokenHeader = refreshToken; } } diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/SseConnector.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/SseConnector.java index 2ad421a..3b8f62c 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/SseConnector.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/SseConnector.java @@ -17,7 +17,7 @@ public class SseConnector { private final SseEmitterRepository sseEmitterRepository; public SseEmitter connect(T key) { - SseEmitter emitter = new SseEmitter(TIMEOUT); + final SseEmitter emitter = new SseEmitter(TIMEOUT); sseEmitterRepository.save(key, emitter); emitter.onTimeout(() -> sseEmitterRepository.remove(key)); emitter.onCompletion(() -> sseEmitterRepository.remove(key)); diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/SseSender.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/SseSender.java index fe32306..c390fa4 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/SseSender.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/SseSender.java @@ -14,7 +14,7 @@ @RequiredArgsConstructor public class SseSender implements EventSender { - private final String METRICS_POSTFIX = " - metrics"; + private static final String METRICS_POSTFIX = " - metrics"; private final SseEmitterRepository sseEmitterRepository; @Override diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/exception/SseConnectionException.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/exception/SseConnectionException.java index ac051ea..8f32c9c 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/exception/SseConnectionException.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/sse/exception/SseConnectionException.java @@ -2,7 +2,7 @@ import com.univ.tracedin.common.exception.WebException; -public class SseConnectionException extends WebException { +public final class SseConnectionException extends WebException { public static final WebException EXCEPTION = new SseConnectionException(); diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/util/GrpcMappingUtils.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/util/GrpcMappingUtils.java index 1ec5146..b466918 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/util/GrpcMappingUtils.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/util/GrpcMappingUtils.java @@ -2,7 +2,7 @@ import static org.apache.commons.lang3.StringUtils.isNumeric; -public class GrpcMappingUtils { +public final class GrpcMappingUtils { public static Object convertValue(String value) { if (isNumeric(value)) { @@ -11,6 +11,8 @@ public static Object convertValue(String value) { return value; } + private GrpcMappingUtils() {} + private static Object parseNumeric(String value) { if (value.contains(".")) { return Double.parseDouble(value); diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/util/TokenUtils.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/util/TokenUtils.java index cc14ae3..ee76000 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/util/TokenUtils.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/global/util/TokenUtils.java @@ -9,11 +9,11 @@ import com.univ.tracedin.domain.auth.Tokens; -public class TokenUtils { +public final class TokenUtils { public static HttpHeaders createTokenHeaders(Tokens tokens) { - HttpHeaders headers = new HttpHeaders(); - ResponseCookie cookie = + final HttpHeaders headers = new HttpHeaders(); + final ResponseCookie cookie = createHttpOnlyCookie( REFRESH_TOKEN_COOKIE_NAME, tokens.refreshToken(), REFRESH_TOKEN_TTL); headers.set(HttpHeaders.AUTHORIZATION, tokens.accessToken()); @@ -21,6 +21,8 @@ public static HttpHeaders createTokenHeaders(Tokens tokens) { return headers; } + private TokenUtils() {} + private static ResponseCookie createHttpOnlyCookie(String name, String value, Duration maxAge) { return ResponseCookie.from(name, value).httpOnly(true).path("/").maxAge(maxAge).build(); } diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/metric/ServiceMetricsApi.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/metric/ServiceMetricsApi.java index 40a23f1..05c7278 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/metric/ServiceMetricsApi.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/metric/ServiceMetricsApi.java @@ -20,9 +20,10 @@ public class ServiceMetricsApi implements ServiceMetricsApiDocs { private final SseConnector sseConnector; + @Override @GetMapping(value = "/subscribe", produces = MediaType.TEXT_EVENT_STREAM_VALUE) public ResponseEntity subscribe(String projectKey, String serviceName) { - SseEmitter emitter = + final SseEmitter emitter = sseConnector.connect(Node.createService(ProjectKey.from(projectKey), serviceName)); return ResponseEntity.ok(emitter); } diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/metric/grpc/ServiceMetricsGrpc.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/metric/grpc/ServiceMetricsGrpc.java index 815bf0c..09c43c6 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/metric/grpc/ServiceMetricsGrpc.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/metric/grpc/ServiceMetricsGrpc.java @@ -48,11 +48,14 @@ private ServiceMetrics toServiceMetrics(AppendServiceMetricsRequest request) { return ServiceMetrics.builder() .projectKey(ProjectKey.from(request.getProjectKey())) .serviceName(request.getServiceName()) - .metrics(request.getMetricsList().stream().map(this::toMetric).toList()) + .metrics( + request.getMetricsList().stream() + .map(ServiceMetricsGrpc::toMetric) + .toList()) .build(); } - private Metric toMetric(MetricRequest metricRequest) { + private static Metric toMetric(MetricRequest metricRequest) { return Metric.builder() .name(metricRequest.getName()) .description(metricRequest.getDescription()) diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/span/SpanApi.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/span/SpanApi.java index 78849c6..181ff82 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/span/SpanApi.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/span/SpanApi.java @@ -24,17 +24,19 @@ public class SpanApi implements SpanApiDocs { private final SpanService spanService; + @Override @GetMapping("/traces") public Response> searchTraces( TraceSearchRequest request, SearchCursor cursor) { - SearchResult responses = + final SearchResult responses = spanService.getTraces(request.toCondition(), cursor).map(TraceResponse::from); return Response.success(responses); } + @Override @GetMapping("/span-tree") public Response getSpanTreeByTrace(String traceId) { - SpanTreeResponse response = + final SpanTreeResponse response = SpanTreeResponse.from(spanService.getSpanTree(TraceId.from(traceId))); return Response.success(response); } diff --git a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/span/grpc/SpanGrpc.java b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/span/grpc/SpanGrpc.java index 06cf068..04d3de7 100644 --- a/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/span/grpc/SpanGrpc.java +++ b/tracedin-application/app-api/src/main/java/com/univ/tracedin/api/span/grpc/SpanGrpc.java @@ -36,7 +36,7 @@ public class SpanGrpc extends SpanGrpcAppenderImplBase { public void appendSpans( AppendSpansRequest request, StreamObserver responseObserver) { try { - spanService.appendSpans(request.getSpansList().stream().map(this::toSpan).toList()); + spanService.appendSpans(request.getSpansList().stream().map(SpanGrpc::toSpan).toList()); responseObserver.onNext(AppendSpanResponse.newBuilder().setStatusCode(200).build()); } catch (Exception e) { log.error("Failed to append spans", e); @@ -46,7 +46,7 @@ public void appendSpans( } } - private Span toSpan(SpanProto.Span span) { + private static Span toSpan(SpanProto.Span span) { return Span.builder() .id(SpanId.from(span.getSpanId())) .traceId(TraceId.from(span.getTraceId())) @@ -92,7 +92,7 @@ private Span toSpan(SpanProto.Span span) { .build(); } - private long nanosToMillis(long nanos) { + private static long nanosToMillis(long nanos) { return nanos / 1_000_000; } } diff --git a/tracedin-common/src/main/java/com/univ/tracedin/common/constants/TracedInConstants.java b/tracedin-common/src/main/java/com/univ/tracedin/common/constants/TracedInConstants.java index 59ca1dd..b5cd7cc 100644 --- a/tracedin-common/src/main/java/com/univ/tracedin/common/constants/TracedInConstants.java +++ b/tracedin-common/src/main/java/com/univ/tracedin/common/constants/TracedInConstants.java @@ -1,6 +1,6 @@ package com.univ.tracedin.common.constants; -public class TracedInConstants { +public final class TracedInConstants { public static final int BAD_REQUEST = 400; public static final int UNAUTHORIZED = 401; @@ -10,4 +10,6 @@ public class TracedInConstants { public static final int INTERNAL_SERVER = 500; public static final String BEARER = "Bearer "; + + private TracedInConstants() {} } diff --git a/tracedin-common/src/main/java/com/univ/tracedin/common/dto/SearchResult.java b/tracedin-common/src/main/java/com/univ/tracedin/common/dto/SearchResult.java index 66cf96e..ea442cf 100644 --- a/tracedin-common/src/main/java/com/univ/tracedin/common/dto/SearchResult.java +++ b/tracedin-common/src/main/java/com/univ/tracedin/common/dto/SearchResult.java @@ -13,7 +13,7 @@ public static SearchResult success( } public SearchResult map(Function mapper) { - List mappedContent = results.stream().map(mapper).collect(Collectors.toList()); + final List mappedContent = results.stream().map(mapper).collect(Collectors.toList()); return new SearchResult<>(mappedContent, afterKey, totalCount); } } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/Alert.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/Alert.java index dc34435..ab0da5b 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/Alert.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/Alert.java @@ -25,7 +25,7 @@ public class Alert { private boolean isRead; public static Alert create(String title, ProjectId projectId, Map details) { - return Alert.builder() + return builder() .receiver(Receiver.from(projectId)) .title(title) .details(details) diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertMethod.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertMethod.java index 8402621..933d10f 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertMethod.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertMethod.java @@ -10,7 +10,7 @@ @Getter @Builder @AllArgsConstructor(access = AccessLevel.PRIVATE) -public class AlertMethod { +public final class AlertMethod { private AlertMethodId id; private ProjectId projectId; diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertMethodManager.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertMethodManager.java index 07ac369..e127506 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertMethodManager.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertMethodManager.java @@ -15,7 +15,7 @@ public class AlertMethodManager { private final AlertMethodRepository alertMethodRepository; public void append(AlertInfo alertInfo) { - AlertMethod alertMethod = AlertMethod.create(alertInfo); + final AlertMethod alertMethod = AlertMethod.create(alertInfo); alertMethodRepository.saveMethod(alertMethod); } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertSender.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertSender.java index 39c637c..eb25fad 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertSender.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertSender.java @@ -19,7 +19,7 @@ public void send(Alert alert) { .forEach( alertMethod -> { if (alertMethod.isActivated()) { - AlertClient client = + final AlertClient client = alertClientFactory.getClient(alertMethod.getAlertType()); client.sendAlert(alertMethod.getContact(), alert); } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertService.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertService.java index c0a2550..76be691 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertService.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/alert/AlertService.java @@ -23,17 +23,17 @@ public List readAllMethods(ProjectId projectId) { } public void removeMethod(AlertMethodId alertMethodId) { - AlertMethod alertMethod = alertMethodManager.read(alertMethodId); + final AlertMethod alertMethod = alertMethodManager.read(alertMethodId); alertMethodManager.remove(alertMethod); } public void deactivateMethod(AlertMethodId alertMethodId) { - AlertMethod alertMethod = alertMethodManager.read(alertMethodId); + final AlertMethod alertMethod = alertMethodManager.read(alertMethodId); alertMethodManager.deactivate(alertMethod); } public void activateMethod(AlertMethodId alertMethodId) { - AlertMethod alertMethod = alertMethodManager.read(alertMethodId); + final AlertMethod alertMethod = alertMethodManager.read(alertMethodId); alertMethodManager.activate(alertMethod); } } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/anomaly/AnomalyTrace.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/anomaly/AnomalyTrace.java index e63d01f..fed36e5 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/anomaly/AnomalyTrace.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/anomaly/AnomalyTrace.java @@ -10,7 +10,7 @@ public record AnomalyTrace(TraceId traceId, ProjectKey projectKey, List public static AnomalyTrace from( TraceId traceId, String projectKey, List anomalySpanIds) { - List spanIds = anomalySpanIds.stream().map(SpanId::from).toList(); + final List spanIds = anomalySpanIds.stream().map(SpanId::from).toList(); return new AnomalyTrace(traceId, ProjectKey.from(projectKey), spanIds); } } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/anomaly/AnomalyTraceProcessor.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/anomaly/AnomalyTraceProcessor.java index bac723a..41c2ce9 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/anomaly/AnomalyTraceProcessor.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/anomaly/AnomalyTraceProcessor.java @@ -32,14 +32,14 @@ public void process(List anomalyTraces) { private void sendAlerts(List anomalyTraces) { for (AnomalyTrace anomalyTrace : anomalyTraces) { - Alert anomalyAlert = createAnomalyAlert(anomalyTrace); + final Alert anomalyAlert = createAnomalyAlert(anomalyTrace); alertSender.send(anomalyAlert); } } private Alert createAnomalyAlert(AnomalyTrace anomalyTrace) { - Project project = projectReader.readByKey(anomalyTrace.projectKey()); - HashMap details = + final Project project = projectReader.readByKey(anomalyTrace.projectKey()); + final HashMap details = new HashMap<>() { { put("traceId", anomalyTrace.traceId().getValue()); @@ -58,7 +58,7 @@ private void updateAnomalySpans(List anomalyTraces) { } } - private String getSpanIdToString(AnomalyTrace anomalyTrace) { + private static String getSpanIdToString(AnomalyTrace anomalyTrace) { return anomalyTrace.anomalySpanIds().stream().map(SpanId::getValue).toList().toString(); } } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/auth/AuthConstants.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/auth/AuthConstants.java index 76414f5..f3062ce 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/auth/AuthConstants.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/auth/AuthConstants.java @@ -2,9 +2,11 @@ import java.time.Duration; -public class AuthConstants { +public final class AuthConstants { public static final String REFRESH_TOKEN_COOKIE_NAME = "refreshToken"; public static final Duration REFRESH_TOKEN_TTL = Duration.ofDays(14); + + private AuthConstants() {} } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/auth/UserAuthenticator.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/auth/UserAuthenticator.java index 0b884d6..c65d5a9 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/auth/UserAuthenticator.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/auth/UserAuthenticator.java @@ -18,9 +18,9 @@ public class UserAuthenticator { private final RefreshTokenCache refreshTokenCache; public Tokens authenticate(LoginInfo login) { - User user = userReader.read(login.email()); + final User user = userReader.read(login.email()); validatePassword(login, user); - Tokens tokens = tokenGenerator.generate(user.getPrincipal()); + final Tokens tokens = tokenGenerator.generate(user.getPrincipal()); refreshTokenCache.cache(tokens.getRefreshToken(user)); return tokens; } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/global/BaseId.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/global/BaseId.java index a14912c..df0e7ec 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/global/BaseId.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/global/BaseId.java @@ -1,5 +1,7 @@ package com.univ.tracedin.domain.global; +import java.util.Objects; + import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -22,7 +24,12 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - BaseId baseId = (BaseId) o; + final BaseId baseId = (BaseId) o; return value.equals(baseId.value); } + + @Override + public int hashCode() { + return Objects.hashCode(getValue()); + } } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsCollectedEvent.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsCollectedEvent.java index 40c75df..2fb6b04 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsCollectedEvent.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsCollectedEvent.java @@ -9,6 +9,6 @@ public static ServiceMetricsCollectedEvent from(ServiceMetrics metrics) { } public String getKey() { - return serviceMetrics.getProjectKey().value() + "-" + serviceMetrics.getServiceName(); + return serviceMetrics.getProjectKey().value() + '-' + serviceMetrics.getServiceName(); } } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsMessageProcessor.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsMessageProcessor.java index 94db6d4..f44b8f8 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsMessageProcessor.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsMessageProcessor.java @@ -14,7 +14,7 @@ public class ServiceMetricsMessageProcessor { private final ServiceMetricsSender serviceMetricsSender; public void process(List messages) { - List metrics = + final List metrics = messages.stream().map(ServiceMetricsCollectedEvent::serviceMetrics).toList(); metrics.forEach(serviceMetricsSender::send); serviceMetricsAppender.appendAll(metrics); diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsReader.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsReader.java deleted file mode 100644 index cb9f688..0000000 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsReader.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.univ.tracedin.domain.metric; - -import org.springframework.stereotype.Component; - -import lombok.RequiredArgsConstructor; - -@Component -@RequiredArgsConstructor -public class ServiceMetricsReader { - - private final ServiceMetricsRepository serviceMetricsRepository; -} diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/HttpTps.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/HttpTps.java index 809a935..c60eec3 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/HttpTps.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/HttpTps.java @@ -7,7 +7,7 @@ public record HttpTps(LocalDateTime timestamp, int httpRequestCount) { public static HttpTps of(long endEpochMillis, double httpRequestCount) { - LocalDateTime timestamp = + final LocalDateTime timestamp = LocalDateTime.ofInstant( Instant.ofEpochMilli(endEpochMillis), ZoneId.systemDefault()); return new HttpTps(timestamp, (int) httpRequestCount); diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/Project.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/Project.java index fad9cb7..a24caae 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/Project.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/Project.java @@ -19,9 +19,6 @@ public class Project { private ProjectKey projectKey; public static Project create(ProjectInfo projectInfo) { - return Project.builder() - .info(projectInfo) - .projectKey(ProjectKey.create(projectInfo)) - .build(); + return builder().info(projectInfo).projectKey(ProjectKey.create(projectInfo)).build(); } } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectAppender.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectAppender.java index a580ae4..86ff401 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectAppender.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectAppender.java @@ -14,8 +14,8 @@ public class ProjectAppender { private final ProjectMemberManager projectMemberManager; public ProjectKey append(User user, ProjectInfo projectInfo) { - Project project = Project.create(projectInfo); - Project saved = projectRepository.save(project); + final Project project = Project.create(projectInfo); + final Project saved = projectRepository.save(project); projectMemberManager.add(saved, user, ProjectMember.MemberRole.ADMIN); return project.getProjectKey(); } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectMember.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectMember.java index 6fe8195..9890a96 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectMember.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectMember.java @@ -20,7 +20,7 @@ public class ProjectMember { private MemberRole role; public static ProjectMember create(ProjectId projectId, UserId memberId, MemberRole role) { - return ProjectMember.builder().projectId(projectId).memberId(memberId).role(role).build(); + return builder().projectId(projectId).memberId(memberId).role(role).build(); } public void changeRole(MemberRole role) { diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectMemberManager.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectMemberManager.java index a6282a5..f442618 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectMemberManager.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectMemberManager.java @@ -15,7 +15,7 @@ public class ProjectMemberManager { private final ProjectRepository projectRepository; public void add(Project project, User targetMember, ProjectMember.MemberRole role) { - ProjectMember projectMember = + final ProjectMember projectMember = ProjectMember.create(project.getId(), targetMember.getId(), role); projectRepository.saveProjectMember(projectMember); } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectReader.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectReader.java index 915bac8..642a043 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectReader.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectReader.java @@ -16,8 +16,8 @@ public class ProjectReader { private final ProjectMemberManager projectMemberManager; public List readAll(User user) { - List projectMembers = projectMemberManager.readAll(user); - List projectIds = + final List projectMembers = projectMemberManager.readAll(user); + final List projectIds = projectMembers.stream().map(ProjectMember::getProjectId).toList(); return projectRepository.findAllByIds(projectIds); } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanService.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanService.java index 7722bcd..74334fd 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanService.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanService.java @@ -26,7 +26,7 @@ public SearchResult getTraces(TraceSearchCondition cond, SearchCursor cur } public SpanTree getSpanTree(TraceId traceId) { - List spans = spanReader.read(traceId); + final List spans = spanReader.read(traceId); return SpanTreeBuilder.build(spans); } } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanStatus.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanStatus.java index a5a194b..101e5b0 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanStatus.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanStatus.java @@ -9,7 +9,7 @@ public static SpanStatus fromValue(String spanStatus) { if (spanStatus == null) { return UNSET; } - for (SpanStatus type : SpanStatus.values()) { + for (SpanStatus type : values()) { if (type.name().equalsIgnoreCase(spanStatus)) { return type; } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanTree.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanTree.java index d65491c..231e4c3 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanTree.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanTree.java @@ -11,13 +11,13 @@ @Getter @Builder @AllArgsConstructor(access = AccessLevel.PRIVATE) -public class SpanTree { +public final class SpanTree { private Span span; private List children; public static SpanTree init(Span span) { - return SpanTree.builder().span(span).children(new ArrayList<>()).build(); + return builder().span(span).children(new ArrayList<>()).build(); } public SpanId getParentId() { diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanTreeBuilder.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanTreeBuilder.java index e1f00bb..6343cf1 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanTreeBuilder.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanTreeBuilder.java @@ -5,10 +5,10 @@ import java.util.Map; import java.util.stream.Collectors; -public class SpanTreeBuilder { +public final class SpanTreeBuilder { public static SpanTree build(List spans) { - Map spanMap = + final Map spanMap = spans.stream().collect(Collectors.toMap(Span::getId, SpanTree::init)); spanMap.values().stream() @@ -16,7 +16,7 @@ public static SpanTree build(List spans) { .forEach( current -> { if (current.getSpan().hasParent()) { - SpanTree parent = spanMap.get(current.getParentId()); + final SpanTree parent = spanMap.get(current.getParentId()); parent.addChild(current); } }); @@ -26,4 +26,6 @@ public static SpanTree build(List spans) { .findFirst() .orElseThrow(() -> new IllegalStateException("No root span found")); } + + private SpanTreeBuilder() {} } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/Trace.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/Trace.java index 283f861..bd1b567 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/Trace.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/Trace.java @@ -12,7 +12,7 @@ @Builder @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) -public class Trace { +public final class Trace { private TraceId id; private String endPoint; diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/user/User.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/user/User.java index 30b8e30..9ea0ed5 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/user/User.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/user/User.java @@ -10,7 +10,7 @@ @Getter @Builder @AllArgsConstructor(access = AccessLevel.PRIVATE) -public class User { +public final class User { private UserId id; diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/user/UserService.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/user/UserService.java deleted file mode 100644 index 9aa1d29..0000000 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/user/UserService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.univ.tracedin.domain.user; - -import org.springframework.stereotype.Service; - -import lombok.RequiredArgsConstructor; - -@Service -@RequiredArgsConstructor -public class UserService { - - private final UserRepository userRepository; -} diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/client/SlackAlertClient.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/client/SlackAlertClient.java index d0d887d..34d3c55 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/client/SlackAlertClient.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/client/SlackAlertClient.java @@ -35,7 +35,7 @@ public class SlackAlertClient implements AlertClient { public void sendAlert(String contact, Alert alert) { try { - WebhookResponse response = slackClient.send(contact, buildPayload(alert)); + final WebhookResponse response = slackClient.send(contact, buildPayload(alert)); if (response.getCode() != 200) { log.error("Failed to send alert to slack. Response: {}", response); @@ -54,8 +54,8 @@ public AlertType getAlertType() { } private Payload buildPayload(Alert alert) { - String link = generateLink(alert); - String messageText = alert.getTitle() + "\n자세한 내용은 " + link + "를 클릭하세요."; + final String link = generateLink(alert); + final String messageText = alert.getTitle() + "\n자세한 내용은 " + link + "를 클릭하세요."; return Payload.builder() .text(messageText) @@ -64,15 +64,15 @@ private Payload buildPayload(Alert alert) { } private String generateLink(Alert alert) { - String traceId = alert.getDetails().get("traceId"); - String encodedTraceId = URLEncoder.encode(traceId, StandardCharsets.UTF_8); - String url = serverUrl + "/api/v1/spans/span-tree?traceId=" + encodedTraceId; - String linkText = "여기"; + final String traceId = alert.getDetails().get("traceId"); + final String encodedTraceId = URLEncoder.encode(traceId, StandardCharsets.UTF_8); + final String url = serverUrl + "/api/v1/spans/span-tree?traceId=" + encodedTraceId; + final String linkText = "여기"; - return "<" + url + "|" + linkText + ">"; + return '<' + url + '|' + linkText + '>'; } - private List buildAttachments(Map details) { + private static List buildAttachments(Map details) { return details.entrySet().stream() .map( entry -> diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/entity/AlertEntity.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/entity/AlertEntity.java index c38f636..2c02762 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/entity/AlertEntity.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/entity/AlertEntity.java @@ -48,8 +48,8 @@ public class AlertEntity { private Map details; public static AlertEntity from(Alert alert) { - Long alertId = (alert.getId() == null) ? null : alert.getId().getValue(); - return AlertEntity.builder() + final Long alertId = (alert.getId() == null) ? null : alert.getId().getValue(); + return builder() .id(alertId) .projectId(alert.getReceiver().projectId().getValue()) .title(alert.getTitle()) diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/entity/AlertMethodEntity.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/entity/AlertMethodEntity.java index d3f501c..d5b132a 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/entity/AlertMethodEntity.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/entity/AlertMethodEntity.java @@ -41,8 +41,9 @@ public class AlertMethodEntity { private boolean isActivated; public static AlertMethodEntity from(AlertMethod alertMethod) { - Long alertMethodId = (alertMethod.getId() == null) ? null : alertMethod.getId().getValue(); - return AlertMethodEntity.builder() + final Long alertMethodId = + (alertMethod.getId() == null) ? null : alertMethod.getId().getValue(); + return builder() .id(alertMethodId) .projectId(alertMethod.getProjectId().getValue()) .alertType(alertMethod.getAlertType()) diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/exception/AlertMethodNotFoundException.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/exception/AlertMethodNotFoundException.java index 34d3451..d93c94c 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/exception/AlertMethodNotFoundException.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/exception/AlertMethodNotFoundException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.InfraException; import com.univ.tracedin.domain.alert.exception.AlertErrorCode; -public class AlertMethodNotFoundException extends InfraException { +public final class AlertMethodNotFoundException extends InfraException { public static final AlertMethodNotFoundException EXCEPTION = new AlertMethodNotFoundException(); diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/exception/AlertSendException.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/exception/AlertSendException.java index 2a509eb..7ac3f3a 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/exception/AlertSendException.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/alert/exception/AlertSendException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.InfraException; import com.univ.tracedin.domain.alert.exception.AlertErrorCode; -public class AlertSendException extends InfraException { +public final class AlertSendException extends InfraException { public static final AlertSendException EXCEPTION = new AlertSendException(); diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/client/AnomalyDetector.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/client/AnomalyDetector.java index 88e500b..d874631 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/client/AnomalyDetector.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/client/AnomalyDetector.java @@ -12,10 +12,10 @@ public class AnomalyDetector implements AnomalyDetectionClient { @Override public AnomalyTraceResult detect(List traceSpans) { - List anomalySpans = + final List anomalySpans = traceSpans.stream().filter(span -> span.getTiming().duration() > 1000).toList(); - boolean isAnomaly = !anomalySpans.isEmpty(); + final boolean isAnomaly = !anomalySpans.isEmpty(); return new AnomalyTraceResult( isAnomaly, diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/listener/AnomalyTraceKafkaListener.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/listener/AnomalyTraceKafkaListener.java index 7ae3261..06cd46a 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/listener/AnomalyTraceKafkaListener.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/listener/AnomalyTraceKafkaListener.java @@ -34,7 +34,7 @@ public void receive(List> records) { records.stream().map(ConsumerRecord::partition).toList(), records.stream().map(ConsumerRecord::offset).toList()); - List anomalyTraces = + final List anomalyTraces = records.stream() .map( record -> diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/streams/AnomalyTraceKafkaStreamsConfig.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/streams/AnomalyTraceKafkaStreamsConfig.java index 9bc860b..15329fc 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/streams/AnomalyTraceKafkaStreamsConfig.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/streams/AnomalyTraceKafkaStreamsConfig.java @@ -22,7 +22,7 @@ public class AnomalyTraceKafkaStreamsConfig { @Bean public KStream spanStreams(StreamsBuilder streamsBuilder) { - KStream stream = streamsBuilder.stream(inputTopic); + final KStream stream = streamsBuilder.stream(inputTopic); spanStreamProcessor.process(stream); return stream; } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/streams/AnomalyTraceStreamProcessor.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/streams/AnomalyTraceStreamProcessor.java index 14368a0..ea8e6a6 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/streams/AnomalyTraceStreamProcessor.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/anomaly/messaging/streams/AnomalyTraceStreamProcessor.java @@ -39,25 +39,25 @@ public class AnomalyTraceStreamProcessor { private final AnomalyDetectionClient anomalyDetectionClient; void process(KStream stream) { - JsonSerde> listOfSpanSerde = new JsonSerde<>(new TypeReference<>() {}); + final JsonSerde> listOfSpanSerde = new JsonSerde<>(new TypeReference<>() {}); // Stream processor - SpanCollectedEvent를 받아서 TraceId로 그루핑한뒤 각 TraceId에 대한 Span들을 List로 묶어서 - KStream spanStream = + final KStream spanStream = stream.flatMap( (key, value) -> { - List> result = new ArrayList<>(); + final List> result = new ArrayList<>(); for (Span span : value.spans()) { - TraceId traceId = span.getTraceId(); + final TraceId traceId = span.getTraceId(); result.add(new KeyValue<>(traceId, span)); } return result; }); - TimeWindows timeWindows = + final TimeWindows timeWindows = TimeWindows.ofSizeAndGrace(Duration.ofMinutes(1), Duration.ofSeconds(30)); // KTable로 만듦 - KTable, List> traceTable = + final KTable, List> traceTable = spanStream .groupByKey() .windowedBy(timeWindows) @@ -79,8 +79,8 @@ void process(KStream stream) { .to(anomalyTraceTopic, Produced.keySerde(getTraceIdSerde())); } - private Serde getTraceIdSerde() { - JsonSerde traceIdSerde = new JsonSerde<>(TraceId.class); + private static Serde getTraceIdSerde() { + final JsonSerde traceIdSerde = new JsonSerde<>(TraceId.class); traceIdSerde.configure(Map.of(), true); return traceIdSerde; } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/auth/cache/RefreshTokenCacheAdapter.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/auth/cache/RefreshTokenCacheAdapter.java index 0aae3fd..0e41c44 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/auth/cache/RefreshTokenCacheAdapter.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/auth/cache/RefreshTokenCacheAdapter.java @@ -1,5 +1,6 @@ package com.univ.tracedin.infra.auth.cache; +import org.jetbrains.annotations.Nullable; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; @@ -19,19 +20,20 @@ public class RefreshTokenCacheAdapter implements RefreshTokenCache { @Override public void cache(RefreshToken refreshToken) { - String key = getKey(refreshToken.userId()); + final String key = getKey(refreshToken.userId()); log.info("Set Refresh Token from {} : {}", key, refreshToken); template.opsForValue().set(key, refreshToken); } + @Nullable @Override public RefreshToken get(UserId id) { - String key = getKey(id); + final String key = getKey(id); log.info("Get Refresh Token from {}", key); return template.opsForValue().get(key); } - private String getKey(UserId userId) { + private static String getKey(UserId userId) { return "USER_REFRESH_TOKEN:" + userId.getValue(); } } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/auth/config/TokenRedisConfig.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/auth/config/TokenRedisConfig.java index e210e35..0c4e1b4 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/auth/config/TokenRedisConfig.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/auth/config/TokenRedisConfig.java @@ -17,7 +17,7 @@ public class TokenRedisConfig { @Bean public RedisTemplate tokenRedisTemplate() { - RedisTemplate template = new RedisTemplate<>(); + final RedisTemplate template = new RedisTemplate<>(); template.setConnectionFactory(connectionFactory); return template; } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/ESSupplier.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/ESSupplier.java index b51b707..929dfe5 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/ESSupplier.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/ESSupplier.java @@ -2,6 +2,7 @@ import java.io.IOException; +@FunctionalInterface public interface ESSupplier { T get() throws IOException; diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/ESUtils.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/ESUtils.java index a51f185..832fa7b 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/ESUtils.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/ESUtils.java @@ -7,7 +7,7 @@ import com.univ.tracedin.infra.span.exception.ElasticSearchException; @Slf4j -public class ESUtils { +public final class ESUtils { public static T executeESQuery(ESSupplier request) { try { @@ -17,4 +17,6 @@ public static T executeESQuery(ESSupplier request) { throw ElasticSearchException.EXCEPTION; } } + + private ESUtils() {} } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/config/ElasticSearchConfig.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/config/ElasticSearchConfig.java index 3cf0c82..79f2856 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/config/ElasticSearchConfig.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/elasticsearch/config/ElasticSearchConfig.java @@ -25,13 +25,13 @@ public class ElasticSearchConfig extends ElasticsearchConfiguration { @Override public ClientConfiguration clientConfiguration() { - return ClientConfiguration.builder().connectedTo(esHost + ":" + esPort).build(); + return ClientConfiguration.builder().connectedTo(esHost + ':' + esPort).build(); } @Bean public ElasticsearchClient elasticsearchClient() { - RestClient restClient = RestClient.builder(new HttpHost(esHost, esPort)).build(); - RestClientTransport transport = + final RestClient restClient = RestClient.builder(new HttpHost(esHost, esPort)).build(); + final RestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper()); return new ElasticsearchClient(transport); } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/kafka/KafkaMessageHelper.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/kafka/KafkaMessageHelper.java index 89604d4..925cde2 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/kafka/KafkaMessageHelper.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/kafka/KafkaMessageHelper.java @@ -5,12 +5,9 @@ import org.apache.kafka.clients.producer.RecordMetadata; import org.springframework.kafka.support.SendResult; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; @Slf4j -@NoArgsConstructor(access = AccessLevel.PROTECTED) public final class KafkaMessageHelper { public static CompletableFuture> getKafkaCallback(V payload) { @@ -34,4 +31,6 @@ public boolean completeExceptionally(Throwable ex) { } }; } + + private KafkaMessageHelper() {} } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/config/MetricRedisConfig.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/config/MetricRedisConfig.java index bc7edec..9c18d83 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/config/MetricRedisConfig.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/config/MetricRedisConfig.java @@ -28,7 +28,7 @@ public class MetricRedisConfig { @Bean public RedisMessageListenerContainer redisMessageListenerContainer( MessageListenerAdapter listenerAdapter) { - RedisMessageListenerContainer container = new RedisMessageListenerContainer(); + final RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(redisConnectionFactory); container.addMessageListener(listenerAdapter, new PatternTopic(METRIC_CHANNEL_ID)); return container; @@ -42,7 +42,7 @@ public MessageListenerAdapter listenerAdapter( @Bean public RedisTemplate notificationTemplate() { - RedisTemplate redisTemplate = new RedisTemplate<>(); + final RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer( diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/document/ServiceMetricsDocument.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/document/ServiceMetricsDocument.java index e1a03ee..eea594e 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/document/ServiceMetricsDocument.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/document/ServiceMetricsDocument.java @@ -37,7 +37,7 @@ public class ServiceMetricsDocument { List metrics; public static ServiceMetricsDocument from(ServiceMetrics serviceMetrics) { - return ServiceMetricsDocument.builder() + return builder() .projectKey(serviceMetrics.getProjectKey().value()) .serviceName(serviceMetrics.getServiceName()) .metrics(serviceMetrics.getMetrics()) diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/listener/ServiceMetricsKafkaListener.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/listener/ServiceMetricsKafkaListener.java index 0bfdff0..b751fcf 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/listener/ServiceMetricsKafkaListener.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/listener/ServiceMetricsKafkaListener.java @@ -33,7 +33,7 @@ public void receive(List> r records.stream().map(ConsumerRecord::partition).toList(), records.stream().map(ConsumerRecord::offset).toList()); - List events = + final List events = records.stream().map(ConsumerRecord::value).toList(); serviceMetricsMessageProcessor.process(events); } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/listener/ServiceMetricsRedisListener.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/listener/ServiceMetricsRedisListener.java index 934f8d5..88d700a 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/listener/ServiceMetricsRedisListener.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/listener/ServiceMetricsRedisListener.java @@ -24,7 +24,7 @@ public class ServiceMetricsRedisListener implements MessageListener { @Override public void onMessage(Message message, byte[] pattern) { try { - ServiceMetrics serviceMetrics = + final ServiceMetrics serviceMetrics = objectMapper.readValue(message.getBody(), ServiceMetrics.class); log.info("Service metrics received: {}", serviceMetrics); eventSender.send(serviceMetrics); diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/publish/ServiceMetricsKafkaPublisher.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/publish/ServiceMetricsKafkaPublisher.java index 25492f3..1aa3faf 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/publish/ServiceMetricsKafkaPublisher.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/messaging/publish/ServiceMetricsKafkaPublisher.java @@ -21,6 +21,7 @@ public class ServiceMetricsKafkaPublisher implements ServiceMetricsMessagePublis @Value("${kafka.topic.service-metrics}") private String serviceMetricsTopic; + @Override public void publish(ServiceMetricsCollectedEvent serviceMetricsCollectedEvent) { kafkaProducer.send( serviceMetricsTopic, diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/repository/ServiceMetricsCoreRepository.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/repository/ServiceMetricsCoreRepository.java index 5ac2db5..55136dd 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/repository/ServiceMetricsCoreRepository.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/repository/ServiceMetricsCoreRepository.java @@ -19,8 +19,9 @@ public class ServiceMetricsCoreRepository implements ServiceMetricsRepository { private final ServiceMetricsElasticSearchRepository serviceMetricsElasticSearchRepository; + @Override public void saveAll(List metrics) { - List documents = + final List documents = metrics.stream().map(ServiceMetricsDocument::from).toList(); serviceMetricsElasticSearchRepository.saveAll(documents); } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/repository/ServiceMetricsElasticSearchRepositoryCustomImpl.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/repository/ServiceMetricsElasticSearchRepositoryCustomImpl.java deleted file mode 100644 index 2637149..0000000 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/metric/repository/ServiceMetricsElasticSearchRepositoryCustomImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.univ.tracedin.infra.metric.repository; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import co.elastic.clients.elasticsearch.ElasticsearchClient; - -@Slf4j -@RequiredArgsConstructor -public class ServiceMetricsElasticSearchRepositoryCustomImpl - implements ServiceMetricsElasticSearchRepositoryCustom { - - private final String INDEX_NAME = "service-metrics"; - private final ElasticsearchClient client; -} diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/entity/ProjectEntity.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/entity/ProjectEntity.java index d6c8b91..c746ce8 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/entity/ProjectEntity.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/entity/ProjectEntity.java @@ -36,8 +36,8 @@ public class ProjectEntity { private String projectKey; public static ProjectEntity from(Project project) { - Long id = (project.getId() == null) ? null : project.getId().getValue(); - return ProjectEntity.builder() + final Long id = (project.getId() == null) ? null : project.getId().getValue(); + return builder() .id(id) .name(project.getInfo().projectName()) .description(project.getInfo().description()) diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/entity/ProjectMemberEntity.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/entity/ProjectMemberEntity.java index 90c7e24..c7533ee 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/entity/ProjectMemberEntity.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/entity/ProjectMemberEntity.java @@ -40,7 +40,7 @@ public class ProjectMemberEntity { private MemberRole role; public static ProjectMemberEntity from(ProjectMember projectMember) { - return ProjectMemberEntity.builder() + return builder() .projectId(projectMember.getProjectId().getValue()) .memberId(projectMember.getMemberId().getValue()) .role(projectMember.getRole()) diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/exception/ProjectMemberNotFoundException.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/exception/ProjectMemberNotFoundException.java index 7b16aa2..99f33ce 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/exception/ProjectMemberNotFoundException.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/exception/ProjectMemberNotFoundException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.InfraException; import com.univ.tracedin.domain.project.exception.ProjectErrorCode; -public class ProjectMemberNotFoundException extends InfraException { +public final class ProjectMemberNotFoundException extends InfraException { public static final ProjectMemberNotFoundException EXCEPTION = new ProjectMemberNotFoundException(); diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/exception/ProjectNotFoundException.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/exception/ProjectNotFoundException.java index a7c7727..d5e566b 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/exception/ProjectNotFoundException.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/exception/ProjectNotFoundException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.InfraException; import com.univ.tracedin.domain.project.exception.ProjectErrorCode; -public class ProjectNotFoundException extends InfraException { +public final class ProjectNotFoundException extends InfraException { public static final ProjectNotFoundException EXCEPTION = new ProjectNotFoundException(); diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/repository/ProjectRepositoryAdapter.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/repository/ProjectRepositoryAdapter.java index aeb8aa2..4234fee 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/repository/ProjectRepositoryAdapter.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/project/repository/ProjectRepositoryAdapter.java @@ -68,7 +68,7 @@ public boolean existsByKey(ProjectKey projectKey) { @Override public List findServiceNodeList(ProjectKey projectKey) { - List serviceNames = + final List serviceNames = spanElasticSearchRepository.findServiceNames(projectKey.value()); return serviceNames.stream() .map(name -> Node.of(projectKey, name, NodeType.SERVICE)) diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/document/SpanDocument.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/document/SpanDocument.java index 06ad82b..22a4a96 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/document/SpanDocument.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/document/SpanDocument.java @@ -119,7 +119,7 @@ public static class Attributes { private Integer totalAddedValues; public static Attributes from(SpanAttributes spanAttributes) { - return Attributes.builder() + return builder() .data(spanAttributes.data()) .capacity(spanAttributes.capacity()) .totalAddedValues(spanAttributes.totalAddedValues()) diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/exception/ElasticSearchException.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/exception/ElasticSearchException.java index 0da6542..531aa48 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/exception/ElasticSearchException.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/exception/ElasticSearchException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.InfraException; import com.univ.tracedin.domain.span.exception.SpanErrorCode; -public class ElasticSearchException extends InfraException { +public final class ElasticSearchException extends InfraException { public static final ElasticSearchException EXCEPTION = new ElasticSearchException(); diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/messaging/listener/SpanKafkaListener.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/messaging/listener/SpanKafkaListener.java index 40367f1..c5a2c4c 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/messaging/listener/SpanKafkaListener.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/messaging/listener/SpanKafkaListener.java @@ -32,7 +32,7 @@ public void receive(List> records) { records.stream().map(ConsumerRecord::partition).toList(), records.stream().map(ConsumerRecord::offset).toList()); - List spans = + final List spans = records.stream() .map(ConsumerRecord::value) .map(SpanCollectedEvent::spans) diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/user/entity/UserEntity.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/user/entity/UserEntity.java index 3586d1f..62df15b 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/user/entity/UserEntity.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/user/entity/UserEntity.java @@ -40,7 +40,7 @@ public class UserEntity { private UserRole role; public static UserEntity from(User user) { - return UserEntity.builder() + return builder() .name(user.getName()) .email(user.getEmail()) .password(user.getPassword()) diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/user/exception/UserNotFoundException.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/user/exception/UserNotFoundException.java index 6843141..c3ef06d 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/user/exception/UserNotFoundException.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/user/exception/UserNotFoundException.java @@ -3,7 +3,7 @@ import com.univ.tracedin.common.exception.InfraException; import com.univ.tracedin.domain.user.exception.UserErrorCode; -public class UserNotFoundException extends InfraException { +public final class UserNotFoundException extends InfraException { public static final UserNotFoundException EXCEPTION = new UserNotFoundException();