diff --git a/runtime/queries/metricsview_comparison_toplist.go b/runtime/queries/metricsview_comparison_toplist.go index f823434ade1..10da6b291b5 100644 --- a/runtime/queries/metricsview_comparison_toplist.go +++ b/runtime/queries/metricsview_comparison_toplist.go @@ -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) } @@ -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) +}