Skip to content

[FEAT] elasticsearch에도 변경된 경매 상태 반영#12

Open
imprity wants to merge 1 commit into
devfrom
feat/elasticsearch-state
Open

[FEAT] elasticsearch에도 변경된 경매 상태 반영#12
imprity wants to merge 1 commit into
devfrom
feat/elasticsearch-state

Conversation

@imprity
Copy link
Copy Markdown

@imprity imprity commented May 20, 2026

📝 작업 내용

경매 상태가 변경될 때 elasticsearch에도 변경된 경매 상태를 반영하도록 수정

✅ 체크리스트 (Checklist)

  • 브랜치 이름 규칙을 준수했나요? (예: feat/login)
  • 코딩 컨벤션을 준수했나요?
  • 기능에 대한 테스트 코드를 작성/수행했나요?
  • 불필요한 주석이나 로그(console.log)를 제거했나요?

💬 기타 사항

제대로된 테스트를 진행하지는 못했지만 elasticsearch에 http 요청을 보내는 부분만 떼어내어 실행해 본 결과 정상 작동함을 확인하였습니다.

Summary by CodeRabbit

변경 사항

  • 새로운 기능
    • 경매 상태 동기화 기능이 추가되었습니다.
    • 경매 시작, 종료(낙찰), 유찰 시 상태가 실시간으로 자동 업데이트됩니다.
    • 상태 업데이트 실패 시 자동으로 로그가 기록됩니다.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Walkthrough

AuctionSqsLambda에 Elasticsearch 경매 상태 동기화 기능 추가. 환경변수 기반으로 HttpClient와 Basic Auth를 설정한 후, 경매의 START/END 처리 시점에 경매 상태를 Elasticsearch /_update 엔드포인트로 POST 전송하고 응답/예외 로깅.

Changes

Elasticsearch 경매 상태 동기화

Layer / File(s) Summary
Elasticsearch 클라이언트 및 환경설정
src/com/example/lambda/AuctionSqsLambda.java
java.net.http 관련 import 추가 및 Elasticsearch URI/인덱스명/자격증명 환경변수 상수 정의. 연결 타임아웃 설정된 HttpClient 인스턴스 생성.
경매 상태 동기화 메서드 구현
src/com/example/lambda/AuctionSqsLambda.java
updateElasticsearchStatus(Long auctionId, String status, Context context) 메서드 추가. 상태값을 JSON으로 직렬화해 Elasticsearch /_update 엔드포인트로 POST 전송. 300 이상 응답 코드 및 예외 발생 시 로깅.
경매 처리 흐름에 동기화 호출 통합
src/com/example/lambda/AuctionSqsLambda.java
경매 처리의 START(ACTIVE), 낙찰 END(DONE), 유찰 END(NO_BID) 각 분기에서 캐시 evict 후 updateElasticsearchStatus 호출 추가.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • GigaMak2/auction-lambda#8: START/END 경매 처리 흐름 변경과 관련. 해당 PR은 입찰 상태를 CLOSED로 업데이트하고 Redis 이벤트를 발행하는 로직을 추가하고, 본 PR은 같은 지점에서 Elasticsearch 상태 동기화를 추가.

Suggested reviewers

  • soomin0209
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 '[FEAT] elasticsearch에도 변경된 경매 상태 반영'으로, 변경사항의 핵심인 Elasticsearch 경매 상태 동기화 기능을 명확하게 요약하고 있습니다.
Description check ✅ Passed PR 설명이 템플릿 구조를 따르며 주요 섹션(작업 내용, 체크리스트, 기타 사항)을 포함하고 있고, 작성자가 테스트 수행 현황을 투명하게 기술했습니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/elasticsearch-state

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@imprity imprity added the enhancement New feature or request label May 20, 2026
@imprity
Copy link
Copy Markdown
Author

imprity commented May 20, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/com/example/lambda/AuctionSqsLambda.java (2)

318-326: 💤 Low value

InterruptedException 처리 개선 고려

httpClient.send()InterruptedException을 던질 수 있습니다. 현재 코드에서는 이를 일반 Exception으로 catch하여 로그만 남기고 있는데, 인터럽트 상태를 복원하지 않으면 상위 호출자가 인터럽트를 감지할 수 없습니다.

Lambda 환경에서는 심각한 문제가 아니지만, 베스트 프랙티스를 위해 고려할 수 있습니다.

