-
Notifications
You must be signed in to change notification settings - Fork 2
fix: Fix query resource count endpoint double counting and bucket overflow #22
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
Increases the default aggregation bucket size from 10 to 100 to reduce the likelihood of bucket overflow in count queries. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Andres Tobon <[email protected]>
Fixes double counting bug in resource count endpoint by adding proper PrivateOnly filtering. Previously, the aggregation query included both public and private resources when it should only include private ones. The template now uses must_not clause to exclude public resources when PrivateOnly is true, handling cases where the public field is omitted in private documents. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Andres Tobon <[email protected]>
Removes the unused context parameter from the convertCountResponse method and updates its call site. The context was not being used within the function. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Andres Tobon <[email protected]>
…service into andrest50/fix-count
WalkthroughRemoved context parameter from convertCountResponse and updated its call site in QueryResourcesCount; added PrivateOnly filter to the OpenSearch query template; increased DefaultBucketSize from 10 to 100; bumped chart version. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Searcher as OpenSearchSearcher
participant OS as OpenSearch
note over Searcher: QueryResourcesCount flow
Client->>Searcher: QueryResourcesCount(query)
Searcher->>OS: count + aggregations request
OS-->>Searcher: response, aggResponse
note over Searcher: convertCountResponse(response, aggResponse)<br/>(ctx removed)
Searcher-->>Client: CountResult
sequenceDiagram
autonumber
participant Caller
participant Tmpl as QueryTemplateBuilder
note over Tmpl: Build bool.must filters
Caller->>Tmpl: Build(query)
alt PublicOnly
Tmpl->>Tmpl: Add clause `public == true`
else PrivateOnly
Tmpl->>Tmpl: Add `must_not` clause `public == true`
end
Tmpl-->>Caller: Compiled query
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
Comment |
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.
Pull Request Overview
This PR fixes a double counting bug in the resource count endpoint and optimizes bucket size configuration. The double counting occurred because the aggregation query was missing the PrivateOnly filter, causing it to return all resources which then got misclassified as private resources.
- Fixed double counting by adding PrivateOnly filter handling to OpenSearch template
- Increased default bucket size from 10 to 100 to reduce overflow frequency
- Removed unused context parameter from convertCountResponse method
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/constants/query.go | Increased DefaultBucketSize from 10 to 100 |
| internal/infrastructure/opensearch/template.go | Added PrivateOnly filter with must_not clause for public field |
| internal/infrastructure/opensearch/searcher.go | Removed unused ctx parameter from convertCountResponse method |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Updates Helm chart version to 0.4.6 to include the latest fixes for the query resource count endpoint. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Andres Tobon <[email protected]>
Summary
Key Changes
1. PrivateOnly Filter Fix
PrivateOnlyhandling to OpenSearch template usingmust_notclausepublicfield is omitted (real production scenario)2. Bucket Size Optimization
DefaultBucketSizefrom 10 to 100has_more=truescenarios3. Test Coverage
SumOtherDocCount > 0handling4. Code Cleanup
ctxparameter fromconvertCountResponsemethodRoot Cause Analysis
The double counting occurred because:
"public": truePrivateOnlyfilter, so it returned ALL resourcesTest Plan
🤖 Generated with Claude Code