-
Notifications
You must be signed in to change notification settings - Fork 715
fix: histogram total count was getting set as 0 in case of streaming aggs #8721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR fixes a bug in the streaming aggregation logic where histogram total counts were incorrectly being reset to 0. The issue occurred when processing streaming aggregations across multiple partitions: the first partition would return valid results with a proper total count, but subsequent partitions with empty hits would overwrite this total to 0.The fix adds a null/undefined check (response.content?.results?.total) to the streaming aggregation condition in useSearchStream.ts. This ensures that the total count is only set when there's actually a valid total value in the response, preserving the accumulated total from previous partitions when subsequent ones are empty.
This change integrates with the existing streaming aggregation system that processes search results in partitions. The streaming aggregation feature allows for real-time processing of large datasets by breaking them into manageable chunks. Without this fix, the UI would show incorrect histogram totals (0) when later partitions had no results, even though earlier partitions contained valid data.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| web/src/composables/useLogs/useSearchStream.ts | 4/5 | Added null check to prevent histogram total from being overwritten to 0 in streaming aggregations |
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it addresses a specific edge case without affecting core functionality
- Score reflects a targeted bug fix that adds defensive programming without changing existing behavior for valid responses
- No files require special attention as the change is simple and well-isolated
Sequence Diagram
sequenceDiagram
participant User
participant UI as "UI Component"
participant SearchStream as "useSearchStream"
participant WebSocket as "WebSocket/Stream"
participant Backend as "Backend Service"
User->>UI: "Initiate search with streaming aggs"
UI->>SearchStream: "getDataThroughStream(false)"
SearchStream->>SearchStream: "getQueryReq(false)"
SearchStream->>SearchStream: "buildWebSocketPayload()"
SearchStream->>SearchStream: "initializeSearchConnection()"
SearchStream->>WebSocket: "Send search request"
WebSocket->>Backend: "Execute search query"
Backend->>WebSocket: "First partition response (with hits)"
WebSocket->>SearchStream: "handleSearchResponse() - metadata"
SearchStream->>SearchStream: "handleStreamingMetadata() - partition 1"
Note over SearchStream: Set searchObj.data.queryResults with first partition data
Backend->>WebSocket: "Second partition response (empty hits)"
WebSocket->>SearchStream: "handleSearchResponse() - metadata"
SearchStream->>SearchStream: "handleStreamingMetadata() - partition 2"
Note over SearchStream: Check streaming_aggs and !hits.length
SearchStream->>SearchStream: "shouldAppendStreamingResults = false"
Note over SearchStream: Preserve total from first partition instead of resetting to 0
SearchStream->>SearchStream: "refreshPagination()"
SearchStream->>SearchStream: "getAggsTotal()"
Note over SearchStream: Calculate total from accumulated aggs data
SearchStream->>UI: "Update histogram with correct total count"
UI->>User: "Display histogram with proper total count"
1 file reviewed, no comments
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
cd96b3c to
df832f7
Compare
df832f7 to
1055cd5
Compare
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 341 | 0 | 19 | 5 | 93% | 4m 38s |
1055cd5 to
2992b7b
Compare
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 366 | 344 | 0 | 19 | 3 | 94% | 4m 39s |
2992b7b to
5db8075
Compare
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 366 | 342 | 0 | 19 | 5 | 93% | 4m 40s |
User description
The histogram total count was getting set to 0 in case of streaming aggs when the first partition returns results and next all partitions return empty hits. In this case it should consider the count of the first partition.
PR Type
Bug fix, Enhancement
Description
Fix histogram total with streaming aggs
Gate total assignment on presence of total
Improve streaming partition/chunk handling
Refactor for readability and safety
Diagram Walkthrough
File Walkthrough
useSearchStream.ts
Streaming aggregation handling and total fixweb/src/composables/useLogs/useSearchStream.ts