Skip to content

proxy: preserve wall-clock duration in metrics#629

Merged
mostlygeek merged 1 commit into
mostlygeek:mainfrom
SuperMarioYL:bugfix/llama-swap-602
Apr 7, 2026
Merged

proxy: preserve wall-clock duration in metrics#629
mostlygeek merged 1 commit into
mostlygeek:mainfrom
SuperMarioYL:bugfix/llama-swap-602

Conversation

@SuperMarioYL
Copy link
Copy Markdown
Contributor

Keep request duration from being underreported when upstream timings only cover part of the full request lifecycle.

  • compare wall-clock and upstream timing durations
  • keep token and throughput values from timings
  • add regression coverage for underreported timings

fixes #602

Keep request duration from being underreported when upstream timings only cover a subset of the full request lifecycle.

- compare wall-clock and upstream timing durations
- keep token and throughput values from timings
- add regression coverage for underreported timings

fixes mostlygeek#602
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9aa228bb-4efc-4d30-b4a4-def9c44fbfbd

📥 Commits

Reviewing files that changed from the base of the PR and between a37b486 and 27d0204.

📒 Files selected for processing (2)
  • proxy/metrics_monitor.go
  • proxy/metrics_monitor_test.go

Walkthrough

The PR modifies duration calculation in the metrics parser to compute wall-clock duration once and compare it against timing-derived duration, selecting the greater value instead of unconditionally using timing data when available.

Changes

Cohort / File(s) Summary
Duration Calculation Logic
proxy/metrics_monitor.go
Modified parseMetrics to compute wallDurationMs once using time.Since(start).Milliseconds(), then update durationMs only if the summed timingsDurationMs exceeds the wall-clock based value, preventing timing data from underreporting actual request duration.
Test Coverage
proxy/metrics_monitor_test.go
Added subtest and github.com/tidwall/gjson import to validate parseMetrics behavior when timing-derived duration is lower than wall-clock time, asserting that metrics.DurationMs reflects the greater value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

🚥 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 The title accurately summarizes the main code change: preserving wall-clock duration in metrics by comparing it with upstream timing duration.
Description check ✅ Passed The description clearly relates to the changeset, explaining the issue of underreported duration and the solution to compare and preserve wall-clock duration.
Linked Issues check ✅ Passed The PR addresses issue #602 by computing wall-clock duration and using maximum of wall-clock vs upstream timing duration, ensuring Activity duration reflects actual request lifetime.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the duration calculation issue: metrics parsing logic for wall-clock duration preservation and regression test coverage.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@mostlygeek
Copy link
Copy Markdown
Owner

Nice thanks for this fix!

@mostlygeek mostlygeek merged commit 06bc6a6 into mostlygeek:main Apr 7, 2026
3 checks passed
@candrews
Copy link
Copy Markdown

@mostlygeek can you please make a release so us users can enjoy this and the other improvement made since the last release?

Thank you!

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.

Duration is incorrect

3 participants