Repository navigation
feat: add timeline time range filtering across the backend pipeline and frontend UI - #1032
Conversation
…vents by timestamp
…kbench pipeline - Implement TimeRangeFilter stage in pkg/server/workbench/filter_time_range.go using O(log E + log R) binary search helpers. - Place TimeRangeFilter at Stage 3 in the 7-stage workbench pipeline (immediately after IncludeDescendantsFilter) so hierarchy expansion happens before time range narrowing and ancestor restoration happens after. - Restrict LogCELFilter log candidate iteration to [StartTimeNs, EndTimeNs] when HasTimeRange is enabled. - Wire FilterStartTime and FilterEndTime from FilterTimeline and FilterTimelineSync gRPC handlers. - Add unit tests for TimeRangeFilter and end-to-end pipeline hierarchy/time-range precedence. - Replace slices.SortStableFunc with slices.SortFunc in indexTimelinesParallel per PR #1020 review feedback. Part of #1018
…e BackendFilter - Define and export TimeRangeFilter interface in ViewStateService and add timeRangeFilter signal shared across standard and advanced modes. - Add BigIntTimeUtil.NsToProtoTimestamp helper to convert nanosecond bigints to protobuf Timestamp messages. - Update FilterTimelineParams and WorkbenchClientService.filterTimeline to convert and pass filterStartTime and filterEndTime to backend RPCs. - Extend BackendFilter and BackendFilterParams with filterStartTime and filterEndTime signals and include them in cache keys. - Synchronize ViewStateService.timeRangeFilter changes to BackendFilter in TimelineToolbarSmartComponent. - Add unit tests across BigIntTimeUtil, WorkbenchClientService, BackendFilter, and TimelineToolbarSmartComponent. Part of #1018
… chip integration Implements the time range filter chip/button in both standard and advanced toolbar modes, along with the manual ISO 8601 timestamp editor popover (TimeRangeFilterBuilderComponent) and nanosecond ISO parsing/formatting utilities. Part of #1018 TAG=agy
… and timeline overlays Part of #1018 - Add TimeRangeMs and TimeRangeOverlayStyle interfaces in interaction-model.ts - Render active (solid) and preview (dashed) time range overlays in TimelineRulerComponent and TimelineFrameComponent - Implement interactive t-key hold time range selection mode with mousewheel width adjustment and click/keyup confirmation in TimelineFrameComponent - Wire timeRangeFilter input and timeRangeSelected output in TimelineSmartComponent to ViewStateService - Add unit tests for TimelineRulerComponent, TimelineFrameComponent, and TimelineSmartComponent TAG=agy
…e time range on the ruler (#1030)
…and add a detailed tooltip (#1031)
There was a problem hiding this comment.
Code Review
This pull request introduces a time range filtering feature to the workbench timeline and log search pipeline, allowing users to filter timelines and logs within a specified time range. It updates the protobuf definitions, Go backend search index and pipeline filters, and the Angular frontend with a new time range filter builder popover and ruler drag-to-select interactions. The review feedback highlights a correctness issue in the binary search implementation (HasActivityInRange and ForEachLogIDInRange) where duplicate timestamps can cause arbitrary matching indices to be returned, potentially skipping matching events or revisions, and suggests using a custom comparison function to guarantee finding the first matching element.
| evtIdx, _ := slices.BinarySearchFunc(t.Events, startTimeNs, func(e EventInfo, target int64) int { | ||
| return cmp.Compare(e.Timestamp, target) | ||
| }) | ||
| if evtIdx < len(t.Events) && t.Events[evtIdx].Timestamp <= endTimeNs { | ||
| return true | ||
| } | ||
| revIdx, _ := slices.BinarySearchFunc(t.Revisions, startTimeNs, func(r RevisionInfo, target int64) int { | ||
| return cmp.Compare(r.ChangedTime, target) | ||
| }) | ||
| return revIdx < len(t.Revisions) && t.Revisions[revIdx].ChangedTime <= endTimeNs |
There was a problem hiding this comment.
Using slices.BinarySearchFunc with a standard comparison function can return any matching index when there are duplicate timestamps. In HasActivityInRange, we want to find the first element that is >= startTimeNs to correctly check if any activity falls within the range. If we use a custom comparison function that returns -1 when the element is < target and 1 when it is >= target, the binary search is guaranteed to return the index of the first element >= target (the insertion point).
| evtIdx, _ := slices.BinarySearchFunc(t.Events, startTimeNs, func(e EventInfo, target int64) int { | |
| return cmp.Compare(e.Timestamp, target) | |
| }) | |
| if evtIdx < len(t.Events) && t.Events[evtIdx].Timestamp <= endTimeNs { | |
| return true | |
| } | |
| revIdx, _ := slices.BinarySearchFunc(t.Revisions, startTimeNs, func(r RevisionInfo, target int64) int { | |
| return cmp.Compare(r.ChangedTime, target) | |
| }) | |
| return revIdx < len(t.Revisions) && t.Revisions[revIdx].ChangedTime <= endTimeNs | |
| evtIdx, _ := slices.BinarySearchFunc(t.Events, startTimeNs, func(e EventInfo, target int64) int { | |
| if e.Timestamp < target { | |
| return -1 | |
| } | |
| return 1 | |
| }) | |
| if evtIdx < len(t.Events) && t.Events[evtIdx].Timestamp <= endTimeNs { | |
| return true | |
| } | |
| revIdx, _ := slices.BinarySearchFunc(t.Revisions, startTimeNs, func(r RevisionInfo, target int64) int { | |
| if r.ChangedTime < target { | |
| return -1 | |
| } | |
| return 1 | |
| }) | |
| return revIdx < len(t.Revisions) && t.Revisions[revIdx].ChangedTime <= endTimeNs |
References
- When using binary search on a collection, ensure that duplicates are handled correctly to prevent the search from returning arbitrary elements.
There was a problem hiding this comment.
Same as the reply on ForEachLogIDInRange: slices.BinarySearchFunc is a lower-bound search and returns the earliest index whose element is >= target, so the duplicate concern does not apply.
For HasActivityInRange specifically, which duplicate is returned would not even matter. All duplicates share the same timestamp, so t.Events[evtIdx].Timestamp <= endTimeNs evaluates identically for any of them. The only property this function needs is that the returned index is the first element >= startTimeNs, which the current code already guarantees.
Keeping cmp.Compare here, since the proposed comparator never returns 0 and therefore breaks the documented contract of BinarySearchFunc without changing behavior.
| evtIdx, _ := slices.BinarySearchFunc(t.Events, startTimeNs, func(e EventInfo, target int64) int { | ||
| return cmp.Compare(e.Timestamp, target) | ||
| }) | ||
| for i := evtIdx; i < len(t.Events) && t.Events[i].Timestamp <= endTimeNs; i++ { | ||
| if !cb(t.Events[i].LogID) { | ||
| return | ||
| } | ||
| } | ||
| revIdx, _ := slices.BinarySearchFunc(t.Revisions, startTimeNs, func(r RevisionInfo, target int64) int { | ||
| return cmp.Compare(r.ChangedTime, target) | ||
| }) | ||
| for i := revIdx; i < len(t.Revisions) && t.Revisions[i].ChangedTime <= endTimeNs; i++ { | ||
| if !cb(t.Revisions[i].LogID) { | ||
| return | ||
| } | ||
| } |
There was a problem hiding this comment.
Using slices.BinarySearchFunc with a standard comparison function can return any matching index when there are duplicate timestamps. In ForEachLogIDInRange, if the binary search returns a non-first match, the loop will start after the first match and completely skip any earlier matching events/revisions that also fall within the range. This is a correctness bug that causes some logs to be missed. We can fix this by using a custom comparison function that returns -1 when the element is < target and 1 when it is >= target, which guarantees that the binary search returns the index of the first element >= target.
evtIdx, _ := slices.BinarySearchFunc(t.Events, startTimeNs, func(e EventInfo, target int64) int {
if e.Timestamp < target {
return -1
}
return 1
})
for i := evtIdx; i < len(t.Events) && t.Events[i].Timestamp <= endTimeNs; i++ {
if !cb(t.Events[i].LogID) {
return
}
}
revIdx, _ := slices.BinarySearchFunc(t.Revisions, startTimeNs, func(r RevisionInfo, target int64) int {
if r.ChangedTime < target {
return -1
}
return 1
})
for i := revIdx; i < len(t.Revisions) && t.Revisions[i].ChangedTime <= endTimeNs; i++ {
if !cb(t.Revisions[i].LogID) {
return
}
}References
- When using binary search on a collection, ensure that duplicates are handled correctly to prevent the search from returning arbitrary elements.
There was a problem hiding this comment.
I do not think this is a real bug. The premise that slices.BinarySearchFunc "can return any matching index when there are duplicate timestamps" does not hold.
slices.BinarySearch is documented as returning "the earliest position where target is found, or the position where target would appear in the sort order", and BinarySearchFunc shares that implementation. It is a lower-bound search: it maintains the invariant cmp(x[i-1], target) < 0 and cmp(x[j], target) >= 0, and converges on the smallest index whose element is >= target. With duplicates it therefore returns the first one deterministically, which is exactly what this loop needs.
This is also covered by an existing test. TestTimelineData_ForEachLogIDInRange has a range matches single point with duplicates across events and revisions case over events {LogID: 2, Timestamp: 200} and {LogID: 3, Timestamp: 200} querying [200, 200], and it asserts []uint32{2, 3, 5}. If the search could land on the second duplicate, log 2 would be skipped and that test would fail.
The proposed comparator returns the same index, but it never returns 0, so the boolean result of BinarySearchFunc would always be false and the function would no longer satisfy the documented comparator contract. Since it produces identical behavior here at the cost of readability, I am keeping cmp.Compare.
Closes #1018
Adds end-to-end time range filtering to the timeline, spanning the Go workbench pipeline and the Angular timeline view and toolbar. This is the integration PR for the
epic/time-range-filterbranch; all of its work already landed on the epic branch through the eight stacked PRs listed at the bottom.Motivation
KHI filters resources by kind, namespace, name regex, or CEL across the entire dataset duration. When investigating an incident in a large cluster, users usually find one critical log timestamp first and then want to see only the resources and logs that actually changed around it. There was no way to narrow the view by time.
What this adds
Backend pipeline
FilterTimelineRequestandFilterTimelineSyncRequestacceptfilter_start_timeandfilter_end_time. When unspecified, the filter covers the full dataset duration, so resources created outside the query interval are still included.cel.LogDataandcel.EventInfocarry log timestamps, and bothEventsandRevisionsinside eachTimelineDataare sorted chronologically during index construction.TimeRangeFilterstage evaluates resource activity with binary search over the sorted events and revisions, so each timeline costs O(log E + log R).IncludeAncestorsFilterso the tree stays intact. MatchedLogIDsare restricted to logs inside the window.Frontend interaction
Escapecancels.Toolbar
~ <end>on the second, so nothing is truncated. The date is repeated on the second line only when the range crosses a day boundary.2026-09-17T14:00:00.000+09:00 ~ 2026-09-17T14:30:00.000+09:00 (30m00s).TimeRangeFilterBuilderComponentfor manual start/end editing, and the chip can be deleted directly.Stacked PRs merged into this epic
TimeRangeFilterstage and pipeline integrationt-key hold selection and timeline/ruler overlayst-key selection with ruler drag selectionNote
#1027 introduced a
t-key hold selection mode that turned out to be unintuitive in practice. #1029 removed it completely and replaced it with ruler drag selection, so not-key code remains in this branch.