Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions framework/logstore/matviews.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,9 @@ const freshAggregateMatViewMinWindow = 24 * time.Hour
// (both StartTime and EndTime nil) are treated as matview-safe — a half-bounded
// range has no measurable width and could still be a short window.
//
// Used by both /api/logs/stats (full metric payload) and /api/logs (pagination
// total count) so those two surfaces stay consistent on the same window.
// Used by /api/logs/stats (full metric payload), /api/logs (pagination total
// count), and the model/user/dimension ranking readers so all those surfaces
// stay consistent on the same window.
func (s *RDBLogStore) canUseMatViewForFreshAggregate(f SearchFilters) bool {
if !s.canUseMatView(f) {
return false
Expand Down
18 changes: 15 additions & 3 deletions framework/logstore/rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,8 +1818,12 @@ func (s *RDBLogStore) buildLatencyHistogramResult(computedBuckets map[int64]Late
}

// GetModelRankings returns models ranked by usage with trend comparison to the previous period.
// Uses the same fresh-aggregate matview gate as GetStats: short windows go to
// the raw table because mv_logs_hourly rounds the window out to full hour
Comment thread
akshaydeo marked this conversation as resolved.
// buckets, which visibly inflates rankings against the raw-path stats and
// cost-histogram totals shown on the same dashboard.
func (s *RDBLogStore) GetModelRankings(ctx context.Context, filters SearchFilters) (*ModelRankingResult, error) {
if s.db.Dialector.Name() == "postgres" && s.canUseMatView(filters) {
if s.db.Dialector.Name() == "postgres" && s.canUseMatViewForFreshAggregate(filters) {
return s.getModelRankingsFromMatView(ctx, filters)
}
selectClause := `
Expand Down Expand Up @@ -1958,8 +1962,12 @@ func (s *RDBLogStore) GetModelRankings(ctx context.Context, filters SearchFilter
}

// GetUserRankings returns users ranked by usage with trend comparison to the previous period.
// Uses the same fresh-aggregate matview gate as GetStats: short windows go to
// the raw table because mv_logs_hourly rounds the window out to full hour
// buckets, which visibly inflates rankings against the raw-path stats and
// cost-histogram totals shown on the same dashboard.
func (s *RDBLogStore) GetUserRankings(ctx context.Context, filters SearchFilters) (*UserRankingResult, error) {
if s.db.Dialector.Name() == "postgres" && s.canUseMatView(filters) {
if s.db.Dialector.Name() == "postgres" && s.canUseMatViewForFreshAggregate(filters) {
return s.getUserRankingsFromMatView(ctx, filters)
}
selectClause := `
Expand Down Expand Up @@ -2091,7 +2099,11 @@ func (s *RDBLogStore) GetDimensionRankings(ctx context.Context, filters SearchFi
return q.Model(&Log{})
}

if fanoutFrom == "" && s.db.Dialector.Name() == "postgres" && s.canUseMatView(filters) {
// Fresh-aggregate gate (not bare canUseMatView): short windows go to the
// raw table because mv_logs_hourly rounds the window out to full hour
// buckets, which visibly inflates rankings against the raw-path stats and
// cost-histogram totals shown on the same dashboard.
if fanoutFrom == "" && s.db.Dialector.Name() == "postgres" && s.canUseMatViewForFreshAggregate(filters) {
return s.getDimensionRankingsFromMatView(ctx, filters, dimension)
}

Expand Down
Loading