Skip to content

Consolidate MuxMetrics mux_dropped instrumentation (DSK-132)#173

Merged
daisuke8000 merged 1 commit into
mainfrom
fix/dsk-132-mux-metrics
Jul 5, 2026
Merged

Consolidate MuxMetrics mux_dropped instrumentation (DSK-132)#173
daisuke8000 merged 1 commit into
mainfrom
fix/dsk-132-mux-metrics

Conversation

@daisuke8000

@daisuke8000 daisuke8000 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • record_mux_drop writes to RunStats when present, otherwise the local atomic (bench/test path).
  • mux_drop_count reads from the same single source.

Test plan

  • cargo test -p rustern-core --lib runtime::forward
  • Local CodeRabbit review (0 findings)

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • mux のドロップ行数が、統計情報利用時に正しく集計されるようになりました。
    • 統計情報がある場合とない場合で集計元を切り替え、表示されるドロップ数の整合性を改善しました。

Record mux drops to RunStats or the local counter, not both; mux_drop_count reads from the active source.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

RunStats に mux tier のドロップ行数を返す public な mux_dropped_line_count() メソッドが追加されました。MuxMetrics の mux_drop_count() と record_mux_drop() は、stats フィールドの有無に応じて処理を分岐し、stats が存在する場合は RunStats 側のカウンタを利用・更新し、存在しない場合のみ従来の内部 AtomicU64 (mux_dropped) を使用するよう変更されました。

Changes

ファイル 変更概要
crates/rustern-core/src/runtime/forward.rs RunStats に mux_dropped_line_count() 追加、MuxMetrics の mux_drop_count()/record_mux_drop() を stats 有無で分岐

Sequence Diagram(s)

本変更は分岐ロジックの追加であり、シーケンス図よりも上記フローチャートで十分説明可能です(省略)。

Possibly related issues

  • DSK-132: MuxMetrics の mux_dropped 計測を RunStats 側に寄せる統合作業に直接関連しています。

重大度メモ: 本変更はカウンタ管理のロジック整理のみで、非同期処理・K8s・セキュリティへの影響は見られません。ただし stats あり時に内部 mux_dropped カウンタへの加算が行われなくなるため、両カウンタの値が乖離する可能性がある点は軽微な正確性リスクとして留意してください(severity: low)。

🚥 Pre-merge checks | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning Conventional Commits の prefix がなく、要件を満たしていません。 feat: などの Conventional Commits prefix を付け、72文字以内で変更内容が分かるようにしてください。
Description check ⚠️ Warning 必要な「概要」「変更理由」セクションがなく、テンプレートに沿っていません。 ## 概要 と ## 変更理由 を追加し、変更の要点と理由をそれぞれ簡潔に記載してください。

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 `@crates/rustern-core/src/runtime/forward.rs`:
- Around line 201-215: The stats-enabled path in mux_drop_count() is reading
from the same MuxMetrics state that stderr_reporter() clears via
snapshot_and_reset(), so the count can lose accumulated drops across intervals.
Update the forward::ForwardRuntime readback so mux_drop_count() uses an
independent counter when stats is Some(...), and keep record_mux_drop()
incrementing that separate read path instead of relying on the reporter-owned
mux_dropped_lines state. Use the existing mux_drop_count(), record_mux_drop(),
and MuxMetrics symbols to locate and split the reporting counter from the
persistent readback counter.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 62249526-2770-470f-b61b-d370aeb3dd95

📥 Commits

Reviewing files that changed from the base of the PR and between 27f6afc and 208ebff.

📒 Files selected for processing (1)
  • crates/rustern-core/src/runtime/forward.rs

Comment on lines 201 to 215
pub fn mux_drop_count(&self) -> u64 {
self.mux_dropped.load(Ordering::Relaxed)
if let Some(stats) = &self.stats {
stats.mux_dropped_line_count()
} else {
self.mux_dropped.load(Ordering::Relaxed)
}
}

