diff --git a/pkg/registry/apis/dashboard/legacysearcher/search_client.go b/pkg/registry/apis/dashboard/legacysearcher/search_client.go index 01e22c1c516..06782789890 100644 --- a/pkg/registry/apis/dashboard/legacysearcher/search_client.go +++ b/pkg/registry/apis/dashboard/legacysearcher/search_client.go @@ -233,11 +233,7 @@ func (c *DashboardSearchClient) Search(ctx context.Context, req *resource.Resour searchFields.Field(resource.SEARCH_FIELD_TITLE), searchFields.Field(resource.SEARCH_FIELD_FOLDER), searchFields.Field(resource.SEARCH_FIELD_TAGS), - { - Name: unisearch.DASHBOARD_LEGACY_ID, - Type: resource.ResourceTableColumnDefinition_INT64, - Description: "Deprecated legacy id of the dashboard", - }, + searchFields.Field(resource.SEARCH_FIELD_LEGACY_ID), } if sortByField != "" { diff --git a/pkg/registry/apis/dashboard/legacysearcher/search_client_test.go b/pkg/registry/apis/dashboard/legacysearcher/search_client_test.go index b7164f94591..2f8a00f691c 100644 --- a/pkg/registry/apis/dashboard/legacysearcher/search_client_test.go +++ b/pkg/registry/apis/dashboard/legacysearcher/search_client_test.go @@ -72,11 +72,7 @@ func TestDashboardSearchClient_Search(t *testing.T) { searchFields.Field(resource.SEARCH_FIELD_TITLE), searchFields.Field(resource.SEARCH_FIELD_FOLDER), searchFields.Field(resource.SEARCH_FIELD_TAGS), - { - Name: unisearch.DASHBOARD_LEGACY_ID, - Type: resource.ResourceTableColumnDefinition_INT64, - Description: "Deprecated legacy id of the dashboard", - }, + searchFields.Field(resource.SEARCH_FIELD_LEGACY_ID), }, Rows: []*resource.ResourceTableRow{ { @@ -149,11 +145,7 @@ func TestDashboardSearchClient_Search(t *testing.T) { searchFields.Field(resource.SEARCH_FIELD_TITLE), searchFields.Field(resource.SEARCH_FIELD_FOLDER), searchFields.Field(resource.SEARCH_FIELD_TAGS), - { - Name: unisearch.DASHBOARD_LEGACY_ID, - Type: resource.ResourceTableColumnDefinition_INT64, - Description: "Deprecated legacy id of the dashboard", - }, + searchFields.Field(resource.SEARCH_FIELD_LEGACY_ID), { Name: "views_total", Type: resource.ResourceTableColumnDefinition_INT64, @@ -218,11 +210,7 @@ func TestDashboardSearchClient_Search(t *testing.T) { searchFields.Field(resource.SEARCH_FIELD_TITLE), searchFields.Field(resource.SEARCH_FIELD_FOLDER), searchFields.Field(resource.SEARCH_FIELD_TAGS), - { - Name: unisearch.DASHBOARD_LEGACY_ID, - Type: resource.ResourceTableColumnDefinition_INT64, - Description: "Deprecated legacy id of the dashboard", - }, + searchFields.Field(resource.SEARCH_FIELD_LEGACY_ID), { Name: "errors_last_30_days", Type: resource.ResourceTableColumnDefinition_INT64, diff --git a/pkg/services/dashboards/service/dashboard_service.go b/pkg/services/dashboards/service/dashboard_service.go index 7de0c917e3b..c7fb77c6769 100644 --- a/pkg/services/dashboards/service/dashboard_service.go +++ b/pkg/services/dashboards/service/dashboard_service.go @@ -57,7 +57,6 @@ import ( "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/storage/legacysql/dualwrite" "github.com/grafana/grafana/pkg/storage/unified/resource" - "github.com/grafana/grafana/pkg/storage/unified/search" "github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/util/retryer" "go.opentelemetry.io/otel/attribute" @@ -1541,7 +1540,7 @@ func (dr *DashboardServiceImpl) FindDashboards(ctx context.Context, query *dashb finalResults := make([]dashboards.DashboardSearchProjection, len(response.Hits)) for i, hit := range response.Hits { result := dashboards.DashboardSearchProjection{ - ID: hit.Field.GetNestedInt64(search.DASHBOARD_LEGACY_ID), + ID: hit.Field.GetNestedInt64(resource.SEARCH_FIELD_LEGACY_ID), UID: hit.Name, OrgID: query.OrgId, Title: hit.Title, diff --git a/pkg/services/dashboards/service/search/search_test.go b/pkg/services/dashboards/service/search/search_test.go index 903abdc3355..405eaf240a6 100644 --- a/pkg/services/dashboards/service/search/search_test.go +++ b/pkg/services/dashboards/service/search/search_test.go @@ -74,8 +74,8 @@ func TestParseResults(t *testing.T) { Type: resource.ResourceTableColumnDefinition_INT32, }, { - Name: search.DASHBOARD_LEGACY_ID, - Type: resource.ResourceTableColumnDefinition_INT32, + Name: resource.SEARCH_FIELD_LEGACY_ID, + Type: resource.ResourceTableColumnDefinition_INT64, }, }, Rows: []*resource.ResourceTableRow{ diff --git a/pkg/services/folder/folderimpl/folder_unifiedstorage.go b/pkg/services/folder/folderimpl/folder_unifiedstorage.go index 98dcdb4881d..fa7b45b6fb7 100644 --- a/pkg/services/folder/folderimpl/folder_unifiedstorage.go +++ b/pkg/services/folder/folderimpl/folder_unifiedstorage.go @@ -28,7 +28,6 @@ import ( "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/store/entity" "github.com/grafana/grafana/pkg/storage/unified/resource" - "github.com/grafana/grafana/pkg/storage/unified/search" "github.com/grafana/grafana/pkg/util" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -219,7 +218,7 @@ func (s *Service) searchFoldersFromApiServer(ctx context.Context, query folder.S for i, item := range parsedResults.Hits { slug := slugify.Slugify(item.Title) hitList[i] = &model.Hit{ - ID: item.Field.GetNestedInt64(search.DASHBOARD_LEGACY_ID), + ID: item.Field.GetNestedInt64(resource.SEARCH_FIELD_LEGACY_ID), UID: item.Name, OrgID: query.OrgID, Title: item.Title, diff --git a/pkg/services/folder/folderimpl/unifiedstore.go b/pkg/services/folder/folderimpl/unifiedstore.go index 70221201a1a..1457fa8407c 100644 --- a/pkg/services/folder/folderimpl/unifiedstore.go +++ b/pkg/services/folder/folderimpl/unifiedstore.go @@ -15,7 +15,6 @@ import ( claims "github.com/grafana/authlib/types" "github.com/grafana/grafana/pkg/apimachinery/utils" "github.com/grafana/grafana/pkg/storage/unified/resource" - "github.com/grafana/grafana/pkg/storage/unified/search" "github.com/grafana/grafana/pkg/apis/folder/v0alpha1" "github.com/grafana/grafana/pkg/infra/log" @@ -238,7 +237,7 @@ func (ss *FolderUnifiedStoreImpl) GetChildren(ctx context.Context, q folder.GetC } f := &folder.FolderReference{ - ID: item.Field.GetNestedInt64(search.DASHBOARD_LEGACY_ID), + ID: item.Field.GetNestedInt64(resource.SEARCH_FIELD_LEGACY_ID), UID: item.Name, Title: item.Title, ParentUID: item.Folder, diff --git a/pkg/storage/unified/resource/document.go b/pkg/storage/unified/resource/document.go index 9a2c6c36716..39b74532a98 100644 --- a/pkg/storage/unified/resource/document.go +++ b/pkg/storage/unified/resource/document.go @@ -272,7 +272,8 @@ func (x *searchableDocumentFields) Field(name string) *ResourceTableColumnDefini } const SEARCH_FIELD_PREFIX = "fields." -const SEARCH_FIELD_ID = "_id" // {namespace}/{group}/{resource}/{name} +const SEARCH_FIELD_ID = "_id" // {namespace}/{group}/{resource}/{name} +const SEARCH_FIELD_LEGACY_ID = utils.LabelKeyDeprecatedInternalID const SEARCH_FIELD_KIND = "kind" // resource ( for federated index filtering ) const SEARCH_FIELD_GROUP_RESOURCE = "gr" // group/resource const SEARCH_FIELD_NAMESPACE = "namespace" @@ -387,6 +388,11 @@ func StandardSearchFields() SearchableDocumentFields { Type: ResourceTableColumnDefinition_DOUBLE, Description: "The search score", }, + { + Name: SEARCH_FIELD_LEGACY_ID, + Type: ResourceTableColumnDefinition_INT64, + Description: "Deprecated legacy id of the resource", + }, }) if err != nil { panic("failed to initialize standard search fields") diff --git a/pkg/storage/unified/search/bleve.go b/pkg/storage/unified/search/bleve.go index 0b6a2c496b3..0203fe186de 100644 --- a/pkg/storage/unified/search/bleve.go +++ b/pkg/storage/unified/search/bleve.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" "slices" + "strconv" "strings" "sync" "time" @@ -1029,6 +1030,15 @@ func (b *bleveIndex) hitsToTable(ctx context.Context, selectFields []string, hit if match.Expl != nil { row.Cells[i], err = json.Marshal(match.Expl) } + case resource.SEARCH_FIELD_LEGACY_ID: + v := match.Fields[resource.SEARCH_FIELD_LABELS+"."+resource.SEARCH_FIELD_LEGACY_ID] + if v != nil { + str, ok := v.(string) + if ok { + id, _ := strconv.ParseInt(str, 10, 64) + row.Cells[i], err = encoders[i](id) + } + } default: fieldName := f.Name // since the bleve index fields mix common and resource-specific fields, it is possible a conflict can happen @@ -1060,6 +1070,7 @@ func getAllFields(standard resource.SearchableDocumentFields, custom resource.Se standard.Field(resource.SEARCH_FIELD_FOLDER), standard.Field(resource.SEARCH_FIELD_RV), standard.Field(resource.SEARCH_FIELD_CREATED), + standard.Field(resource.SEARCH_FIELD_LEGACY_ID), } if custom != nil { diff --git a/pkg/storage/unified/search/bleve_test.go b/pkg/storage/unified/search/bleve_test.go index d8d4af741ff..0ac8d9c0c5c 100644 --- a/pkg/storage/unified/search/bleve_test.go +++ b/pkg/storage/unified/search/bleve_test.go @@ -348,6 +348,9 @@ func TestBleveBackend(t *testing.T) { Checksum: "xxxx", TimestampMillis: 300, }, + Labels: map[string]string{ + utils.LabelKeyDeprecatedInternalID: "123", + }, }) _ = index.Write(&resource.IndexableDocument{ RV: 2, @@ -359,7 +362,8 @@ func TestBleveBackend(t *testing.T) { }, Title: "yyy (folder)", Labels: map[string]string{ - "region": "west", + "region": "west", + utils.LabelKeyDeprecatedInternalID: "321", }, }) return rv, nil diff --git a/pkg/storage/unified/search/dashboard.go b/pkg/storage/unified/search/dashboard.go index 62b8125726c..888c2f0c4ab 100644 --- a/pkg/storage/unified/search/dashboard.go +++ b/pkg/storage/unified/search/dashboard.go @@ -18,7 +18,6 @@ import ( // Standard dashboard fields //------------------------------------------------------------ -const DASHBOARD_LEGACY_ID = "legacy_id" const DASHBOARD_SCHEMA_VERSION = "schema_version" const DASHBOARD_LINK_COUNT = "link_count" const DASHBOARD_PANEL_TYPES = "panel_types" @@ -189,11 +188,6 @@ func DashboardBuilder(namespaced resource.NamespacedDocumentSupplier) (resource. Filterable: true, }, }, - { - Name: DASHBOARD_LEGACY_ID, - Type: resource.ResourceTableColumnDefinition_INT64, - Description: "Deprecated legacy id of the dashboard", - }, }) if namespaced == nil { namespaced = func(ctx context.Context, namespace string, blob resource.BlobSupport) (resource.DocumentBuilder, error) { @@ -314,9 +308,9 @@ func (s *DashboardDocumentBuilder) BuildDocument(ctx context.Context, key *resou } doc.Fields = map[string]any{ - DASHBOARD_SCHEMA_VERSION: summary.SchemaVersion, - DASHBOARD_LINK_COUNT: summary.LinkCount, - DASHBOARD_LEGACY_ID: summary.ID, + DASHBOARD_SCHEMA_VERSION: summary.SchemaVersion, + DASHBOARD_LINK_COUNT: summary.LinkCount, + resource.SEARCH_FIELD_LEGACY_ID: summary.ID, } if len(panelTypes) > 0 { @@ -342,7 +336,6 @@ func (s *DashboardDocumentBuilder) BuildDocument(ctx context.Context, key *resou func DashboardFields() []string { baseFields := []string{ - DASHBOARD_LEGACY_ID, DASHBOARD_SCHEMA_VERSION, DASHBOARD_LINK_COUNT, DASHBOARD_PANEL_TYPES, diff --git a/pkg/storage/unified/search/testdata/doc/dashboard-aaa-out.json b/pkg/storage/unified/search/testdata/doc/dashboard-aaa-out.json index 1edd60a2ec9..964eb2fec41 100644 --- a/pkg/storage/unified/search/testdata/doc/dashboard-aaa-out.json +++ b/pkg/storage/unified/search/testdata/doc/dashboard-aaa-out.json @@ -31,7 +31,7 @@ ], "errors_last_1_days": 1, "errors_last_7_days": 1, - "legacy_id": 141, + "grafana.app/deprecatedInternalID": 141, "link_count": 0, "panel_types": [ "barchart", diff --git a/pkg/storage/unified/search/testdata/manual-dashboard.json b/pkg/storage/unified/search/testdata/manual-dashboard.json index 21aeada431c..dbea7a6014e 100644 --- a/pkg/storage/unified/search/testdata/manual-dashboard.json +++ b/pkg/storage/unified/search/testdata/manual-dashboard.json @@ -43,6 +43,13 @@ "description": "created timestamp", "priority": 0 }, + { + "name": "grafana.app/deprecatedInternalID", + "type": "number", + "format": "int64", + "description": "Deprecated legacy id of the resource", + "priority": 0 + }, { "name": "schema_version", "type": "number", @@ -168,13 +175,6 @@ "format": "int64", "description": "Total number of views", "priority": 0 - }, - { - "name": "legacy_id", - "type": "number", - "format": "int64", - "description": "Deprecated legacy id of the dashboard", - "priority": 0 } ], "rows": [ @@ -228,6 +228,7 @@ "xxx", null, null, + 11, null, null, [ @@ -247,7 +248,6 @@ 100, null, null, - null, null ], "object": { @@ -271,6 +271,7 @@ "xxx", null, null, + 10, null, null, [ @@ -291,7 +292,6 @@ 50, null, null, - null, null ], "object": { diff --git a/pkg/storage/unified/search/testdata/manual-folder.json b/pkg/storage/unified/search/testdata/manual-folder.json index 06e8b593eba..a2cf62df9eb 100644 --- a/pkg/storage/unified/search/testdata/manual-folder.json +++ b/pkg/storage/unified/search/testdata/manual-folder.json @@ -42,6 +42,13 @@ "format": "int64", "description": "created timestamp", "priority": 0 + }, + { + "name": "grafana.app/deprecatedInternalID", + "type": "number", + "format": "int64", + "description": "Deprecated legacy id of the resource", + "priority": 0 } ], "rows": [ @@ -52,7 +59,8 @@ null, null, null, - null + null, + 321 ], "object": { "kind": "folders", @@ -71,7 +79,8 @@ null, null, null, - null + null, + 123 ], "object": { "kind": "folders",