K8s: Dashboards: Fix search parsing (#98560)

This commit is contained in:
Stephanie Hingtgen 2025-01-06 14:41:45 -07:00 committed by GitHub
parent 69af0f7ab6
commit c566e6af4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 5 deletions

View File

@ -310,7 +310,13 @@ func (s *SearchHandler) DoSearch(w http.ResponseWriter, r *http.Request) {
return return
} }
s.write(w, dashboardsvc.ParseResults(result, searchRequest.Offset)) parsedResults, err := dashboardsvc.ParseResults(result, searchRequest.Offset)
if err != nil {
errhttp.Write(ctx, err, w)
return
}
s.write(w, parsedResults)
} }
func (s *SearchHandler) write(w http.ResponseWriter, obj any) { func (s *SearchHandler) write(w http.ResponseWriter, obj any) {

View File

@ -1360,7 +1360,7 @@ func (dr *DashboardServiceImpl) searchDashboardsThroughK8sRaw(ctx context.Contex
return nil, err return nil, err
} }
return ParseResults(res, 0), nil return ParseResults(res, 0)
} }
func (dr *DashboardServiceImpl) searchDashboardsThroughK8s(ctx context.Context, query *dashboards.FindPersistedDashboardsQuery) ([]*dashboards.Dashboard, error) { func (dr *DashboardServiceImpl) searchDashboardsThroughK8s(ctx context.Context, query *dashboards.FindPersistedDashboardsQuery) ([]*dashboards.Dashboard, error) {
@ -1382,9 +1382,13 @@ func (dr *DashboardServiceImpl) searchDashboardsThroughK8s(ctx context.Context,
return result, nil return result, nil
} }
func ParseResults(result *resource.ResourceSearchResponse, offset int64) *v0alpha1.SearchResults { func ParseResults(result *resource.ResourceSearchResponse, offset int64) (*v0alpha1.SearchResults, error) {
if result == nil { if result == nil {
return nil return nil, nil
} else if result.Error != nil {
return nil, fmt.Errorf("%d error searching: %s: %s", result.Error.Code, result.Error.Message, result.Error.Details)
} else if result.Results == nil {
return nil, nil
} }
titleIDX := 0 titleIDX := 0
@ -1455,7 +1459,7 @@ func ParseResults(result *resource.ResourceSearchResponse, offset int64) *v0alph
} }
} }
return sr return sr, nil
} }
func (dr *DashboardServiceImpl) UnstructuredToLegacyDashboard(ctx context.Context, item *unstructured.Unstructured, orgID int64) (*dashboards.Dashboard, error) { func (dr *DashboardServiceImpl) UnstructuredToLegacyDashboard(ctx context.Context, item *unstructured.Unstructured, orgID int64) (*dashboards.Dashboard, error) {