Skip to content

fix: gate ranking readers on fresh-aggregate matview window - #4355

Merged
akshaydeo merged 1 commit into
devfrom
rankings-matview-fresh-gate
Jun 15, 2026
Merged

fix: gate ranking readers on fresh-aggregate matview window#4355
akshaydeo merged 1 commit into
devfrom
rankings-matview-fresh-gate

Conversation

@akshaydeo

@akshaydeo akshaydeo commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Ranking readers (GetModelRankings, GetUserRankings, GetDimensionRankings) were using canUseMatView to decide whether to query mv_logs_hourly. For short time windows, mv_logs_hourly rounds the window out to full hour buckets, which inflates ranking totals relative to the raw-path stats and cost-histogram numbers shown on the same dashboard. This PR switches all three ranking readers to use canUseMatViewForFreshAggregate — the same gate already used by /api/logs/stats and /api/logs — so that short windows consistently fall back to the raw table across all surfaces.

Changes

  • GetModelRankings, GetUserRankings, and GetDimensionRankings now call canUseMatViewForFreshAggregate instead of canUseMatView, ensuring short windows bypass the materialized view.
  • The canUseMatViewForFreshAggregate doc comment is updated to reflect that ranking readers are now also governed by this gate.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

Run the log store tests and verify that ranking queries for short time windows (less than 24 hours) route to the raw table rather than the materialized view.

go test ./framework/logstore/...

Manually verify on a dashboard with a short time window (e.g. last 1 hour) that model/user/dimension ranking totals match the stats and cost-histogram totals shown alongside them.

Screenshots/Recordings

N/A

Breaking changes

  • Yes
  • No

Related issues

N/A

Security considerations

None.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

Summary by CodeRabbit

  • Documentation

    • Clarified time window handling requirements for ranking queries to ensure consistent metrics.
  • Refactor

    • Updated ranking query optimization logic to improve consistency across different time windows and data sources.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@akshaydeo, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 1 hour, 40 minutes, and 54 seconds. Learn how PR review limits work.

To continue reviewing without waiting, enable usage-based billing in the billing tab.

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e2e6d319-a591-4bb6-b437-6371d101a279

📥 Commits

Reviewing files that changed from the base of the PR and between 877a9e8 and 97cdca5.

📒 Files selected for processing (2)
  • framework/logstore/matviews.go
  • framework/logstore/rdb.go
📝 Walkthrough

Walkthrough

This PR updates the matview eligibility check for ranking functions in the logstore to use the fresh-aggregate rule, ensuring consistency with API logs endpoints. Documentation is clarified, and three ranking functions adopt the same 24-hour minimum-window policy to prevent hourly-rounded matview data from distorting short-window rankings.

Changes

Fresh-aggregate matview eligibility for ranking functions

Layer / File(s) Summary
Clarify fresh-aggregate matview documentation
framework/logstore/matviews.go
Updated the canUseMatViewForFreshAggregate comment to include ranking readers alongside existing logs/stats API call sites.
Apply fresh-aggregate matview eligibility to ranking functions
framework/logstore/rdb.go
GetModelRankings, GetUserRankings, and GetDimensionRankings now gate their matview paths with canUseMatViewForFreshAggregate instead of generic matview checks, with updated comments explaining hourly-rounding effects on rankings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through matviews so bright,
Fresh aggregates keeping the rankings right,
Twenty-four hours in a consistent span,
No hourly rounding to muss up the plan—
Hopping from stats to rankings, all day!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The linked issue #123 concerns File API support for providers (OpenAI, Anthropic), which is unrelated to the ranking reader matview changes in this PR. Verify that the correct issues are linked. The PR addresses matview window gating for ranking readers, not File API support. Update linked issues accordingly or remove if incorrectly associated.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: switching ranking readers to use the fresh-aggregate matview window gate.
Description check ✅ Passed The PR description provides a comprehensive summary, detailed changes, and testing instructions aligned with the template.
Out of Scope Changes check ✅ Passed The code changes in matviews.go and rdb.go are focused and directly address the stated objective of gating ranking readers on the fresh-aggregate matview window.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rankings-matview-fresh-gate

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

@akshaydeo
akshaydeo marked this pull request as ready for review June 12, 2026 22:24
@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — the change is a one-line gate swap in each of three functions, all existing matview eligibility checks are still enforced, and the new gate is already battle-tested on the stats and pagination paths.

The replacement function is a strict superset of the old gate (it calls canUseMatView internally and adds a window-size check on top), so the matview path can only become less frequently taken — never incorrectly enabled. The fanoutFrom guard in GetDimensionRankings is preserved. The doc-comment update is accurate. No logic paths were added or removed.

No files require special attention.

Important Files Changed

Filename Overview
framework/logstore/matviews.go Doc comment updated to list the three ranking readers as additional callers of canUseMatViewForFreshAggregate — accurate and complete.
framework/logstore/rdb.go GetModelRankings, GetUserRankings, and GetDimensionRankings each have their canUseMatView call replaced with canUseMatViewForFreshAggregate; the fanoutFrom guard in GetDimensionRankings is preserved, and new inline comments explain the rationale.

Reviews (2): Last reviewed commit: "fix: gate ranking readers on fresh-aggre..." | Re-trigger Greptile

