Dashboards: Disallow List with RV filter on legacy & align RV format (#104003)

Throw errors when trying to call List in legacy with an RV specified
Change ResourceVersion to microseconds

Co-authored-by: Marco de Abreu <18629099+marcoabreu@users.noreply.github.com>
pull/104081/head
Marco de Abreu 3 months ago committed by GitHub
parent 71b06e9845
commit d57fa1291f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      pkg/registry/apis/dashboard/legacy/sql_dashboards.go
  2. 5
      pkg/registry/apis/dashboard/legacy/storage.go
  3. 4
      pkg/registry/apis/dashboard/libary_panel.go

@ -550,7 +550,7 @@ func (a *dashboardSqlAccess) GetLibraryPanels(ctx context.Context, query Library
ObjectMeta: metav1.ObjectMeta{
Name: p.UID,
CreationTimestamp: metav1.NewTime(p.Created),
ResourceVersion: strconv.FormatInt(p.Updated.UnixMilli(), 10),
ResourceVersion: strconv.FormatInt(p.Updated.UnixMicro(), 10),
},
Spec: dashboard.LibraryPanelSpec{},
}
@ -610,7 +610,7 @@ func (a *dashboardSqlAccess) GetLibraryPanels(ctx context.Context, query Library
if query.UID == "" {
rv, err := sqlx.GetResourceVersion(ctx, "library_element", "updated")
if err == nil {
res.ResourceVersion = strconv.FormatInt(rv, 10)
res.ResourceVersion = strconv.FormatInt(rv*1000, 10) // convert to microseconds
}
}
return res, err

@ -13,6 +13,7 @@ import (
"github.com/grafana/grafana/pkg/apimachinery/utils"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/storage/unified/resource"
apierrors "k8s.io/apimachinery/pkg/api/errors"
)
func getDashboardFromEvent(event resource.WriteEvent) (*dashboard.Dashboard, error) {
@ -222,6 +223,9 @@ func (a *dashboardSqlAccess) ReadResource(ctx context.Context, req *resource.Rea
// List implements AppendingStore.
func (a *dashboardSqlAccess) ListIterator(ctx context.Context, req *resource.ListRequest, cb func(resource.ListIterator) error) (int64, error) {
if req.ResourceVersion != 0 {
return 0, apierrors.NewBadRequest("List with explicit resourceVersion is not supported with this storage backend")
}
opts := req.Options
info, err := claims.ParseNamespace(opts.Key.Namespace)
if err == nil {
@ -265,6 +269,7 @@ func (a *dashboardSqlAccess) ListIterator(ctx context.Context, req *resource.Lis
if err != nil {
return 0, err
}
listRV *= 1000 // Convert to microseconds
rows, err := a.getRows(ctx, sql, query)
if rows != nil {
defer func() {

@ -13,6 +13,7 @@ import (
"github.com/grafana/grafana/pkg/apimachinery/utils"
"github.com/grafana/grafana/pkg/registry/apis/dashboard/legacy"
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
apierrors "k8s.io/apimachinery/pkg/api/errors"
)
var (
@ -51,6 +52,9 @@ func (s *LibraryPanelStore) ConvertToTable(ctx context.Context, object runtime.O
}
func (s *LibraryPanelStore) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) {
if options.ResourceVersion != "" {
return nil, apierrors.NewBadRequest("List with explicit resourceVersion is not supported with this storage backend")
}
ns, err := request.NamespaceInfoFrom(ctx, true)
if err != nil {
return nil, err

Loading…
Cancel
Save