pub fn record_mux_drop(&self) {
self.mux_dropped.fetch_add(1, Ordering::Relaxed);
if let Some(stats) = &self.stats {
stats.record_mux_dropped_line();
} else {
self.mux_dropped.fetch_add(1, Ordering::Relaxed);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# stderr_reporter がテスト実行中に spawn されるか、interval が短いテストケースが存在するか確認
rg -n 'stderr_reporter|RuntimeStatsConfig' crates/rustern-core --type=rust -A3 -B3

Repository: daisuke8000/rustern

Length of output: 5713


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Run a focused read-only inspection of the stats implementation and its call sites.
sed -n '1,260p' crates/rustern-core/src/runtime/forward.rs
printf '\n---- mux_forward_core ----\n'
sed -n '1,180p' crates/rustern-core/src/runtime/mux_forward_core.rs
printf '\n---- load_multistream excerpt ----\n'
sed -n '360,410p' crates/rustern-core/tests/load_multistream.rs
printf '\n---- usages of mux_drop_count / record_mux_drop / snapshot_and_reset ----\n'
rg -n 'mux_drop_count|record_mux_drop|snapshot_and_reset|mux_dropped_line_count|mux_dropped_lines' crates/rustern-core/src crates/rustern-core/tests -A2 -B2

Repository: daisuke8000/rustern

Length of output: 21570


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# どのタイミングで mux_drop_count() を読むか、load test の流れを確認する。
sed -n '330,365p' crates/rustern-core/tests/load_multistream.rs
printf '\n----\n'
sed -n '410,490p' crates/rustern-core/tests/load_multistream.rs
printf '\n---- mux_metrics tests/usages ----\n'
rg -n 'mux_drop_count\(\)|record_mux_drop\(' crates/rustern-core -A3 -B3

Repository: daisuke8000/rustern

Length of output: 6872


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# load_multistream と bench で stats.reporter が有効なまま mux_drop_count() を読む箇所を確認する。
sed -n '1,120p' crates/rustern-core/tests/load_multistream.rs
printf '\n---- bench excerpt ----\n'
sed -n '430,475p' crates/rustern-core/benches/mux_forward.rs
printf '\n---- stats config defaults / docs ----\n'
sed -n '1,120p' crates/rustern-core/src/runtime/config.rs

Repository: daisuke8000/rustern

Length of output: 10401


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Run a read-only probe to see whether the reporter can reset the counter before the final read.
python3 - <<'PY'
from pathlib import Path
import re

text = Path('crates/rustern-core/tests/load_multistream.rs').read_text()
m = re.search(r'duration\s*=\s*.*?LOSSY_OBSERVE|LOSSY_OBSERVE', text)
print("LOSSY_OBSERVE present:", bool(m))
for pat in [r'LOSSY_OBSERVE\s*:\s*Duration::from_secs\((\d+)\)', r'TEST_HARD_LIMIT\s*:\s*Duration::from_secs\((\d+)\)', r'load_scale\(\)']:
    mm = re.search(pat, text)
    print(pat, "=>", mm.group(1) if mm else None)
PY

Repository: daisuke8000/rustern

Length of output: 400


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# stats reporter の有無と、bench で mux_drop_count() を読む前に interval が回る条件があるか確認する。
rg -n 'RuntimeStatsConfig\s*\{|stats:\s*Some\(|stats:\s*None\(|stderr_reporter\(' crates/rustern-core/tests crates/rustern-core/benches crates/rustern-core/src -A4 -B4

Repository: daisuke8000/rustern

Length of output: 5744


stats 有効時は mux_drop_count() を独立カウンタで読めるようにするべきです

stderr_reporter() が同じ mux_dropped_linessnapshot_and_reset()swap(0) するため、stats: Some(...) の経路では interval を跨いだ後の mux_drop_count() が累積値を欠く可能性があります。MuxMetrics 側の readback は reporter から分離してください。

🤖 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 `@crates/rustern-core/src/runtime/forward.rs` around lines 201 - 215, The
stats-enabled path in mux_drop_count() is reading from the same MuxMetrics state
that stderr_reporter() clears via snapshot_and_reset(), so the count can lose
accumulated drops across intervals. Update the forward::ForwardRuntime readback
so mux_drop_count() uses an independent counter when stats is Some(...), and
keep record_mux_drop() incrementing that separate read path instead of relying
on the reporter-owned mux_dropped_lines state. Use the existing
mux_drop_count(), record_mux_drop(), and MuxMetrics symbols to locate and split
the reporting counter from the persistent readback counter.

@daisuke8000
daisuke8000 merged commit 46436c1 into main Jul 5, 2026
3 checks passed
@daisuke8000
daisuke8000 deleted the fix/dsk-132-mux-metrics branch July 5, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant