Skip to content

fix: Alloy storage(positions)를 호스트 볼륨으로 영속화 - #32

Merged
m-a-king merged 2 commits into
mainfrom
fix/alloy-positions-persistence
Aug 9, 2026
Merged

fix: Alloy storage(positions)를 호스트 볼륨으로 영속화#32
m-a-king merged 2 commits into
mainfrom
fix/alloy-positions-persistence

Conversation

@m-a-king

@m-a-king m-a-king commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Situation

  • core 로그 기반 건수 집계가 실측 약 1.4배 부풀려져 있었다. 최근 14일 파싱 로그 563건 중 220쌍이 완전 동일 라인(같은 span_id, 같은 시각, 같은 내용)이었고, 중복쌍은 항상 "라벨 없는 원본 + __time_shard__ 라벨 복사본" 조합이었다.
  • 원인 체인을 실측으로 확정했다: 매 배포가 provision-alloy.sh 로 Alloy 를 docker rm -f 재생성하는데, 읽기 위치(loki.source.docker 의 positions.yml)가 컨테이너 내부에만 있어 함께 유실된다. 새 수집기는 그 시점에 떠 있는 옛 색(blue/green) 앱 컨테이너의 로그를 처음부터 전량 재전송하고, 도착 시점 기준 40분(time_sharding_ignore_recent)을 넘긴 라인은 Grafana Cloud 가 __time_shard__ 별도 스트림으로 받아 원본 스트림의 exact-dup 드롭을 우회해 중복 저장된다.
  • 확정 증거:
증거 내용
dev 경계 실험 마지막 Alloy 재생성(08-06 09:13) 이전 이벤트만 중복 55건, 이후는 0건
Alloy 기동 로그 기동 1분 뒤 "finished transferring logs, written 약 687KB" 직후 그 컨테이너가 배포 전환으로 삭제됨
prod 대응 중복 이벤트 구간이 promote 시각과 1:1 대응 (07-25에서 27 이벤트는 07-28 promote, 08-01에서 06 이벤트는 08-06 promote)
extractor 박스 배포가 드물어 중복 0건

Task

  • Alloy 컨테이너를 갈아치워도 읽기 위치가 이어지도록 storage 를 호스트에 영속화한다.

Action

  • config 설치(/etc/piki-alloy)와 같은 결로, 재부팅에도 남는 고정 경로 /var/lib/piki-alloy/data 를 만들어 컨테이너의 /var/lib/alloy/data 로 마운트했다.
  • run 명령에 --storage.path=/var/lib/alloy/data 를 명시했다. 미지정 시 기본값이 CWD 상대 경로(data-alloy/)라 이미지 내부 구조(작업 디렉터리)에 묶여 마운트 대상이 흔들리기 때문이다(v1.16.1 run --help 실측: default "data-alloy/").
  • 권한 처리는 두지 않았다. 컨테이너가 root 로 돌아(dev 박스 실측 uid=0) 호스트 root 소유 디렉터리로 충분하다.

Result

  • 배포로 Alloy 가 재생성돼도 커서가 이어져 재수집 자체가 사라진다. 부수 효과로, 재수집이 옛 컨테이너 삭제와의 레이스에서 지면 전환 직전 구간 로그가 통째로 유실될 수 있던 리스크(dev 실측에서 5초 차이로 겨우 이긴 레이스)도 함께 닫힌다.
  • 검증: bash 문법 검사, 운영 고정 버전(v1.16.1) 이미지에서 --storage.path 플래그 존재 확인, 마운트+플래그 조합으로 스모크 기동해 스토리지 파일이 호스트 경로에 실제 생성됨을 확인했다.
  • 주의: 각 박스 최초 1회 배포는 호스트 경로가 비어 있어 기존처럼 한 번 재수집이 일어날 수 있다(그 이후부터 영속). 이미 쌓인 중복 로그는 소급 제거되지 않으므로, 과거 구간 건수 분석은 span_id 기준 dedup 을 병행해야 한다.

연관 이슈

Summary by CodeRabbit

  • 개선 사항
    • Alloy의 위치 정보가 컨테이너 재시작이나 서버 재부팅 후에도 유지됩니다.
    • 영속 데이터 저장 공간이 자동으로 생성되고 Alloy에 연결됩니다.

- 매 배포의 rm -f 재기동이 컨테이너 내부 positions 를 유실해, 새 수집기가 떠 있는 앱 컨테이너 로그를 처음부터 재전송했다. 도착 시점 40분을 넘긴 라인은 Grafana Cloud 가 __time_shard__ 스트림으로 받아 원본과 별개로 저장돼 로그가 약 1.4배 중복됐다(2026-08 core 실측)
- 고정 경로 /var/lib/piki-alloy/data 를 /var/lib/alloy/data 로 마운트하고 --storage.path 를 명시. 미지정 기본값이 CWD 상대(data-alloy/)라 이미지 내부 구조에 묶이기 때문
- 컨테이너가 root 로 돌아(실측 uid=0) chown 은 두지 않았다
@m-a-king m-a-king added the fix 외부 가시적 결함 수정 label Aug 7, 2026
@m-a-king m-a-king self-assigned this Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@m-a-king, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 80fddd21-e878-4caf-9906-8aada3ddd3f6

📥 Commits

Reviewing files that changed from the base of the PR and between 818d25e and 902dce3.

📒 Files selected for processing (1)
  • blocks/alloy/provision-alloy.sh
📝 Walkthrough

Walkthrough

Alloy positions 데이터의 호스트 저장 경로를 추가했다. 컨테이너에 해당 경로를 마운트했다. Alloy 실행 시 --storage.path를 지정했다.

Changes

Alloy 영속 데이터 저장

Layer / File(s) Summary
Alloy 저장 경로 구성
blocks/alloy/provision-alloy.sh
호스트에 /var/lib/piki-alloy/data 디렉터리를 생성한다. 이를 컨테이너의 /var/lib/alloy/data에 마운트한다. Alloy가 해당 경로에 positions 데이터를 저장하도록 --storage.path를 추가한다.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 Alloy의 positions 저장소를 호스트 볼륨으로 영속화하는 주요 변경 사항을 명확하게 설명합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@blocks/alloy/provision-alloy.sh`:
- Around line 129-132: Update the container replacement flow before docker run:
first attempt docker stop --timeout 15 "$NAME" for graceful shutdown, then use
docker rm -f "$NAME" only as the fallback when stopping fails or the container
remains. Preserve the existing error-tolerant behavior and volume mounts.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 048380cb-0bf2-435e-bed4-d6723d253c03

📥 Commits

Reviewing files that changed from the base of the PR and between 1858b0c and 818d25e.

📒 Files selected for processing (1)
  • blocks/alloy/provision-alloy.sh

Comment thread blocks/alloy/provision-alloy.sh
- rm -f 단독은 SIGKILL 이라 positions 마지막 sync(10s 주기) 이후 오프셋과 loki.write 미전송 배치가 유실된다. stop(timeout 15s)이 종료 flush 를 보장하고 rm -f 는 fallback 으로 남긴다
- CodeRabbit 리뷰 수용
@m-a-king
m-a-king merged commit 6fd7ffe into main Aug 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 외부 가시적 결함 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant