-
Notifications
You must be signed in to change notification settings - Fork 1
Test/#184 loadtest #185
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
base: develop
Are you sure you want to change the base?
Test/#184 loadtest #185
Changes from 3 commits
766a1a4
9441468
49d277a
a7891f4
134f94a
ccd472e
f110cc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package KUSITMS.WITHUS.global.infra.email.sender; | ||
|
|
||
| import KUSITMS.WITHUS.global.infra.email.MailProperties; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.core.io.InputStreamSource; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.support.TransactionSynchronization; | ||
| import org.springframework.transaction.support.TransactionSynchronizationManager; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * μ€μ λ°μ‘ μμ΄ λ°μ‘ μ§μ°λ§ μ¬ννλ ꡬν체. | ||
| * λΆν ν μ€νΈμμ SendGrid/Gmail μΌμΌ νλλ₯Ό μλͺ¨νμ§ μκΈ° μν΄ μ¬μ©νλ€. | ||
| * | ||
| * <p>{@link SmtpMailSender}, {@link SendGridMailSender} μ λμΌνκ² μ»€λ° μ΄νμ λμνλ€. | ||
| * νΈλμμ μμμ μ§μ°μ μ£Όλ©΄ DB 컀λ₯μ μ μ μκ°μ΄ ν¨κ» λμ΄λ μ ν λ€λ₯Έ κ²μ μΈ‘μ νκ² λλ―λ‘ | ||
| * afterCommit ꡬ쑰λ₯Ό λ°λμ λ§μΆ°μΌ νλ€. | ||
| */ | ||
| @Slf4j | ||
| @Component | ||
| @Profile("!test") | ||
| @ConditionalOnProperty(name = "mail.provider", havingValue = "noop") | ||
| @RequiredArgsConstructor | ||
| public class NoopMailSender implements MailSender { | ||
|
|
||
| private final MailProperties mailProperties; | ||
|
|
||
| @Override | ||
| public void send(String to, String subject, String text) { | ||
| simulateAfterCommit(to, subject); | ||
| } | ||
|
|
||
| @Override | ||
| public void sendWithAttachments( | ||
| String to, | ||
| String subject, | ||
| String html, | ||
| List<InputStreamSource> attachments | ||
| ) { | ||
| simulateAfterCommit(to, subject); | ||
| } | ||
|
|
||
| private void simulateAfterCommit(String to, String subject) { | ||
| if (!TransactionSynchronizationManager.isSynchronizationActive()) { | ||
| simulate(to, subject); | ||
| return; | ||
| } | ||
|
|
||
| TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { | ||
| @Override | ||
| public void afterCommit() { | ||
| simulate(to, subject); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void simulate(String to, String subject) { | ||
| long delayMs = mailProperties.getNoopDelayMs(); | ||
|
|
||
| if (delayMs > 0) { | ||
| try { | ||
| Thread.sleep(delayMs); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| log.info("Email skipped by noop provider (simulated {}ms): [{}] subject: {}", delayMs, to, subject); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,10 +83,14 @@ private void sendMail(String to, String subject, String html, List<InputStreamSo | |
| .POST(HttpRequest.BodyPublishers.ofString(requestBody)) | ||
| .build(); | ||
|
|
||
| long startedAt = System.nanoTime(); | ||
| HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); | ||
| long elapsedMs = (System.nanoTime() - startedAt) / 1_000_000L; | ||
|
|
||
| if (response.statusCode() != ACCEPTED) { | ||
| log.error( | ||
| "SendGrid rejected email: status={} to={} subject={} body={}", | ||
| "SendGrid rejected email in {}ms: status={} to={} subject={} body={}", | ||
| elapsedMs, | ||
|
Comment on lines
+86
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π Maintainability & Code Quality | π‘ Minor | β‘ Quick win μμΈ κ²½λ‘μλ SendGrid μ μ‘ μκ°μ κΈ°λ‘νμΈμ.
π€ Prompt for AI Agents |
||
| response.statusCode(), | ||
| to, | ||
| subject, | ||
|
|
@@ -96,7 +100,13 @@ private void sendMail(String to, String subject, String html, List<InputStreamSo | |
| } | ||
|
|
||
| String messageId = response.headers().firstValue("X-Message-Id").orElse("unknown"); | ||
| log.info("Email accepted by SendGrid: [{}] subject: {} messageId: {}", to, subject, messageId); | ||
| log.info( | ||
| "Email accepted by SendGrid in {}ms: [{}] subject: {} messageId: {}", | ||
| elapsedMs, | ||
| to, | ||
| subject, | ||
| messageId | ||
| ); | ||
| } catch (CustomException e) { | ||
| throw e; | ||
| } catch (IOException e) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Security & Privacy | π Major | β‘ Quick win
μμ μ μ΄λ©μΌμ INFO λ‘κ·Έμμ μ κ±°νμμμ€.
ApplicationMailServiceλapplication.getEmail()μtoλ‘ μ λ¬ν©λλ€. μ΄ λ‘κ·Έλ noop λ°μ‘λ§λ€ μμ μ μ΄λ©μΌμ μλ¬ΈμΌλ‘ κΈ°λ‘ν©λλ€. λΆν ν μ€νΈ μ€ λλμ κ°μΈμ λ³΄κ° μ ν리μΌμ΄μ λ‘κ·Έμ λ¨μ΅λλ€.μμ μμ μ λͺ©μ λ‘κ·Έμμ μ κ±°νκ±°λ λΉμλ³ννμμμ€.
μμ μμ
π Committable suggestion
π€ Prompt for AI Agents