Skip to content

Commit

Permalink
Fix comparison toplist time range nil checks (#3044)
Browse files Browse the repository at this point in the history
  • Loading branch information
begelundmuller authored Sep 8, 2023
1 parent f848b77 commit 140dd8b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions runtime/queries/metricsview_comparison_toplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func (q *MetricsViewComparisonToplist) Resolve(ctx context.Context, rt *runtime.
return fmt.Errorf("not available for dialect '%s'", olap.Dialect())
}

if q.MetricsView.TimeDimension == "" && (q.BaseTimeRange != nil || q.ComparisonTimeRange != nil) {
if q.MetricsView.TimeDimension == "" && (!isTimeRangeNil(q.BaseTimeRange) || !isTimeRangeNil(q.ComparisonTimeRange)) {
return fmt.Errorf("metrics view '%s' does not have a time dimension", q.MetricsViewName)
}

if q.ComparisonTimeRange != nil {
if !isTimeRangeNil(q.ComparisonTimeRange) {
return q.executeComparisonToplist(ctx, olap, q.MetricsView, priority, q.ResolvedMVSecurity)
}

Expand Down Expand Up @@ -561,3 +561,7 @@ func validateSort(sorts []*runtimev1.MetricsViewComparisonSort) error {
}
return nil
}

func isTimeRangeNil(tr *runtimev1.TimeRange) bool {
return tr == nil || (tr.Start == nil && tr.End == nil)
}

0 comments on commit 140dd8b

Please sign in to comment.