♻️ InterruptedException 처리 제안
-        } catch (Exception e) {
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            context.getLogger().log("[ES] status update 인터럽트: auctionId=%d, %s".formatted(
+                    auctionId, e.getMessage()));
+        } catch (Exception e) {
             context.getLogger().log("[ES] status update 예외: auctionId=%d, %s".formatted(
                     auctionId, e.getMessage()));
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/com/example/lambda/AuctionSqsLambda.java` around lines 318 - 326, The
catch-all Exception block around the httpClient.send call swallows
InterruptedException and doesn't restore the thread's interrupt status; update
AuctionSqsLambda's httpClient.send handling by adding a specific catch
(InterruptedException ie) that logs the interruption (using
context.getLogger().log with auctionId) and then calls
Thread.currentThread().interrupt() before exiting/returning, and keep the
existing catch (Exception e) for other exceptions so normal errors are still
logged via the same pattern.

50-60: 💤 Low value

환경 변수 null 체크 고려

ES_USERNAME 또는 ES_PASSWORD가 설정되지 않은 경우 System.getenv()null을 반환하고, Java에서 null + ":""null:" 문자열이 됩니다. 이로 인해 잘못된 Basic Auth 헤더가 생성되어 ES에서 401 오류가 발생합니다.

배포 시 환경 변수 누락을 조기에 감지하려면 null 체크를 추가하는 것이 좋습니다.

🛡️ 방어적 null 체크 제안
     private static final String ES_URL = System.getenv("ELASTICSEARCH_URIS");
     private static final String ES_AUCTION_INDEX = System.getenv("ELASTICSEARCH_AUCTION_INDEX");
     private static final String ES_USERNAME = System.getenv("ELASTICSEARCH_USERNAME");
     private static final String ES_PASSWORD = System.getenv("ELASTICSEARCH_PASSWORD");

-    private static final String ES_BASIC_AUTH = "Basic " + java.util.Base64.getEncoder()
-        .encodeToString((ES_USERNAME + ":" + ES_PASSWORD).getBytes(java.nio.charset.StandardCharsets.UTF_8));
+    private static final String ES_BASIC_AUTH;
+    static {
+        if (ES_URL == null || ES_AUCTION_INDEX == null || ES_USERNAME == null || ES_PASSWORD == null) {
+            throw new IllegalStateException("Elasticsearch 환경 변수가 설정되지 않았습니다.");
+        }
+        ES_BASIC_AUTH = "Basic " + java.util.Base64.getEncoder()
+            .encodeToString((ES_USERNAME + ":" + ES_PASSWORD).getBytes(java.nio.charset.StandardCharsets.UTF_8));
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/com/example/lambda/AuctionSqsLambda.java` around lines 50 - 60, The
static initialization currently builds ES_BASIC_AUTH from ES_USERNAME and
ES_PASSWORD without null checks; add defensive validation in the
AuctionSqsLambda static init (or a small helper like validateEnvVar) to assert
ES_USERNAME and ES_PASSWORD are non-null/non-empty and if they are missing throw
an IllegalStateException (or log and abort startup) with a clear message naming
the missing env var(s); then compute ES_BASIC_AUTH using the validated values so
you never encode "null:password" or "username:null".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/com/example/lambda/AuctionSqsLambda.java`:
- Around line 318-326: The catch-all Exception block around the httpClient.send
call swallows InterruptedException and doesn't restore the thread's interrupt
status; update AuctionSqsLambda's httpClient.send handling by adding a specific
catch (InterruptedException ie) that logs the interruption (using
context.getLogger().log with auctionId) and then calls
Thread.currentThread().interrupt() before exiting/returning, and keep the
existing catch (Exception e) for other exceptions so normal errors are still
logged via the same pattern.
- Around line 50-60: The static initialization currently builds ES_BASIC_AUTH
from ES_USERNAME and ES_PASSWORD without null checks; add defensive validation
in the AuctionSqsLambda static init (or a small helper like validateEnvVar) to
assert ES_USERNAME and ES_PASSWORD are non-null/non-empty and if they are
missing throw an IllegalStateException (or log and abort startup) with a clear
message naming the missing env var(s); then compute ES_BASIC_AUTH using the
validated values so you never encode "null:password" or "username:null".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: eca4bcd3-b4c5-43a4-bd26-7513e1e56b5e

📥 Commits

Reviewing files that changed from the base of the PR and between 32a868b and 701feed.

📒 Files selected for processing (1)
  • src/com/example/lambda/AuctionSqsLambda.java

@imprity imprity requested a review from hhjo96 May 20, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant