Skip to content

Conversation

@andrest50
Copy link
Contributor

@andrest50 andrest50 commented Nov 20, 2025

Summary

  • Implemented a new tags_all query parameter that works alongside the existing tags parameter to support both OR and AND tag filtering logic
  • tags: Filters with OR logic (matches resources with ANY of the tags)
  • tags_all: Filters with AND logic (matches resources with ALL of the tags)
  • Both parameters can be used together in a single query

Changes

  • Updated API design to include tags_all parameter for both /query/resources and /query/resources/count endpoints
  • Modified OpenSearch template to handle tags_all in must clause (AND logic) and tags in should clause (OR logic)
  • Updated mock implementation with two-pass filtering to support both parameters
  • Added TagsAll field to SearchCriteria domain model
  • Updated all converter functions to map tags_all from payload
  • Added comprehensive test coverage for both parameters and their combination
  • Regenerated Goa API code

Example Usage

  • OR logic: ?tags=active&tags=public (matches resources with active OR public)
  • AND logic: ?tags_all=governance&tags_all=security (matches resources with governance AND security)
  • Combined: ?tags=active&tags_all=governance&tags_all=security (matches resources with active AND (governance AND security))

Test Plan

  • Unit tests pass for OpenSearch query generation
  • Unit tests pass for mock implementation
  • Test cases cover OR logic only, AND logic only, and combined OR+AND
  • All existing tests still pass

Ticket

LFXV2-775

🤖 Generated with Claude Code

Implemented a new tags_all query parameter that works alongside the
existing tags parameter to support both OR and AND tag filtering logic:

- tags: Filters with OR logic (matches resources with ANY of the tags)
- tags_all: Filters with AND logic (matches resources with ALL of the tags)
- Both parameters can be used together in a single query

Changes:
- Updated API design to include tags_all parameter
- Modified OpenSearch template to handle tags_all in must clause
- Updated mock implementation with two-pass filtering
- Added TagsAll field to SearchCriteria domain model
- Updated all converter functions to map tags_all from payload
- Added comprehensive test coverage for both parameters
- Regenerated Goa API code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Andres Tobon <[email protected]>
@andrest50 andrest50 requested a review from a team as a code owner November 20, 2025 18:49
Copilot AI review requested due to automatic review settings November 20, 2025 18:49
@coderabbitai
Copy link

coderabbitai bot commented Nov 20, 2025

Walkthrough

Adds AND-logic tag filtering by introducing a new TagsAll field propagated from API payloads into search criteria, updating OpenSearch template and mock searcher to apply TagsAll (AND) alongside existing Tags (OR), expanding tests, and bumping the Helm chart version.

Changes

Cohort / File(s) Summary
API & Design Specification
design/query-svc.go
Adds tags_all payload field and HTTP query parameter for query-resources and query-resources-count; adjusts tags descriptions and removes per-endpoint BadRequest declarations.
Domain Model
internal/domain/model/search_criteria.go
Adds exported TagsAll []string to SearchCriteria and clarifies Tags uses OR logic.
Payload Conversion
cmd/service/converters.go
Propagates TagsAll from request payload into criteria in payloadToCriteria, payloadToCountPublicCriteria, and payloadToCountAggregationCriteria.
Mock Search Implementation
internal/infrastructure/mock/resource_searcher.go
Applies OR-based criteria.Tags filter then, if present, an AND-based criteria.TagsAll filter in QueryResources and QueryResourcesCount.
Mock Search Tests
internal/infrastructure/mock/resource_searcher_test.go
Adds tests for OR (Tags), AND (TagsAll), and combined scenarios for query and count methods.
OpenSearch Template
internal/infrastructure/opensearch/template.go
Extends query template to conditionally include a must-clause iterating over .TagsAll, adding term filters per tag.
OpenSearch Query Tests
internal/infrastructure/opensearch/searcher_test.go
Renames existing tags test to indicate OR semantics and adds tests for tags_all (AND) and combined tags + tags_all rendering.
Chart Version
charts/lfx-v2-query-service/Chart.yaml
Bumps Helm chart version from 0.4.8 to 0.4.9.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant Converter
    participant Searcher
    participant Backend

    Client->>API: GET /query/resources?tags_all=active,security
    API->>Converter: payloadToCriteria(payload)
    Converter->>Converter: criteria.TagsAll = payload.TagsAll
    API->>Searcher: QueryResources(criteria)
    Searcher->>Searcher: Apply OR filter (criteria.Tags)
    alt TagsAll present
        Searcher->>Searcher: Apply AND filter (criteria.TagsAll)
    end
    Searcher->>Backend: Execute query (rendered with should + must clauses)
    Backend-->>Searcher: Results
    Searcher-->>API: Filtered resources
    API-->>Client: Response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to OpenSearch template clause composition for correct boolean semantics.
  • Verify mock searcher and template produce consistent behavior for combined Tags (OR) + TagsAll (AND).
  • Check converter coverage for all payload-to-criteria conversion paths and tests for edge cases (empty lists, overlaps).

