Skip to content

Commit 4207318

Browse files
committed
warn on rollup/base query coverage mismatch
1 parent 9c94a59 commit 4207318

26 files changed

Lines changed: 3098 additions & 1828 deletions

proto/gen/rill/runtime/v1/queries.pb.go

Lines changed: 1913 additions & 1823 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/gen/rill/runtime/v1/queries.pb.validate.go

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/gen/rill/runtime/v1/runtime.swagger.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6296,6 +6296,11 @@ definitions:
62966296
items:
62976297
type: object
62986298
title: Not optional, not null
6299+
servingTable:
6300+
type: string
6301+
description: |-
6302+
Rollup table the query was routed to. Empty when the query was served from the metrics view's base table.
6303+
Matches the keys of rollup_time_ranges in MetricsViewTimeRangeResponse and MetricsViewTimeRangesResponse.
62996304
trace:
63006305
$ref: '#/definitions/v1Trace'
63016306
description: Traces of spans captured during request execution. Only populated if trace was set to true in the request.
@@ -6459,6 +6464,11 @@ definitions:
64596464
type: object
64606465
$ref: '#/definitions/v1MetricsViewComparisonRow'
64616466
title: Not optional, not null
6467+
servingTable:
6468+
type: string
6469+
description: |-
6470+
Rollup table the query was routed to. Empty when the query was served from the metrics view's base table.
6471+
Matches the keys of rollup_time_ranges in MetricsViewTimeRangeResponse and MetricsViewTimeRangesResponse.
64626472
trace:
64636473
$ref: '#/definitions/v1Trace'
64646474
description: Traces of spans captured during request execution. Only populated if trace was set to true in the request.
@@ -6801,6 +6811,13 @@ definitions:
68016811
timeRangeSummary:
68026812
$ref: '#/definitions/v1TimeRangeSummary'
68036813
title: Not optional, not null
6814+
rollupTimeRanges:
6815+
type: object
6816+
additionalProperties:
6817+
$ref: '#/definitions/v1TimeRangeSummary'
6818+
description: |-
6819+
Time range summaries for the metrics view's rollups, keyed by rollup table name.
6820+
Only populated when the metrics view has rollups.
68046821
maxQueryTimeRangeMillis:
68056822
type: string
68066823
format: int64
@@ -6816,6 +6833,13 @@ definitions:
68166833
fullTimeRange:
68176834
$ref: '#/definitions/v1TimeRangeSummary'
68186835
description: The full time range summary for the requested time dimension.
6836+
rollupTimeRanges:
6837+
type: object
6838+
additionalProperties:
6839+
$ref: '#/definitions/v1TimeRangeSummary'
6840+
description: |-
6841+
Time range summaries for the metrics view's rollups, keyed by rollup table name.
6842+
Only populated when the metrics view has rollups.
68196843
resolvedTimeRanges:
68206844
type: array
68216845
items:
@@ -6903,6 +6927,11 @@ definitions:
69036927
type: object
69046928
$ref: '#/definitions/v1TimeSeriesValue'
69056929
title: Not optional, not null
6930+
servingTable:
6931+
type: string
6932+
description: |-
6933+
Rollup table the query was routed to. Empty when the query was served from the metrics view's base table.
6934+
Matches the keys of rollup_time_ranges in MetricsViewTimeRangeResponse and MetricsViewTimeRangesResponse.
69066935
trace:
69076936
$ref: '#/definitions/v1Trace'
69086937
description: Traces of spans captured during request execution. Only populated if trace was set to true in the request.

