@@ -432,7 +432,7 @@ func costFromTotals(model string, input, output, cached int64, prices map[string
432432 return computeCost (model , input , output , cached , prices )
433433}
434434
435- // BuildUsageOverview returns the summary, hourly+daily series and a 30×96 health grid.
435+ // BuildUsageOverview returns the summary, hourly+daily series and a range-sized 15-minute health grid.
436436func (s * Store ) BuildUsageOverview (ctx context.Context , f storage.UsageFilter , prices map [string ]storage.ModelPriceSetting ) (* storage.UsageOverview , error ) {
437437 now := time .Now ().UTC ()
438438
@@ -581,8 +581,16 @@ func (s *Store) bucketSeriesDaily(ctx context.Context, f storage.UsageFilter, no
581581func (s * Store ) healthGrid (ctx context.Context , f storage.UsageFilter , now time.Time ) ([][]storage.HealthCell , error ) {
582582 healthFilter := f
583583 end := startOfDay (now ).Add (24 * time .Hour )
584- healthFilter .End = end
585- healthFilter .Start = end .Add (- 30 * 24 * time .Hour )
584+ if healthFilter .HasRange () {
585+ healthFilter .Start = startOfDay (healthFilter .Start )
586+ healthFilter .End = startOfDay (healthFilter .End .Add (- time .Nanosecond )).Add (24 * time .Hour )
587+ if healthFilter .End .Sub (healthFilter .Start ) > 30 * 24 * time .Hour {
588+ healthFilter .Start = healthFilter .End .Add (- 30 * 24 * time .Hour )
589+ }
590+ } else {
591+ healthFilter .End = end
592+ healthFilter .Start = end .Add (- 30 * 24 * time .Hour )
593+ }
586594 type row struct {
587595 Bucket string
588596 Total int64
@@ -606,8 +614,12 @@ func (s *Store) healthGrid(ctx context.Context, f storage.UsageFilter, now time.
606614 bucketMap [t .UTC ()] = storage.HealthCell {Bucket : t .UTC (), Total : r .Total , Failed : r .Failed }
607615 }
608616
609- grid := make ([][]storage.HealthCell , 30 )
610- for d := 0 ; d < 30 ; d ++ {
617+ days := int (healthFilter .End .Sub (healthFilter .Start ).Hours () / 24 )
618+ if days < 1 {
619+ days = 1
620+ }
621+ grid := make ([][]storage.HealthCell , days )
622+ for d := 0 ; d < days ; d ++ {
611623 row := make ([]storage.HealthCell , 96 )
612624 dayStart := healthFilter .Start .Add (time .Duration (d ) * 24 * time .Hour )
613625 for c := 0 ; c < 96 ; c ++ {
0 commit comments