wire up unified search from the ui; add basic search support (#94358)
* wire up search from the ui; add basic search support
This commit is contained in:
@@ -15,8 +15,10 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/searchV2"
|
||||
"github.com/grafana/grafana/pkg/services/store"
|
||||
"github.com/grafana/grafana/pkg/services/unifiedSearch"
|
||||
testdatasource "github.com/grafana/grafana/pkg/tsdb/grafana-testdata-datasource"
|
||||
)
|
||||
|
||||
@@ -51,15 +53,17 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func ProvideService(search searchV2.SearchService, store store.StorageService) *Service {
|
||||
return newService(search, store)
|
||||
func ProvideService(search searchV2.SearchService, searchNext unifiedSearch.SearchService, store store.StorageService, features featuremgmt.FeatureToggles) *Service {
|
||||
return newService(search, searchNext, store, features)
|
||||
}
|
||||
|
||||
func newService(search searchV2.SearchService, store store.StorageService) *Service {
|
||||
func newService(search searchV2.SearchService, searchNext unifiedSearch.SearchService, store store.StorageService, features featuremgmt.FeatureToggles) *Service {
|
||||
s := &Service{
|
||||
search: search,
|
||||
store: store,
|
||||
log: log.New("grafanads"),
|
||||
search: search,
|
||||
searchNext: searchNext,
|
||||
store: store,
|
||||
log: log.New("grafanads"),
|
||||
features: features,
|
||||
}
|
||||
|
||||
return s
|
||||
@@ -67,9 +71,11 @@ func newService(search searchV2.SearchService, store store.StorageService) *Serv
|
||||
|
||||
// Service exists regardless of user settings
|
||||
type Service struct {
|
||||
search searchV2.SearchService
|
||||
store store.StorageService
|
||||
log log.Logger
|
||||
search searchV2.SearchService
|
||||
searchNext unifiedSearch.SearchService
|
||||
store store.StorageService
|
||||
log log.Logger
|
||||
features featuremgmt.FeatureToggles
|
||||
}
|
||||
|
||||
func DataSourceModel(orgId int64) *datasources.DataSource {
|
||||
@@ -95,7 +101,7 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
|
||||
response.Responses[q.RefID] = s.doListQuery(ctx, q)
|
||||
case queryTypeRead:
|
||||
response.Responses[q.RefID] = s.doReadQuery(ctx, q)
|
||||
case queryTypeSearch:
|
||||
case queryTypeSearch, queryTypeSearchNext:
|
||||
response.Responses[q.RefID] = s.doSearchQuery(ctx, req, q)
|
||||
default:
|
||||
response.Responses[q.RefID] = backend.DataResponse{
|
||||
@@ -177,6 +183,18 @@ func (s *Service) doRandomWalk(query backend.DataQuery) backend.DataResponse {
|
||||
}
|
||||
|
||||
func (s *Service) doSearchQuery(ctx context.Context, req *backend.QueryDataRequest, query backend.DataQuery) backend.DataResponse {
|
||||
m := requestModel{}
|
||||
err := json.Unmarshal(query.JSON, &m)
|
||||
if err != nil {
|
||||
return backend.DataResponse{
|
||||
Error: err,
|
||||
}
|
||||
}
|
||||
|
||||
if s.features.IsEnabled(ctx, featuremgmt.FlagUnifiedStorageSearch) {
|
||||
return *s.searchNext.DoQuery(ctx, req.PluginContext.User, req.PluginContext.OrgID, m.SearchNext)
|
||||
}
|
||||
|
||||
searchReadinessCheckResp := s.search.IsReady(ctx, req.PluginContext.OrgID)
|
||||
if !searchReadinessCheckResp.IsReady {
|
||||
dashboardSearchNotServedRequestsCounter.With(prometheus.Labels{
|
||||
@@ -192,17 +210,11 @@ func (s *Service) doSearchQuery(ctx context.Context, req *backend.QueryDataReque
|
||||
}
|
||||
}
|
||||
|
||||
m := requestModel{}
|
||||
err := json.Unmarshal(query.JSON, &m)
|
||||
if err != nil {
|
||||
return backend.DataResponse{
|
||||
Error: err,
|
||||
}
|
||||
}
|
||||
return *s.search.DoDashboardQuery(ctx, req.PluginContext.User, req.PluginContext.OrgID, m.Search)
|
||||
}
|
||||
|
||||
type requestModel struct {
|
||||
QueryType string `json:"queryType"`
|
||||
Search searchV2.DashboardQuery `json:"search,omitempty"`
|
||||
QueryType string `json:"queryType"`
|
||||
Search searchV2.DashboardQuery `json:"search,omitempty"`
|
||||
SearchNext unifiedSearch.Query `json:"searchNext,omitempty"`
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ const (
|
||||
// QueryTypeList will list the files in a folder
|
||||
queryTypeSearch = "search"
|
||||
|
||||
// queryTypeSearchNext will perform a search query using the next generation search service
|
||||
queryTypeSearchNext = "searchNext"
|
||||
|
||||
// QueryTypeList will list the files in a folder
|
||||
queryTypeList = "list"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user