Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature : async error handler with slack alarm #322

Merged
merged 4 commits into from
Feb 8, 2023

Conversation

ImNM
Copy link
Member

@ImNM ImNM commented Feb 7, 2023

개요

작업사항

  • 비동기 처리시 오류가 발생하면 다른 스레드라서 서블릿으로 리턴되는게 아니므로
  • 비동기 오류 인터셉터해서 슬랙 알림 처리했습니다.
    무제

변경로직

  • 변경로직 밑에 코멘트 확인바랍니다

그리구 앞으로 도메인 이벤트에 롬복 tostring 달아주시면 감사하겠습니다.!
비동기 요청으로 넘어온 파라미터들을 받을 수 있는데

로그로 남겨서 위 사진에 요청 파라미터처럼 내용이보이면 디버깅 하기 더 쉬울듯 합니다!

@ImNM ImNM added For: Utils [이슈 대상] API, 모델, 뷰를 제외한 백엔드 로직 Type: Feature [이슈 목적] 새로운 기능 추가 Type: Refactor [이슈 목적] 프로덕션 코드 리팩토링 labels Feb 7, 2023
@ImNM ImNM requested a review from sanbonai06 as a code owner February 7, 2023 14:41
@ImNM ImNM self-assigned this Feb 7, 2023
Comment on lines +45 to +62

@Async
public void sendNotification(List<LayoutBlock> layoutBlocks) {
if (!isNeedToNotificationProfile()) {
return;
}
ChatPostMessageRequest chatPostMessageRequest =
ChatPostMessageRequest.builder()
.channel(CHANNEL_ID)
.text("")
.blocks(layoutBlocks)
.build();
try {
methodsClient.chatPostMessage(chatPostMessageRequest);
} catch (SlackApiException | IOException slackApiException) {
log.error(slackApiException.toString());
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

슬랙 프로바이더를
인프라 모듈로 빼었습니다.

import org.springframework.web.util.ContentCachingRequestWrapper;

@Component
@RequiredArgsConstructor
@Slf4j
public class SlackApiProvider {
private final MethodsClient methodsClient;
public class SlackInternalErrorSender {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 샌더는
api 모듈에 config 에서 slack 패키지로 위치를 이동시켰습니다
@gengminy 경민형이 아마 여기서 유저랑 우리 를 위한 슬랙 샌더 작업하시면 될것같습니다

Comment on lines -102 to +74
ChatPostMessageRequest chatPostMessageRequest =
ChatPostMessageRequest.builder()
.channel(CHANNEL_ID)
.text("")
.blocks(layoutBlocks)
.build();
try {
methodsClient.chatPostMessage(chatPostMessageRequest);
} catch (SlackApiException slackApiException) {
log.error(slackApiException.toString());
}
slackProvider.sendNotification(layoutBlocks);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layoutBlocks 을 인자로 받아서
보냅니다
비동기 관련 어노테이션은
slackProvider.sendNotification
해당 메소드로 위치시켰습니다.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 306 Code Smells

16.4% 16.4% Coverage
0.0% 0.0% Duplication

Copy link
Member

@gengminy gengminy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

슬랙 설정 이동한 거 확인입니다

Copy link
Member

@sanbonai06 sanbonai06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니당 수고하셨어용

@ImNM ImNM merged commit 12ebcc3 into dev Feb 8, 2023
@ImNM ImNM deleted the feature/309-async-error-handler branch February 8, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For: Utils [이슈 대상] API, 모델, 뷰를 제외한 백엔드 로직 Type: Feature [이슈 목적] 새로운 기능 추가 Type: Refactor [이슈 목적] 프로덕션 코드 리팩토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 [feature] async 에러 핸들링
3 participants