SpringBoot
-
MSA) 서비스 별 각 인스턴스에서 애플리케이션을 Docker 컨테이너화 후, 발생한 Eureka Client 간의 통신 문제SpringBoot 2024. 7. 9. 10:38
개발 서버를 구축하기 위해, 현재 위와 같이MSA의 Eureka 서버를 제외하고, 각 서비스들을 각각의 인스턴스에 Blue/Green 무중단 배포를 적용하여 도커로 컨테이너화 한 상태였습니다. API Gateway 서버와 Batch Service 서버 모두CD가 동작하면 각 서버에 작성한 쉘 스크립트가 실행되어 Blue/Green 무중단 배포를 적용하는 방식입니다. 위와 같이 Blue/Green을 적용을 확인하기 위해 각 마이크로 서비스에 헬스 체크 컨트롤러를 만들어 둔 상태였습니다. 문제각 서비스에서 도커 컨테이너가 정상적으로 올라간 것을 확인한 후,API Gateway 서버에서 Batch Service의 API를 잘 라우팅 해주는지 확인하기 위해아래와 같이 리눅스 상에서 curl 명령을 통해 헬..
-
MSA) Spring Cloud 기반의 MSA 구조에서 Swagger 통합하기 + FastAPI의 Swagger까지SpringBoot 2024. 6. 17. 21:51
들어가며 저번 시간에 FastAPI 서버를 Spring Cloud Eureka에 Client로 등록하는 방법에 이어서,이번에는 각 서비스마다 Swagger를 설정하여 이를 한 곳에서 통합하여 볼 수 있게끔 적용하려고 합니다. MSA 구조에서 프로젝트를 진행하면, 각 마이크로서비스들이 각각의 애플리케이션에서 돌아가기 때문에모놀리식 구조와 다르게 API 문서들을 관리하는데 어려움이 존재합니다. 쉽게 설명해보자면 모놀리식 구조의 경우 하나의 애플리케이션으로 운영 되므로애플리케이션에 Swagger를 하나만 띄우면 되지만 MSA 구조는 서비스들이 독립적으로 분리되어있기 때문에 서비스마다 Swagger를 띄워줘야합니다.이러한 상황에서 Swagger를 통합해주지 않는다면, API를 받아쓰는 프론트 입장에서는 호출하..
-
MSA) Spring Cloud Eureka에 FastAPI 서버를 Client로 등록하기SpringBoot 2024. 6. 1. 00:21
들어가며저희 팀이 계획한 기획에서 python을 활용하여 데이터 분석과 여러 데이터들을 가져와야할 것 같아MSA 구조의 팀 프로젝트를 수행하기 전에, 연습하고 해당 내용을 기록하고자 글을 작성했습니다. Python 기반의 백엔드 프레임워크를 Flask를 쓸지 FastAPI를 쓸지는 정확히 확정이 되진 않았지만,Flask는 작은 프로젝트에서 다뤄본 경험이 있기도 하고 FastAPI가 좋다고들 하는데 사용해보지는 않아서배워볼겸 FastAPI로 진행하고자 합니다. 적용한 내용을 보기 쉽게 그림으로 그려보았습니다. FastAPI를 설치하기 전에, 가상환경 세팅하기# 가상환경을 만들 디렉토리로 이동$ cd {directory}# 가상환경 만들기$ python3 -m venv {venv name}# 가상환경..
-
Locust를 통해 부하 테스트를 진행하고 Prometheus/Grafana로 모니터링하기SpringBoot 2024. 3. 29. 22:14
멀티 모듈 프로젝트를 구성하여 쿠폰 발급 시스템 개발을 진행했었습니다. 이제 종합적으로 Locust를 사용하여 부하 테스트를 진행하고 각 모듈에 가해지는 부하를 Prometheus에서 지표들을 수집하고, Grafana의 대시보드에서 확인하는 과정을 기록하려고 합니다. 우선 Prometheus와 Grafana 컨테이너를 띄워주고 Prometheus에 접속해줍니다. 현재 지표를 수집할 애플리케이션들이 켜져있지 않으므로 동작시켜 줍니다. Grafana에 접속했는데 현재 저의 경우 아래 사진과 같이 주황색 경고등이 떠있는 것을 확인할 수 있었습니다. 경고등에 마우스를 가져가면 This panel requires Angular (deprecated)라는 문구가 뜨는데 이는 대시보드가 AngularJS가 필요한..
-
프로메테우스와 그라파나를 사용하여 모니터링 수행하기SpringBoot 2024. 3. 28. 10:14
들어가며 우선 서비스 개발과 장기적인 운영 관점에서 애플리케이션을 모니터링하는 것은 매우 중요한 작업입니다. 애플리케이션에서 발생하는 동작들에 대한 메트릭을 수집하여 애플리케이션 성능을 분석하면서 추후에 성능을 최적화할 수 있고, 시스템 내부에서 발생할 수 있는 잠재적인 문제를 빠르게 식별하고 해결하는 데 도움이 될 수 있습니다. 또한 외부로 부터 발생하는 악의적인 활동이나 보안 위협을 식별하고 대응할 수 있기 때문에 모니터링 환경 구축은 필수적이라고 할 수 있습니다. 그러므로 이번에 스프링부트 환경에서 프로메테우스와 그라파나를 사용하여 모니터링 구축을 하면서 공부한 내용들을 기록해보았습니다. 용어 및 개념 Metric 위에서부터 메트릭이라는 용어를 사용했기 때문에, 해당 용어에 대해서 궁금하셨을 수도 ..
-
기존에 동시성 이슈 문제 해결을 위해 사용한 Redisson 대신 Redis의 script를 사용해서 성능 올리기SpringBoot 2024. 3. 24. 00:21
들어가며 public void issue(long couponId, long userId) { // 캐시를 통해 쿠폰에 대한 유효성 검증 수행 CouponRedisEntity coupon = couponCacheService.getCouponCache(couponId); coupon.checkIssuableCoupon(); // 레디스 동시성 이슈 해결하기 위함 distributeLockExecutor.execute("lock_%s".formatted(couponId), 3000, 3000, () -> { couponIssueRedisService.checkCouponIssueQuantity(coupon, userId); issueRequest(couponId, userId); }); } 기존에 위 메소..
-
Mockito 에러 - UnnecessaryStubbingException 해결SpringBoot 2024. 3. 21. 19:53
문제 사용자가 게시판에 올린 미션 인증 글을 관리자가 승인을 해주는 기능을 만들었는데, 이와 관련해서 테스트 코드를 작성하고 있었습니다. 그 중에 사용자가 올린 미션 인증 글의 상태가 승인 대기중인 글이 아닐 때, 이에 맞는 오류 메시지를 반환해야 했습니다. @Test @DisplayName("미션 인증글 승인 - 승인 대기중인 글이 아닐 때, 오류 메시지를 잘 반환하는지?") void acceptMission_4() { // given Team team = TeamMock.create("팀1"); User user = UserMock.create(team, UserRole.MENTOR, passwordEncoder); Mission mission = MissionMock.create(); Mission..
-
쿠폰 발급 요청 시, 확인하는 쿠폰 정보를 Redis Cache에 담아 개선하기SpringBoot 2024. 3. 19. 23:48
들어가며 선착순 쿠폰 발급 기능 개발을 진행하고 있는데, 현재 쿠폰 발급 요청에 대한 서비스 로직에 쿠폰 발급 전에 확인하는 것 중 하나인 해당 쿠폰의 유효성 검증 부분에 개선점이 필요했습니다. Coupon coupon = couponIssueService.findCoupon(couponId); 클라이언트에서 쿠폰 발급 요청 API를 호출할 때마다, 위와 같은 방식으로 데이터베이스에 있는 couponId에 대한 쿠폰 정보를 가져와서, 쿠폰의 유효성 검증을 수행했습니다. 여기서 유효성 검증은 사용자가 쿠폰 발급을 요청한 해당 쿠폰이 발급 가능 기간에 속하는지 검증하는 단계라고 보면 됩니다. 하지만 이러한 방식은 사용자가 요청할 때마다, 데이터베이스에서 값을 조회하기 때문에 순식간에 많은 사용자가 쿠폰 발급..