Skip to content

feat: add timeline time range filtering across the backend pipeline and frontend UI - #1032

Merged
kyasbal merged 9 commits into
mainfrom
epic/time-range-filter
Sep 18, 2026
Merged

kyasbal merged 9 commits into
mainfrom
epic/time-range-filter

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 18, 2026

Copy link
Copy Markdown
Member

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-filter branch; 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

  • FilterTimelineRequest and FilterTimelineSyncRequest accept filter_start_time and filter_end_time. When unspecified, the filter covers the full dataset duration, so resources created outside the query interval are still included.
  • cel.LogData and cel.EventInfo carry log timestamps, and both Events and Revisions inside each TimelineData are sorted chronologically during index construction.
  • The new TimeRangeFilter stage evaluates resource activity with binary search over the sorted events and revisions, so each timeline costs O(log E + log R).
  • Time range filtering takes precedence over descendant expansion. A child resource with no event or revision inside the window is dropped, while its ancestors are kept through IncludeAncestorsFilter so the tree stays intact. Matched LogIDs are restricted to logs inside the window.

Frontend interaction

  • Drag horizontally on the timeline ruler to select a range. A dashed preview band follows the pointer, a right-to-left drag is normalized, a drag shorter than 3px counts as a click, and Escape cancels.
  • An applied range can be adjusted afterwards by dragging its left or right edge handle, which anchors the opposite edge. While an edge is dragged the committed overlay is dimmed rather than unmounted, so the handles keep the resize cursor.
  • A clear button on top of the active range removes the filter.
  • The range is drawn as a persistent overlay on both the ruler and the chart body.

Toolbar

  • The time range filter is a shared filter parameter across Standard Mode and Advanced (CEL) Mode. It shows up as a chip in the toolbar filter list.
  • The chip label is rendered in two lines, start on the first and ~ <end> on the second, so nothing is truncated. The date is repeated on the second line only when the range crosses a day boundary.
  • The chip tooltip shows full ISO 8601 timestamps and the duration, for example 2026-09-17T14:00:00.000+09:00 ~ 2026-09-17T14:30:00.000+09:00 (30m00s).
  • Clicking the chip opens TimeRangeFilterBuilderComponent for manual start/end editing, and the chip can be deleted directly.

Stacked PRs merged into this epic

PR Summary
#1020 Backend API and search index timestamp sorting
#1022 TimeRangeFilter stage and pipeline integration
#1025 Frontend filter state and backend client wiring
#1026 Toolbar time filter chip and manual timestamp editor popover
#1027 Interactive t-key hold selection and timeline/ruler overlays
#1029 Replace t-key selection with ruler drag selection
#1030 Active range edge resize handles and clear button
#1031 Two-line time range chip label and detailed tooltip

Note

#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 no t-key code remains in this branch.

…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
@kyasbal kyasbal added type:feature New feature or request area:backend-core Core backend frameworks, DAG task runner, and server API area:frontend Web frontend application and UI components labels Sep 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +87 to +96
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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).

Suggested change
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
  1. When using binary search on a collection, ensure that duplicates are handled correctly to prevent the search from returning arbitrary elements.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +106 to +121
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
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
  1. When using binary search on a collection, ensure that duplicates are handled correctly to prevent the search from returning arbitrary elements.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kyasbal
kyasbal added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit 88c9596 Sep 18, 2026
21 checks passed
@kyasbal
kyasbal deleted the epic/time-range-filter branch September 18, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-core Core backend frameworks, DAG task runner, and server API area:frontend Web frontend application and UI components type:feature New feature or request

1 participant