mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 22:19:30 +08:00
K8s: Search fallback: Support tag search (#100767)
This commit is contained in:

committed by
GitHub

parent
b89fd287c7
commit
9494e6eb37
@ -89,6 +89,36 @@ func (c *DashboardSearchClient) Search(ctx context.Context, req *resource.Resour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if searching for tags, get those instead of the dashboards or folders
|
||||||
|
for facet, _ := range req.Facet {
|
||||||
|
if facet == resource.SEARCH_FIELD_TAGS {
|
||||||
|
tags, err := c.dashboardStore.GetDashboardTags(ctx, &dashboards.GetDashboardTagsQuery{
|
||||||
|
OrgID: user.GetOrgID(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
list := &resource.ResourceSearchResponse{
|
||||||
|
Results: &resource.ResourceTable{},
|
||||||
|
Facet: map[string]*resource.ResourceSearchResponse_Facet{
|
||||||
|
"tags": &resource.ResourceSearchResponse_Facet{
|
||||||
|
Terms: []*resource.ResourceSearchResponse_TermFacet{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tag := range tags {
|
||||||
|
list.Facet["tags"].Terms = append(list.Facet["tags"].Terms, &resource.ResourceSearchResponse_TermFacet{
|
||||||
|
Term: tag.Term,
|
||||||
|
Count: int64(tag.Count),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// handle deprecated dashboardIds query param
|
// handle deprecated dashboardIds query param
|
||||||
for _, field := range req.Options.Labels {
|
for _, field := range req.Options.Labels {
|
||||||
if field.Key == utils.LabelKeyDeprecatedInternalID {
|
if field.Key == utils.LabelKeyDeprecatedInternalID {
|
||||||
|
@ -92,6 +92,46 @@ func TestDashboardSearchClient_Search(t *testing.T) {
|
|||||||
mockStore.AssertExpectations(t)
|
mockStore.AssertExpectations(t)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Query for tags should return facet properly", func(t *testing.T) {
|
||||||
|
mockStore.On("GetDashboardTags", mock.Anything, &dashboards.GetDashboardTagsQuery{OrgID: 2}).Return([]*dashboards.DashboardTagCloudItem{
|
||||||
|
{Term: "tag1", Count: 1},
|
||||||
|
{Term: "tag2", Count: 5},
|
||||||
|
}, nil).Once()
|
||||||
|
|
||||||
|
req := &resource.ResourceSearchRequest{
|
||||||
|
Facet: map[string]*resource.ResourceSearchRequest_Facet{
|
||||||
|
"tags": {
|
||||||
|
Field: "tags",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Options: &resource.ListOptions{
|
||||||
|
Key: dashboardKey,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
resp, err := client.Search(ctx, req)
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
require.Equal(t, &resource.ResourceSearchResponse{
|
||||||
|
Results: &resource.ResourceTable{},
|
||||||
|
Facet: map[string]*resource.ResourceSearchResponse_Facet{
|
||||||
|
"tags": &resource.ResourceSearchResponse_Facet{
|
||||||
|
Terms: []*resource.ResourceSearchResponse_TermFacet{
|
||||||
|
{
|
||||||
|
Term: "tag1",
|
||||||
|
Count: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Term: "tag2",
|
||||||
|
Count: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, resp)
|
||||||
|
mockStore.AssertExpectations(t)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Query should be set as the title, and * should be removed", func(t *testing.T) {
|
t.Run("Query should be set as the title, and * should be removed", func(t *testing.T) {
|
||||||
mockStore.On("FindDashboards", mock.Anything, &dashboards.FindPersistedDashboardsQuery{
|
mockStore.On("FindDashboards", mock.Anything, &dashboards.FindPersistedDashboardsQuery{
|
||||||
Title: "test",
|
Title: "test",
|
||||||
|
Reference in New Issue
Block a user