K8s: Search fallback: Support all sort by methods (#100776)
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
ngalertstore "github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||
"github.com/grafana/grafana/pkg/services/search/sort"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -52,7 +53,7 @@ func TestDirectSQLStats(t *testing.T) {
|
||||
fStore := folderimpl.ProvideStore(db)
|
||||
folderSvc := folderimpl.ProvideService(
|
||||
fStore, actest.FakeAccessControl{ExpectedEvaluate: true}, bus.ProvideBus(tracing.InitializeTracerForTest()), dashStore, folderimpl.ProvideDashboardFolderStore(db),
|
||||
nil, db, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil)
|
||||
nil, db, featuremgmt.WithFeatures(), supportbundlestest.NewFakeBundleService(), nil, cfg, nil, tracing.InitializeTracerForTest(), nil, sort.ProvideService())
|
||||
|
||||
// create parent folder
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ func (x *searchableDocumentFields) Fields() []string {
|
||||
}
|
||||
|
||||
func (x *searchableDocumentFields) Field(name string) *ResourceTableColumnDefinition {
|
||||
name = strings.TrimPrefix(name, "fields.")
|
||||
name = strings.TrimPrefix(name, SEARCH_FIELD_PREFIX)
|
||||
|
||||
f, ok := x.fields[name]
|
||||
if ok {
|
||||
@@ -246,6 +246,7 @@ func (x *searchableDocumentFields) Field(name string) *ResourceTableColumnDefini
|
||||
return nil
|
||||
}
|
||||
|
||||
const SEARCH_FIELD_PREFIX = "fields."
|
||||
const SEARCH_FIELD_ID = "_id" // {namespace}/{group}/{resource}/{name}
|
||||
const SEARCH_FIELD_KIND = "kind" // resource ( for federated index filtering )
|
||||
const SEARCH_FIELD_GROUP_RESOURCE = "gr" // group/resource
|
||||
|
||||
@@ -552,7 +552,7 @@ func (b *bleveIndex) toBleveSearchRequest(ctx context.Context, req *resource.Res
|
||||
fields := make([]string, 0, len(req.Fields))
|
||||
for _, f := range req.Fields {
|
||||
if slices.Contains(DashboardFields(), f) {
|
||||
f = "fields." + f
|
||||
f = resource.SEARCH_FIELD_PREFIX + f
|
||||
}
|
||||
fields = append(fields, f)
|
||||
}
|
||||
@@ -677,7 +677,7 @@ func getSortFields(req *resource.ResourceSearchRequest) []string {
|
||||
}
|
||||
|
||||
if slices.Contains(DashboardFields(), input) {
|
||||
input = "fields." + input
|
||||
input = resource.SEARCH_FIELD_PREFIX + input
|
||||
}
|
||||
|
||||
if sort.Desc {
|
||||
@@ -847,7 +847,7 @@ func (b *bleveIndex) hitsToTable(ctx context.Context, selectFields []string, hit
|
||||
v := match.Fields[fieldName]
|
||||
// fields that are specific to the resource get stored as fields.<fieldName>, so we need to check for that
|
||||
if v == nil {
|
||||
v = match.Fields["fields."+fieldName]
|
||||
v = match.Fields[resource.SEARCH_FIELD_PREFIX+fieldName]
|
||||
}
|
||||
if v != nil {
|
||||
// Encode the value to protobuf
|
||||
|
||||
Reference in New Issue
Block a user