Skip to content

Commit 8c89465

Browse files
authored
Merge pull request #204 from GoTogether-Inc/feature/#199
[feature] 성능 모니터링을 위한 커스텀 메트릭 구현
2 parents 5e1a42f + 361d3c2 commit 8c89465

15 files changed

Lines changed: 468 additions & 17 deletions

File tree

src/main/java/com/gotogether/domain/bookmark/service/BookmarkServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.gotogether.domain.user.entity.User;
1717
import com.gotogether.global.apipayload.code.status.ErrorStatus;
1818
import com.gotogether.global.apipayload.exception.GeneralException;
19+
import com.gotogether.global.service.MetricService;
1920

2021
import lombok.RequiredArgsConstructor;
2122

@@ -25,6 +26,7 @@ public class BookmarkServiceImpl implements BookmarkService {
2526

2627
private final BookmarkRepository bookmarkRepository;
2728
private final EventFacade eventFacade;
29+
private final MetricService metricService;
2830

2931
@Override
3032
@Transactional
@@ -39,6 +41,8 @@ public Bookmark createBookmark(Long eventId, Long userId) {
3941
Bookmark bookmark = BookmarkConverter.of(user, event);
4042
bookmarkRepository.save(bookmark);
4143

44+
metricService.recordBookmarkCreation(eventId);
45+
4246
return bookmark;
4347
}
4448

src/main/java/com/gotogether/domain/event/service/EventServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.gotogether.global.apipayload.exception.GeneralException;
2727
import com.gotogether.global.common.service.S3UploadService;
2828
import com.gotogether.global.scheduler.EventScheduler;
29+
import com.gotogether.global.service.MetricService;
2930

3031
import lombok.RequiredArgsConstructor;
3132

@@ -42,6 +43,7 @@ public class EventServiceImpl implements EventService {
4243
private final ReferenceLinkService referenceLinkService;
4344
private final S3UploadService s3UploadService;
4445
private final EventScheduler eventScheduler;
46+
private final MetricService metricService;
4547

4648
@Override
4749
@Transactional
@@ -62,6 +64,9 @@ public Event createEvent(EventRequestDTO request) {
6264
updateBannerImageToFinal(event, request.getBannerImageUrl());
6365

6466
eventScheduler.scheduleUpdateEventStatus(event.getId(), event.getEndDate());
67+
68+
metricService.recordEventCreation(event.getId(), event.getCategory().name());
69+
6570
return event;
6671
}
6772

src/main/java/com/gotogether/domain/hostchannel/service/HostChannelServiceImpl.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.gotogether.domain.hostchannel.service;
22

3+
import java.util.LinkedHashSet;
34
import java.util.List;
45
import java.util.Optional;
56
import java.util.Set;
67
import java.util.stream.Collectors;
7-
import java.util.LinkedHashSet;
88

99
import org.springframework.data.domain.Page;
1010
import org.springframework.data.domain.Pageable;
@@ -34,17 +34,18 @@
3434
import com.gotogether.domain.order.repository.OrderRepository;
3535
import com.gotogether.domain.ticket.entity.Ticket;
3636
import com.gotogether.domain.ticket.repository.TicketRepository;
37+
import com.gotogether.domain.ticketoptionanswer.repository.TicketOptionAnswerRepository;
38+
import com.gotogether.domain.ticketoptionassignment.entity.TicketOptionAssignment;
39+
import com.gotogether.domain.ticketoptionassignment.repository.TicketOptionAssignmentRepository;
3740
import com.gotogether.domain.ticketqrcode.entity.TicketQrCode;
3841
import com.gotogether.domain.ticketqrcode.service.TicketQrCodeService;
3942
import com.gotogether.domain.user.entity.User;
4043
import com.gotogether.domain.user.repository.UserRepository;
4144
import com.gotogether.global.apipayload.code.status.ErrorStatus;
4245
import com.gotogether.global.apipayload.exception.GeneralException;
4346
import com.gotogether.global.common.service.S3UploadService;
47+
import com.gotogether.global.service.MetricService;
4448
import com.gotogether.global.util.ExcelGenerator;
45-
import com.gotogether.domain.ticketoptionassignment.entity.TicketOptionAssignment;
46-
import com.gotogether.domain.ticketoptionassignment.repository.TicketOptionAssignmentRepository;
47-
import com.gotogether.domain.ticketoptionanswer.repository.TicketOptionAnswerRepository;
4849

4950
import lombok.RequiredArgsConstructor;
5051

@@ -59,12 +60,15 @@ public class HostChannelServiceImpl implements HostChannelService {
5960
private final OrderCustomRepository orderCustomRepository;
6061
private final TicketRepository ticketRepository;
6162
private final EventRepository eventRepository;
62-
private final EventFacade eventFacade;
63-
private final TicketQrCodeService ticketQrCodeService;
64-
private final S3UploadService s3UploadService;
6563
private final TicketOptionAssignmentRepository ticketOptionAssignmentRepository;
6664
private final TicketOptionAnswerRepository ticketOptionAnswerRepository;
6765

66+
private final TicketQrCodeService ticketQrCodeService;
67+
private final S3UploadService s3UploadService;
68+
private final MetricService metricService;
69+
70+
private final EventFacade eventFacade;
71+
6872
@Override
6973
@Transactional
7074
public HostChannel createHostChannel(Long userId, HostChannelRequestDTO request) {
@@ -91,6 +95,8 @@ public HostChannel createHostChannel(Long userId, HostChannelRequestDTO request)
9195

9296
updateProfileImageToFinal(newHostChannel, request.getProfileImageUrl());
9397

98+
metricService.recordHostChannelCreation(newHostChannel.getId());
99+
94100
return newHostChannel;
95101
}
96102

src/main/java/com/gotogether/domain/order/service/OrderServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.gotogether.domain.user.entity.User;
3434
import com.gotogether.global.apipayload.code.status.ErrorStatus;
3535
import com.gotogether.global.apipayload.exception.GeneralException;
36+
import com.gotogether.global.service.MetricService;
3637

3738
import lombok.RequiredArgsConstructor;
3839

@@ -46,6 +47,7 @@ public class OrderServiceImpl implements OrderService {
4647
private final TicketQrCodeService ticketQrCodeService;
4748
private final OrderCustomRepository orderCustomRepository;
4849
private final TicketOptionAnswerService ticketOptionAnswerService;
50+
private final MetricService metricService;
4951

5052
@Override
5153
@Transactional
@@ -75,6 +77,9 @@ public List<Order> createOrder(OrderRequestDTO request, Long userId) {
7577
ticketOptionAnswerService.createTicketOptionAnswers(user, answers, order);
7678
}
7779

80+
double totalAmount = ticket.getPrice() * ticketCnt;
81+
metricService.recordTicketPurchase(ticket.getEvent().getId(), ticket.getId(), ticketCnt, totalAmount);
82+
7883
return orders;
7984
}
8085

@@ -114,6 +119,8 @@ public void cancelOrder(OrderCancelRequestDTO request, Long userId) {
114119

115120
Ticket ticket = eventFacade.getTicketById(order.getTicket().getId());
116121

122+
metricService.recordOrderCancellation(ticket.getEvent().getId(), ticket.getPrice());
123+
117124
order.cancelOrder();
118125
ticket.increaseAvailableQuantity();
119126
ticketQrCodeService.deleteQrCode(orderId);

src/main/java/com/gotogether/domain/reservationemail/service/ReservationEmailServiceImpl.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.gotogether.global.apipayload.code.status.ErrorStatus;
2121
import com.gotogether.global.apipayload.exception.GeneralException;
2222
import com.gotogether.global.scheduler.EventScheduler;
23+
import com.gotogether.global.service.MetricService;
2324

2425
import lombok.RequiredArgsConstructor;
2526

@@ -28,9 +29,13 @@
2829
public class ReservationEmailServiceImpl implements ReservationEmailService {
2930

3031
private final ReservationEmailRepository reservationEmailRepository;
31-
private final ReservationEmailFacade reservationEmailFacade;
32-
private final EventFacade eventFacade;
32+
3333
private final EmailService mailService;
34+
private final MetricService metricService;
35+
36+
private final EventFacade eventFacade;
37+
private final ReservationEmailFacade reservationEmailFacade;
38+
3439
private final EventScheduler eventScheduler;
3540

3641
@Override
@@ -48,6 +53,8 @@ public ReservationEmail createReservationEmail(ReservationEmailRequestDTO reques
4853

4954
eventScheduler.scheduleEmail(reservationEmail.getId(), reservationEmail.getReservationDate());
5055

56+
metricService.recordReservationEmailCreation(reservationEmail.getId());
57+
5158
return reservationEmail;
5259
}
5360

@@ -104,6 +111,9 @@ public void sendReservationEmail(Long reservationEmailId) {
104111
);
105112

106113
reservationEmail.markAsSent();
114+
115+
metricService.recordReservationEmailDispatch(reservationEmail.getId());
116+
107117
reservationEmailRepository.save(reservationEmail);
108118
}
109119

src/main/java/com/gotogether/domain/ticketoption/service/TicketOptionServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.gotogether.domain.ticketoptionassignment.repository.TicketOptionAssignmentRepository;
2121
import com.gotogether.global.apipayload.code.status.ErrorStatus;
2222
import com.gotogether.global.apipayload.exception.GeneralException;
23+
import com.gotogether.global.service.MetricService;
2324

2425
import lombok.RequiredArgsConstructor;
2526

@@ -32,6 +33,7 @@ public class TicketOptionServiceImpl implements TicketOptionService {
3233
private final TicketOptionAssignmentRepository ticketOptionAssignmentRepository;
3334
private final TicketRepository ticketRepository;
3435
private final TicketOptionAnswerRepository ticketOptionAnswerRepository;
36+
private final MetricService metricService;
3537

3638
@Override
3739
@Transactional
@@ -47,6 +49,8 @@ public TicketOption createTicketOption(TicketOptionRequestDTO request) {
4749
ticketOptionChoiceRepository.saveAll(choices);
4850
}
4951

52+
metricService.recordTicketOptionCreation(ticketOption.getId());
53+
5054
return ticketOption;
5155
}
5256

src/main/java/com/gotogether/domain/ticketoptionanswer/service/TicketOptionAnswerServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.gotogether.domain.user.repository.UserRepository;
2929
import com.gotogether.global.apipayload.code.status.ErrorStatus;
3030
import com.gotogether.global.apipayload.exception.GeneralException;
31+
import com.gotogether.global.service.MetricService;
3132

3233
import lombok.RequiredArgsConstructor;
3334

@@ -41,6 +42,8 @@ public class TicketOptionAnswerServiceImpl implements TicketOptionAnswerService
4142
private final TicketOptionAssignmentRepository ticketOptionAssignmentRepository;
4243
private final UserRepository userRepository;
4344

45+
private final MetricService metricService;
46+
4447
// 미사용
4548
@Override
4649
@Transactional
@@ -71,6 +74,8 @@ public void createTicketOptionAnswer(Long userId, TicketOptionAnswerRequestDTO r
7174
.answerText(request.getAnswerText())
7275
.build();
7376

77+
metricService.recordTicketOptionAnswerCreation(answer.getId());
78+
7479
ticketOptionAnswerRepository.save(answer);
7580
}
7681

src/main/java/com/gotogether/domain/ticketoptionassignment/service/TicketOptionAssignmentServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.gotogether.domain.ticketoptionassignment.repository.TicketOptionAssignmentRepository;
1313
import com.gotogether.global.apipayload.code.status.ErrorStatus;
1414
import com.gotogether.global.apipayload.exception.GeneralException;
15+
import com.gotogether.global.service.MetricService;
1516

1617
import lombok.RequiredArgsConstructor;
1718

@@ -22,6 +23,7 @@ public class TicketOptionAssignmentServiceImpl implements TicketOptionAssignment
2223
private final TicketRepository ticketRepository;
2324
private final TicketOptionRepository ticketOptionRepository;
2425
private final TicketOptionAssignmentRepository ticketOptionAssignmentRepository;
26+
private final MetricService metricService;
2527

2628
@Override
2729
@Transactional
@@ -48,6 +50,8 @@ public void assignTicketOption(Long ticketId, Long ticketOptionId) {
4850
.ticketOption(ticketOption)
4951
.build();
5052

53+
metricService.recordTicketOptionAssignment(ticketOptionId, ticketId);
54+
5155
ticketOptionAssignmentRepository.save(assignment);
5256
}
5357

src/main/java/com/gotogether/domain/ticketqrcode/service/TicketQrCodeServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.gotogether.domain.ticketqrcode.repository.TicketQrCodeRepository;
2424
import com.gotogether.global.apipayload.code.status.ErrorStatus;
2525
import com.gotogether.global.apipayload.exception.GeneralException;
26+
import com.gotogether.global.service.MetricService;
2627

2728
import jakarta.transaction.Transactional;
2829
import lombok.RequiredArgsConstructor;
@@ -33,6 +34,7 @@ public class TicketQrCodeServiceImpl implements TicketQrCodeService {
3334

3435
private final TicketQrCodeRepository ticketQrCodeRepository;
3536
private final EventFacade eventFacade;
37+
private final MetricService metricService;
3638

3739
@Value("${qr.secret-key}")
3840
private String qrSecretKey;
@@ -67,6 +69,8 @@ public void validateSignedQrCode(Long orderId, String sig) {
6769

6870
TicketQrCode qrCode = getAvailableQrCode(order);
6971
qrCode.updateStatus(TicketQrCodeStatus.USED);
72+
73+
metricService.recordTicketUsage(orderId, order.getTicket().getEvent().getId());
7074
}
7175

7276
private String generateSignedQrCodeImage(Order order) {

src/main/java/com/gotogether/global/apipayload/code/status/ErrorStatus.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public enum ErrorStatus implements BaseErrorCode {
6464
_TICKET_OPTION_ALREADY_ASSIGNED(HttpStatus.BAD_REQUEST, "TICKET_OPTION_ASSIGN4002", "이미 해당 티켓 옵션이 부착되어 있습니다."),
6565
_TICKET_OPTION_CHOICE_NOT_FOUND(HttpStatus.NOT_FOUND, "TICKET_OPTION_CHOICE4001", "선택지를 찾을 수 없습니다."),
6666
_TICKET_OPTION_ALREADY_ANSWERED(HttpStatus.BAD_REQUEST, "TICKET_OPTION_ANSWER4001", "이미 응답된 티켓 옵션입니다."),
67+
6768
// 미사용
6869
_TICKET_OPTION_ANSWER_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, "TICKET_OPTION_ANSWER4002", "해당 티켓 옵션에 대한 응답이 이미 존재합니다."),
6970

@@ -74,7 +75,9 @@ public enum ErrorStatus implements BaseErrorCode {
7475
_SMS_ALREADY_SEND(HttpStatus.BAD_REQUEST, "SMS4001", "이미 인증 코드가 발송되었습니다."),
7576
_SMS_CERTIFICATION_EXPIRED(HttpStatus.BAD_REQUEST, "SMS4002", "인증 코드가 만료되었습니다."),
7677
_SMS_CERTIFICATION_MISMATCH(HttpStatus.BAD_REQUEST, "SMS4003", "인증 코드가 일치하지 않습니다."),
77-
_SMS_SEND_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "SMS5001", "SMS 전송에 실패했습니다.");
78+
_SMS_SEND_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "SMS5001", "SMS 전송에 실패했습니다."),
79+
80+
_S3_URL_GENERATION_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "S35001", "S3 Pre-signed URL 생성에 실패했습니다.");
7881

7982
private final HttpStatus httpStatus;
8083
private final String code;

0 commit comments

Comments
 (0)