From c8664d303ee90fc753841d836857a52d2a34fe11 Mon Sep 17 00:00:00 2001 From: owensmallwood Date: Tue, 21 Oct 2025 11:54:14 -0600 Subject: [PATCH] Unified Storage: Match all included tags (#112748) * if you include multiple tags in the search query, search for them using AND logic * go-fmt --- .../dashboards/service/dashboard_service.go | 2 +- .../service/dashboard_service_test.go | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pkg/services/dashboards/service/dashboard_service.go b/pkg/services/dashboards/service/dashboard_service.go index 170c924b6cda..7ef77f9a0ab5 100644 --- a/pkg/services/dashboards/service/dashboard_service.go +++ b/pkg/services/dashboards/service/dashboard_service.go @@ -1937,7 +1937,7 @@ func (dr *DashboardServiceImpl) searchDashboardsThroughK8sRaw(ctx context.Contex if len(query.Tags) > 0 { req := []*resourcepb.Requirement{{ Key: resource.SEARCH_FIELD_TAGS, - Operator: string(selection.In), + Operator: "=", Values: query.Tags, }} request.Options.Fields = append(request.Options.Fields, req...) diff --git a/pkg/services/dashboards/service/dashboard_service_test.go b/pkg/services/dashboards/service/dashboard_service_test.go index b18df17c12f3..e5043dff6402 100644 --- a/pkg/services/dashboards/service/dashboard_service_test.go +++ b/pkg/services/dashboards/service/dashboard_service_test.go @@ -1938,6 +1938,33 @@ func TestSearchDashboardsThroughK8sRaw(t *testing.T) { assert.Equal(t, "dash-db", query.Type) // query type should be added }) + t.Run("search will try and match all included tags", func(t *testing.T) { + ctx := context.Background() + k8sCliMock := new(client.MockK8sHandler) + service := &DashboardServiceImpl{k8sclient: k8sCliMock} + query := &dashboards.FindPersistedDashboardsQuery{ + OrgId: 1, + Sort: model.SortOption{Name: "viewed-recently-desc"}, + Tags: []string{"tag1", "tag2"}, + } + k8sCliMock.On("GetNamespace", mock.Anything, mock.Anything).Return("default") + k8sCliMock.On("Search", mock.Anything, mock.Anything, mock.MatchedBy(func(req *resourcepb.ResourceSearchRequest) bool { + // make sure we use AND logic with multiple tags + for _, field := range req.Options.Fields { + if field.Key == "tags" { + return field.Operator == "=" + } + } + return false + })).Return(&resourcepb.ResourceSearchResponse{ + Results: &resourcepb.ResourceTable{ + Columns: []*resourcepb.ResourceTableColumnDefinition{}, + Rows: []*resourcepb.ResourceTableRow{}, + }}, nil) + _, err := service.searchDashboardsThroughK8s(ctx, query) + require.NoError(t, err) + }) + t.Run("search will include sort field in hit fields", func(t *testing.T) { ctx := context.Background() k8sCliMock := new(client.MockK8sHandler)