K8s: Dashboard history: Fix version endpoint in mode3+ (#102649)

This commit is contained in:
Stephanie Hingtgen
2025-03-21 22:54:23 +02:00
committed by GitHub
parent 4cb9042e4c
commit 62e3c95e7b
2 changed files with 54 additions and 40 deletions
@@ -221,25 +221,42 @@ func (s *Service) getDashIDMaybeEmpty(ctx context.Context, uid string, orgID int
return result.ID, nil
}
func (s *Service) getHistoryThroughK8s(ctx context.Context, orgID int64, dashboardUID string, rv int64) (*dashver.DashboardVersionDTO, error) {
out, err := s.k8sclient.Get(ctx, dashboardUID, orgID, v1.GetOptions{ResourceVersion: strconv.FormatInt(rv, 10)})
if err != nil {
if apierrors.IsNotFound(err) {
func (s *Service) getHistoryThroughK8s(ctx context.Context, orgID int64, dashboardUID string, version int64) (*dashver.DashboardVersionDTO, error) {
// this is an unideal implementation - we have to list all versions and filter here, since there currently is no way to query for the
// generation id in unified storage, so we cannot query for the dashboard version directly, and we cannot use search as history is not indexed.
// use batches to make sure we don't load too much data at once.
const batchSize = 50
labelSelector := utils.LabelKeyGetHistory + "=" + dashboardUID
var continueToken string
for {
out, err := s.k8sclient.List(ctx, orgID, v1.ListOptions{
LabelSelector: labelSelector,
Limit: int64(batchSize),
Continue: continueToken,
})
if err != nil {
if apierrors.IsNotFound(err) {
return nil, dashboards.ErrDashboardNotFound
}
return nil, err
}
if out == nil {
return nil, dashboards.ErrDashboardNotFound
}
return nil, err
}
if out == nil {
return nil, dashboards.ErrDashboardNotFound
for _, item := range out.Items {
if item.GetGeneration() == version {
return s.UnstructuredToLegacyDashboardVersion(ctx, &item, orgID)
}
}
continueToken = out.GetContinue()
if continueToken == "" || len(out.Items) == 0 {
break
}
}
dash, err := s.UnstructuredToLegacyDashboardVersion(ctx, out, orgID)
if err != nil {
return nil, err
}
return dash, nil
return nil, dashboards.ErrDashboardNotFound
}
func (s *Service) listHistoryThroughK8s(ctx context.Context, orgID int64, dashboardUID string, limit int64, continueToken string) (*dashver.DashboardVersionResponse, error) {
@@ -313,18 +330,13 @@ func (s *Service) UnstructuredToLegacyDashboardVersion(ctx context.Context, item
created = *updated
}
id, err := obj.GetResourceVersionInt64()
if err != nil {
return nil, err
}
restoreVer, err := getRestoreVersion(obj.GetMessage())
if err != nil {
return nil, err
}
out := dashver.DashboardVersionDTO{
ID: id,
ID: dashVersion,
DashboardID: obj.GetDeprecatedInternalID(), // nolint:staticcheck
DashboardUID: uid,
Created: created,