Comment thread framework/logstore/rdb.go
Model/user/dimension rankings used bare canUseMatView, so short dashboard
windows (1h/6h) were served from mv_logs_hourly, which rounds the window
out to full hour buckets and inflates ranking costs/requests by up to 2x
against the raw-path stats and cost-histogram totals on the same page.
Rankings now use canUseMatViewForFreshAggregate, same as GetStats and the
pagination count: windows under 24h go to the raw logs table.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@akshaydeo
akshaydeo force-pushed the rankings-matview-fresh-gate branch from 877a9e8 to 97cdca5 Compare June 15, 2026 13:27

akshaydeo commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Jun 15, 1:49 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 15, 1:50 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo merged commit 3e2f859 into dev Jun 15, 2026
13 of 15 checks passed
@akshaydeo
akshaydeo deleted the rankings-matview-fresh-gate branch June 15, 2026 13:50
akshaydeo added a commit that referenced this pull request Jun 15, 2026
## Summary

Ranking readers (`GetModelRankings`, `GetUserRankings`, `GetDimensionRankings`) were using `canUseMatView` to decide whether to query `mv_logs_hourly`. For short time windows, `mv_logs_hourly` rounds the window out to full hour buckets, which inflates ranking totals relative to the raw-path stats and cost-histogram numbers shown on the same dashboard. This PR switches all three ranking readers to use `canUseMatViewForFreshAggregate` — the same gate already used by `/api/logs/stats` and `/api/logs` — so that short windows consistently fall back to the raw table across all surfaces.

## Changes

- `GetModelRankings`, `GetUserRankings`, and `GetDimensionRankings` now call `canUseMatViewForFreshAggregate` instead of `canUseMatView`, ensuring short windows bypass the materialized view.
- The `canUseMatViewForFreshAggregate` doc comment is updated to reflect that ranking readers are now also governed by this gate.

## Type of change

- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

Run the log store tests and verify that ranking queries for short time windows (less than 24 hours) route to the raw table rather than the materialized view.

```sh
go test ./framework/logstore/...
```

Manually verify on a dashboard with a short time window (e.g. last 1 hour) that model/user/dimension ranking totals match the stats and cost-histogram totals shown alongside them.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

None.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Documentation**
  * Clarified time window handling requirements for ranking queries to ensure consistent metrics.

* **Refactor**
  * Updated ranking query optimization logic to improve consistency across different time windows and data sources.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
…4355)

## Summary

Ranking readers (`GetModelRankings`, `GetUserRankings`, `GetDimensionRankings`) were using `canUseMatView` to decide whether to query `mv_logs_hourly`. For short time windows, `mv_logs_hourly` rounds the window out to full hour buckets, which inflates ranking totals relative to the raw-path stats and cost-histogram numbers shown on the same dashboard. This PR switches all three ranking readers to use `canUseMatViewForFreshAggregate` — the same gate already used by `/api/logs/stats` and `/api/logs` — so that short windows consistently fall back to the raw table across all surfaces.

## Changes

- `GetModelRankings`, `GetUserRankings`, and `GetDimensionRankings` now call `canUseMatViewForFreshAggregate` instead of `canUseMatView`, ensuring short windows bypass the materialized view.
- The `canUseMatViewForFreshAggregate` doc comment is updated to reflect that ranking readers are now also governed by this gate.

## Type of change

- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

Run the log store tests and verify that ranking queries for short time windows (less than 24 hours) route to the raw table rather than the materialized view.

```sh
go test ./framework/logstore/...
```

Manually verify on a dashboard with a short time window (e.g. last 1 hour) that model/user/dimension ranking totals match the stats and cost-histogram totals shown alongside them.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

None.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Documentation**
  * Clarified time window handling requirements for ranking queries to ensure consistent metrics.

* **Refactor**
  * Updated ranking query optimization logic to improve consistency across different time windows and data sources.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
occcat pushed a commit to occcat/bifrost that referenced this pull request Sep 2, 2026
…4355)

## Summary

Ranking readers (`GetModelRankings`, `GetUserRankings`, `GetDimensionRankings`) were using `canUseMatView` to decide whether to query `mv_logs_hourly`. For short time windows, `mv_logs_hourly` rounds the window out to full hour buckets, which inflates ranking totals relative to the raw-path stats and cost-histogram numbers shown on the same dashboard. This PR switches all three ranking readers to use `canUseMatViewForFreshAggregate` — the same gate already used by `/api/logs/stats` and `/api/logs` — so that short windows consistently fall back to the raw table across all surfaces.

## Changes

- `GetModelRankings`, `GetUserRankings`, and `GetDimensionRankings` now call `canUseMatViewForFreshAggregate` instead of `canUseMatView`, ensuring short windows bypass the materialized view.
- The `canUseMatViewForFreshAggregate` doc comment is updated to reflect that ranking readers are now also governed by this gate.

## Type of change

- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

Run the log store tests and verify that ranking queries for short time windows (less than 24 hours) route to the raw table rather than the materialized view.

```sh
go test ./framework/logstore/...
```

Manually verify on a dashboard with a short time window (e.g. last 1 hour) that model/user/dimension ranking totals match the stats and cost-histogram totals shown alongside them.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

None.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Documentation**
  * Clarified time window handling requirements for ranking queries to ensure consistent metrics.

* **Refactor**
  * Updated ranking query optimization logic to improve consistency across different time windows and data sources.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

2 participants