Skip to content

fix(web): bound HistogramCache range to the inspection query time range - #1037

Merged
kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-uoskqrulunty
Sep 25, 2026
Merged

kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-uoskqrulunty

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 25, 2026

Copy link
Copy Markdown
Member

Problem

Opening some inspection files fails. HistogramCache tried to allocate typed arrays with ~500M elements (windowCount = 502696905 was observed).

Cause

HistogramCache used two different sources for its size:

  • Time range: the min and max timestamps of all logs.
  • Bucket width (minBucketTime): the inspection query range divided into 10000 buckets.

A single log far outside the query range makes the bucket count grow without bound. For example, with a 1 hour query the bucket width is 500ms, and 502,696,904 buckets x 500ms is about 8 years. Cloud Asset Inventory snapshot logs can be stamped with the asset's last change time (TemporalAsset.Window.StartTime), which can be years before the query start.

Fix

  • HistogramCache now takes the histogram range as required arguments (rangeBeginTimeMs, rangeEndTimeMs) instead of deriving it from logs. The bucket containing the range end is included.
  • Logs outside the range are not counted. This includes logs within one bucket before the range start, which were previously counted in the prefix slot.
  • timeline-frame passes the inspection query range (minQueryLogTimeMS / maxQueryLogTimeMS) to both the all-logs and filtered-logs caches. The rest of the timeline (horizontal scroll, chart draw range, range selection) already uses this range.
  • Removed the public logMinTimeMS / logMaxTimeMS fields.

Tests

  • Added tests for logs outside the range (years before, one bucket before, and after the range) and for a log exactly at the range end.
  • make test-web (1417 passed), make lint-web, make build-storybook pass.
@kyasbal kyasbal added the type:bug Something isn't working as expected label Sep 25, 2026
@kyasbal
kyasbal requested a review from RyuSA as a code owner September 25, 2026 07:54
@kyasbal kyasbal added the area:frontend Web frontend application and UI components label Sep 25, 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 refactors HistogramCache to accept explicit range boundaries (rangeBeginTimeMs and rangeEndTimeMs) instead of deriving them from the logs, preventing unbounded bucket count inflation from outlier logs. Call sites in TimelineFrameComponent and associated unit tests have been updated, and new tests were added to verify range boundaries. Feedback is provided regarding a potential issue where out-of-bounds writes and NaN propagation can occur if bucketCount exceeds windowCount, with a suggestion to dynamically allocate Float32Array buffers of size bucketCount.

@kyasbal
kyasbal added this pull request to the merge queue Sep 25, 2026
Merged via the queue into GoogleCloudPlatform:main with commit d402902 Sep 25, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-uoskqrulunty branch September 25, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Web frontend application and UI components type:bug Something isn't working as expected

1 participant