Skip to content

Commit

Permalink
K8s search: add legacy id to dashboard response (grafana#99132)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephaniehingtgen authored Jan 17, 2025
1 parent 6901bad commit 5a930e0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pkg/services/dashboards/service/dashboard_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions pkg/storage/unified/search/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"c"
],
"labels": {
"grafana.app/deprecatedInternalID": "141",
"host": "abc",
"region": "xyz"
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/unified/search/testdata/doc/dashboard-aaa.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
},
"labels": {
"host": "abc",
"region": "xyz"
"region": "xyz",
"grafana.app/deprecatedInternalID": "141"
}
},
"spec": {
Expand Down
10 changes: 10 additions & 0 deletions pkg/storage/unified/search/testdata/manual-dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -198,6 +205,7 @@
null,
null,
null,
null,
null
],
"object": {
Expand Down Expand Up @@ -239,6 +247,7 @@
100,
null,
null,
null,
null
],
"object": {
Expand Down Expand Up @@ -282,6 +291,7 @@
50,
null,
null,
null,
null
],
"object": {
Expand Down

0 comments on commit 5a930e0

Please sign in to comment.