Possibly related PRs

  • #21 — Chart version bump: modifies the same Helm Chart.yaml version field; potentially overlaps release/versioning changes.
  • #22 — OpenSearch template changes: adds conditional query clauses in the template (e.g., PrivateOnly), touches similar template logic as this PR.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for a tags_all parameter with AND logic for tag filtering.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing the implementation of tags_all parameter, API changes, OpenSearch modifications, mock implementation updates, and test coverage.
Linked Issues check ✅ Passed All coding requirements from LFXV2-775 are met: AND operator support for multiple tags is implemented, existing OR behavior is preserved, and both parameters coexist in the API and implementations.
Out of Scope Changes check ✅ Passed All changes are in scope: API design updates, OpenSearch template modifications, mock implementation changes, domain model extensions, converter updates, test additions, and chart version bump are all directly related to implementing tags_all AND logic support.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch andrest50/tags-all

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5f743b5 and 5141b4f.

⛔ Files ignored due to path filters (10)
  • gen/http/openapi.json is excluded by !**/gen/**
  • gen/http/openapi.yaml is excluded by !**/gen/**
  • gen/http/openapi3.json is excluded by !**/gen/**
  • gen/http/openapi3.yaml is excluded by !**/gen/**
  • gen/http/query_svc/client/encode_decode.go is excluded by !**/gen/**
  • gen/http/query_svc/client/types.go is excluded by !**/gen/**
  • gen/http/query_svc/server/encode_decode.go is excluded by !**/gen/**
  • gen/http/query_svc/server/types.go is excluded by !**/gen/**
  • gen/query_svc/client.go is excluded by !**/gen/**
  • gen/query_svc/service.go is excluded by !**/gen/**
📒 Files selected for processing (1)
  • design/query-svc.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • design/query-svc.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: MegaLinter

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a 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 adds support for a new tags_all query parameter to enable AND logic filtering alongside the existing tags parameter (OR logic). The implementation spans API design, domain model, OpenSearch query generation, mock implementation, and comprehensive test coverage. Changes include updating the Goa design file, regenerating API code, modifying the OpenSearch query template to use the must clause for AND logic, implementing two-pass filtering in the mock searcher, and adding test cases for OR-only, AND-only, and combined scenarios.

  • Added TagsAll field to SearchCriteria domain model for AND logic filtering
  • Updated OpenSearch query template to include tags_all in must clause
  • Modified mock implementation with separate filtering passes for OR and AND tag logic
  • Regenerated Goa API code with new tags_all parameter support across all layers

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
design/query-svc.go Added tags_all attribute definition with AND logic semantics and examples
internal/domain/model/search_criteria.go Added TagsAll field to SearchCriteria struct with documentation
internal/infrastructure/opensearch/template.go Added tags_all terms to must clause for AND logic in OpenSearch query
internal/infrastructure/mock/resource_searcher.go Implemented two-pass filtering for tags (OR) and tags_all (AND) logic
internal/infrastructure/opensearch/searcher_test.go Added test cases for tags_all (AND), tags (OR), and combined scenarios
internal/infrastructure/mock/resource_searcher_test.go Added comprehensive test coverage for new filtering logic
cmd/service/converters.go Updated converter functions to map tags_all from payload to criteria
gen/query_svc/service.go Regenerated payload structures with TagsAll field
gen/http/query_svc/server/types.go Regenerated payload constructors with tagsAll parameter
gen/http/query_svc/server/encode_decode.go Added decoding support for tags_all query parameter
gen/http/query_svc/client/encode_decode.go Added encoding support for tags_all query parameter
gen/http/query_svc/client/cli.go Added CLI flag handling for tags-all parameter
gen/http/openapi3.yaml Updated OpenAPI 3.0 specification with tags_all parameter documentation
gen/http/openapi.yaml Updated Swagger 2.0 specification with tags_all parameter documentation
gen/http/openapi3.json Regenerated JSON representation of OpenAPI 3.0 spec
gen/http/openapi.json Regenerated JSON representation of Swagger 2.0 spec
gen/http/cli/lfx_v2_query_service/cli.go Updated CLI usage examples with tags-all parameter
Comments suppressed due to low confidence (1)

internal/infrastructure/opensearch/template.go:69

  • The minimum_should_match and should fields are placed incorrectly in the JSON structure. Line 66 closes the must array with ], and then lines 67-83 attempt to add minimum_should_match and should as siblings to must. However, the comma on line 67 is placed after the closing bracket of the must array, which would create invalid JSON. These fields should be properly positioned as siblings to must within the bool object. The correct structure should have the comma before line 67 removed and these fields should be at the same indentation level as the must array (inside the bool object but not inside the must array).
      ]
      {{- if .Tags }},
      "minimum_should_match": 1,
      "should": [

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Andres Tobon <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3990f9e and 5f743b5.

⛔ Files ignored due to path filters (10)
  • gen/http/openapi.json is excluded by !**/gen/**
  • gen/http/openapi.yaml is excluded by !**/gen/**
  • gen/http/openapi3.json is excluded by !**/gen/**
  • gen/http/openapi3.yaml is excluded by !**/gen/**
  • gen/http/query_svc/client/encode_decode.go is excluded by !**/gen/**
  • gen/http/query_svc/client/types.go is excluded by !**/gen/**
  • gen/http/query_svc/server/encode_decode.go is excluded by !**/gen/**
  • gen/http/query_svc/server/types.go is excluded by !**/gen/**
  • gen/query_svc/client.go is excluded by !**/gen/**
  • gen/query_svc/service.go is excluded by !**/gen/**
📒 Files selected for processing (1)
  • design/query-svc.go (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
design/**

📄 CodeRabbit inference engine (CLAUDE.md)

Keep Goa API design specifications in the design/ directory

Files:

  • design/query-svc.go
🧠 Learnings (2)
📚 Learning: 2025-09-10T17:40:14.123Z
Learnt from: CR
Repo: linuxfoundation/lfx-v2-query-service PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-10T17:40:14.123Z
Learning: Applies to cmd/query_svc/query_svc.go : Keep the service implementation that connects Goa to domain logic in cmd/query_svc/query_svc.go

Applied to files:

  • design/query-svc.go
📚 Learning: 2025-09-10T17:40:14.123Z
Learnt from: CR
Repo: linuxfoundation/lfx-v2-query-service PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-10T17:40:14.123Z
Learning: Applies to internal/service/resource_search.go : Implement use case orchestration for resource search in internal/service/resource_search.go

Applied to files:

  • design/query-svc.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: MegaLinter
🔇 Additional comments (4)
design/query-svc.go (4)

53-58: LGTM! Clear API contract for OR vs AND tag filtering.

The descriptions explicitly state the semantic difference between tags (OR logic) and tags_all (AND logic), and the examples appropriately demonstrate multiple tag values for each parameter.


80-80: LGTM! HTTP parameter mapping is correct.

The tags_all parameter is properly mapped for the query-resources endpoint.


117-122: LGTM! Consistent implementation across endpoints.

The tags and tags_all attributes for query-resources-count are identical to those in query-resources, ensuring consistent API behavior.


146-146: LGTM! HTTP parameter mapping is correct.

The tags_all parameter is properly mapped for the query-resources-count endpoint, consistent with the query-resources endpoint.

Fixed a bug where the query-resources-count endpoint would panic with
a nil pointer dereference when returning BadRequest errors. The issue
was caused by an inconsistency in the API design where the endpoint
was using dsl.ErrorResult (which generates *goa.ServiceError) instead
of the custom BadRequestError type used by other endpoints.

The generated error handling code tried to cast the error to
*goa.ServiceError, but the service was returning *querysvc.BadRequestError,
causing the cast to fail and leaving the error pointer as nil.

Changes:
- Removed the redundant dsl.Error("BadRequest", dsl.ErrorResult, ...)
  declaration from query-resources-count endpoint
- This makes it consistent with other endpoints which use the
  service-level BadRequestError type defined at line 22
- Regenerated Goa code to fix the error handling

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Andres Tobon <[email protected]>
@andrest50 andrest50 merged commit 963b99e into main Nov 21, 2025
5 checks passed
@andrest50 andrest50 deleted the andrest50/tags-all branch November 21, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants