From 5a930e0ec6c1170bfc387f47ca5a767d715dd8d3 Mon Sep 17 00:00:00 2001 From: Stephanie Hingtgen Date: Thu, 16 Jan 2025 22:16:48 -0700 Subject: [PATCH] K8s search: add legacy id to dashboard response (#99132) --- pkg/services/dashboards/service/dashboard_service.go | 4 +++- pkg/storage/unified/search/dashboard.go | 10 +++++++--- .../unified/search/testdata/doc/dashboard-aaa-out.json | 1 + .../unified/search/testdata/doc/dashboard-aaa.json | 3 ++- .../unified/search/testdata/manual-dashboard.json | 10 ++++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pkg/services/dashboards/service/dashboard_service.go b/pkg/services/dashboards/service/dashboard_service.go index e9fa15309de..188200725e9 100644 --- a/pkg/services/dashboards/service/dashboard_service.go +++ b/pkg/services/dashboards/service/dashboard_service.go @@ -52,6 +52,7 @@ import ( "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/storage/unified/resource" + "github.com/grafana/grafana/pkg/storage/unified/search" "github.com/grafana/grafana/pkg/util" ) @@ -1215,6 +1216,7 @@ func (dr *DashboardServiceImpl) FindDashboards(ctx context.Context, query *dashb finalResults := make([]dashboards.DashboardSearchProjection, len(response.Hits)) for i, hit := range response.Hits { finalResults[i] = dashboards.DashboardSearchProjection{ + ID: hit.Field.GetNestedInt64(search.DASHBOARD_LEGACY_ID), UID: hit.Name, OrgID: query.OrgId, Title: hit.Title, @@ -1980,7 +1982,7 @@ func ParseResults(result *resource.ResourceSearchResponse, offset int64) (*v0alp for i, row := range result.Results.Rows { fields := &common.Unstructured{} for colIndex, col := range result.Results.Columns { - if _, ok := excludedFields[col.Name]; ok { + if _, ok := excludedFields[col.Name]; !ok { val, err := resource.DecodeCell(col, colIndex, row.Cells[colIndex]) if err != nil { return nil, err diff --git a/pkg/storage/unified/search/dashboard.go b/pkg/storage/unified/search/dashboard.go index b96cbf4ae0e..20daca89039 100644 --- a/pkg/storage/unified/search/dashboard.go +++ b/pkg/storage/unified/search/dashboard.go @@ -189,6 +189,11 @@ 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) { @@ -267,6 +272,7 @@ func (s *DashboardDocumentBuilder) BuildDocument(ctx context.Context, key *resou // metadata name is the dashboard uid summary.UID = obj.GetName() + summary.ID = obj.GetDeprecatedInternalID() // nolint:staticcheck doc := resource.NewIndexableDocument(key, rv, obj) doc.Title = summary.Title @@ -310,11 +316,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, } - if summary.ID > 0 { - doc.Fields[DASHBOARD_LEGACY_ID] = summary.ID - } if len(panelTypes) > 0 { sort.Strings(panelTypes) doc.Fields[DASHBOARD_PANEL_TYPES] = panelTypes 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 cf5f5485a95..04278a03fde 100644 --- a/pkg/storage/unified/search/testdata/doc/dashboard-aaa-out.json +++ b/pkg/storage/unified/search/testdata/doc/dashboard-aaa-out.json @@ -16,6 +16,7 @@ "c" ], "labels": { + "grafana.app/deprecatedInternalID": "141", "host": "abc", "region": "xyz" }, diff --git a/pkg/storage/unified/search/testdata/doc/dashboard-aaa.json b/pkg/storage/unified/search/testdata/doc/dashboard-aaa.json index d7e09d40570..d9ecbfc6aec 100644 --- a/pkg/storage/unified/search/testdata/doc/dashboard-aaa.json +++ b/pkg/storage/unified/search/testdata/doc/dashboard-aaa.json @@ -13,7 +13,8 @@ }, "labels": { "host": "abc", - "region": "xyz" + "region": "xyz", + "grafana.app/deprecatedInternalID": "141" } }, "spec": { diff --git a/pkg/storage/unified/search/testdata/manual-dashboard.json b/pkg/storage/unified/search/testdata/manual-dashboard.json index c8375063dbc..21aeada431c 100644 --- a/pkg/storage/unified/search/testdata/manual-dashboard.json +++ b/pkg/storage/unified/search/testdata/manual-dashboard.json @@ -168,6 +168,13 @@ "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": [ @@ -198,6 +205,7 @@ null, null, null, + null, null ], "object": { @@ -239,6 +247,7 @@ 100, null, null, + null, null ], "object": { @@ -282,6 +291,7 @@ 50, null, null, + null, null ], "object": {