proto/rill/runtime/v1/queries.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,9 @@ message MetricsViewAggregationResponse {
485485
StructType schema = 1;
486486
// Not optional, not null
487487
repeated google.protobuf.Struct data = 2;
488+
// Rollup table the query was routed to. Empty when the query was served from the metrics view's base table.
489+
// Matches the keys of rollup_time_ranges in MetricsViewTimeRangeResponse and MetricsViewTimeRangesResponse.
490+
string serving_table = 4;
488491
// Traces of spans captured during request execution. Only populated if trace was set to true in the request.
489492
Trace trace = 3;
490493
}
@@ -638,6 +641,9 @@ message MetricsViewComparisonRequest {
638641
message MetricsViewComparisonResponse {
639642
// Not optional, not null
640643
repeated MetricsViewComparisonRow rows = 1;
644+
// Rollup table the query was routed to. Empty when the query was served from the metrics view's base table.
645+
// Matches the keys of rollup_time_ranges in MetricsViewTimeRangeResponse and MetricsViewTimeRangesResponse.
646+
string serving_table = 3;
641647
// Traces of spans captured during request execution. Only populated if trace was set to true in the request.
642648
Trace trace = 2;
643649
}
@@ -747,6 +753,9 @@ message MetricsViewTimeSeriesResponse {
747753
repeated MetricsViewColumn meta = 1;
748754
// Not optional, not null
749755
repeated TimeSeriesValue data = 2;
756+
// Rollup table the query was routed to. Empty when the query was served from the metrics view's base table.
757+
// Matches the keys of rollup_time_ranges in MetricsViewTimeRangeResponse and MetricsViewTimeRangesResponse.
758+
string serving_table = 4;
750759
// Traces of spans captured during request execution. Only populated if trace was set to true in the request.
751760
Trace trace = 3;
752761
}
@@ -861,6 +870,9 @@ message MetricsViewTimeRangeRequest {
861870
message MetricsViewTimeRangeResponse {
862871
// Not optional, not null
863872
TimeRangeSummary time_range_summary = 1;
873+
// Time range summaries for the metrics view's rollups, keyed by rollup table name.
874+
// Only populated when the metrics view has rollups.
875+
map<string, TimeRangeSummary> rollup_time_ranges = 4;
864876
// The metrics view's max_query_time_range property resolved into milliseconds against the current time.
865877
// Zero if the metrics view does not configure max_query_time_range.
866878
int64 max_query_time_range_millis = 3;
@@ -931,6 +943,9 @@ message MetricsViewTimeRangesRequest {
931943
message MetricsViewTimeRangesResponse {
932944
// The full time range summary for the requested time dimension.
933945
TimeRangeSummary full_time_range = 1;
946+
// Time range summaries for the metrics view's rollups, keyed by rollup table name.
947+
// Only populated when the metrics view has rollups.
948+
map<string, TimeRangeSummary> rollup_time_ranges = 6;
934949
// The resolved time ranges for the requested rilltime expressions.
935950
repeated ResolvedTimeRange resolved_time_ranges = 3;
936951
// The same values as resolved_time_ranges for backwards compatibility.

runtime/queries/metricsview_aggregation.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ func (q *MetricsViewAggregation) Resolve(ctx context.Context, rt *runtime.Runtim
127127
}
128128

129129
q.Result = &runtimev1.MetricsViewAggregationResponse{
130-
Schema: res.Schema,
131-
Data: data,
130+
Schema: res.Schema,
131+
Data: data,
132+
ServingTable: rollupServingTable(e, mv.ValidSpec),
132133
}
133134
return nil
134135
}
@@ -287,6 +288,15 @@ func ResolveTimestampResult(ctx context.Context, rt *runtime.Runtime, instanceID
287288
return tsRes, nil
288289
}
289290

291+
// rollupServingTable returns the rollup table the executor's last query was routed to.
292+
// Returns an empty string when the query was served from the metrics view's base table.
293+
func rollupServingTable(e *executor.Executor, mv *runtimev1.MetricsViewSpec) string {
294+
if t := e.LatestQueryTable(); t != "" && t != mv.Table {
295+
return t
296+
}
297+
return ""
298+
}
299+
290300
func (q *MetricsViewAggregation) rewriteToMetricsViewQuery(export bool) (*metricsview.Query, error) {
291301
qry := &metricsview.Query{MetricsView: q.MetricsViewName}
292302

runtime/queries/metricsview_comparison_toplist.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ func (q *MetricsViewComparison) Resolve(ctx context.Context, rt *runtime.Runtime
172172
}
173173

174174
q.Result = &runtimev1.MetricsViewComparisonResponse{
175-
Rows: rows,
175+
Rows: rows,
176+
ServingTable: rollupServingTable(e, mv.ValidSpec),
176177
}
177178

178179
return nil

runtime/queries/metricsview_timeseries.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ func (q *MetricsViewTimeSeries) Resolve(ctx context.Context, rt *runtime.Runtime
143143
}
144144
defer res.Close()
145145

146-
return q.populateResult(res, timeDim, mv.ValidSpec, nullImpl)
146+
if err := q.populateResult(res, timeDim, mv.ValidSpec, nullImpl); err != nil {
147+
return err
148+
}
149+
q.Result.ServingTable = rollupServingTable(e, mv.ValidSpec)
150+
return nil
147151
}
148152

149153
func (q *MetricsViewTimeSeries) Export(ctx context.Context, rt *runtime.Runtime, instanceID string, w io.Writer, opts *runtime.ExportOptions) error {

runtime/server/queries_metrics.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ func (s *Server) MetricsViewTimeRange(ctx context.Context, req *runtimev1.Metric
419419
Max: valOrNullTime(ts.Max),
420420
Watermark: valOrNullTime(ts.Watermark),
421421
},
422+
RollupTimeRanges: rollupTimeRangeSummaries(ts),
422423
MaxQueryTimeRangeMillis: metricsview.ResolveMaxQueryTimeRange(maxQueryTimeRange, time.Now()).Milliseconds(),
423424
}, nil
424425
}
@@ -528,11 +529,13 @@ func (s *Server) MetricsViewTimeRanges(ctx context.Context, req *runtimev1.Metri
528529
return nil, err
529530
}
530531
if req.ExecutionTime != nil {
531-
// If override is set, we use it for every ref except `min`
532+
// If override is set, we use it for every ref except `min`.
533+
// Rollup timestamps are preserved as-is since they report actual data coverage.
532534
ts = metricsview.TimestampsResult{
533535
Min: ts.Min,
534536
Max: req.ExecutionTime.AsTime(),
535537
Watermark: req.ExecutionTime.AsTime(),
538+
Rollups: ts.Rollups,
536539
}
537540
now = req.ExecutionTime.AsTime()
538541
}
@@ -603,6 +606,7 @@ func (s *Server) MetricsViewTimeRanges(ctx context.Context, req *runtimev1.Metri
603606
Max: valOrNullTime(ts.Max),
604607
Watermark: valOrNullTime(ts.Watermark),
605608
},
609+
RollupTimeRanges: rollupTimeRangeSummaries(ts),
606610
ResolvedTimeRanges: timeRanges,
607611
TimeRanges: backwardsCompatibleRanges,
608612
MaxQueryTimeRangeMillis: metricsview.ResolveMaxQueryTimeRange(maxQueryTimeRange, now).Milliseconds(),
@@ -810,3 +814,19 @@ func valOrNullTime(v time.Time) *timestamppb.Timestamp {
810814
}
811815
return timestamppb.New(v)
812816
}
817+
818+
// rollupTimeRangeSummaries converts the rollup timestamps in a TimestampsResult
819+
// to time range summaries keyed by rollup table name. Returns nil when the metrics view has no rollups.
820+
func rollupTimeRangeSummaries(ts metricsview.TimestampsResult) map[string]*runtimev1.TimeRangeSummary {
821+
if len(ts.Rollups) == 0 {
822+
return nil
823+
}
824+
res := make(map[string]*runtimev1.TimeRangeSummary, len(ts.Rollups))
825+
for table, rts := range ts.Rollups {
826+
res[table] = &runtimev1.TimeRangeSummary{
827+
Min: valOrNullTime(rts.Min),
828+
Max: valOrNullTime(rts.Max),
829+
}
830+
}
831+
return res
832+
}

0 commit comments

Comments
 (0)