diff --git a/pkg/registry/apis/dashboard/legacy/storage.go b/pkg/registry/apis/dashboard/legacy/storage.go index 7064d1d9994..239bc77ef90 100644 --- a/pkg/registry/apis/dashboard/legacy/storage.go +++ b/pkg/registry/apis/dashboard/legacy/storage.go @@ -8,6 +8,7 @@ import ( "time" claims "github.com/grafana/authlib/types" + "github.com/grafana/grafana/pkg/apimachinery/utils" dashboard "github.com/grafana/grafana/pkg/apis/dashboard" "github.com/grafana/grafana/pkg/storage/unified/resource" @@ -86,7 +87,10 @@ func (a *dashboardSqlAccess) WriteEvent(ctx context.Context, event resource.Writ if a.subscribers != nil { go func() { write := &resource.WrittenEvent{ - WriteEvent: event, + Type: event.Type, + Key: event.Key, + PreviousRV: event.PreviousRV, + Value: event.Value, Timestamp: time.Now().UnixMilli(), ResourceVersion: rv, diff --git a/pkg/storage/unified/resource/cdk_backend.go b/pkg/storage/unified/resource/cdk_backend.go index eefba09d78f..19a7385a3f5 100644 --- a/pkg/storage/unified/resource/cdk_backend.go +++ b/pkg/storage/unified/resource/cdk_backend.go @@ -131,7 +131,10 @@ func (s *cdkBackend) WriteEvent(ctx context.Context, event WriteEvent) (rv int64 if s.stream != nil { go func() { write := &WrittenEvent{ - WriteEvent: event, + Type: event.Type, + Key: event.Key, + PreviousRV: event.PreviousRV, + Value: event.Value, Timestamp: time.Now().UnixMilli(), ResourceVersion: rv, } diff --git a/pkg/storage/unified/resource/event.go b/pkg/storage/unified/resource/event.go index 91c9225ee0c..fc408e23027 100644 --- a/pkg/storage/unified/resource/event.go +++ b/pkg/storage/unified/resource/event.go @@ -21,18 +21,24 @@ type WriteEvent struct { ObjectOld utils.GrafanaMetaAccessor } -// WriteEvents after they include a resource version +// WrittenEvent is a WriteEvent reported with a resource version. type WrittenEvent struct { - WriteEvent + Type WatchEvent_Type + Key *ResourceKey + PreviousRV int64 + + // The json payload (without resourceVersion) + Value []byte + // Metadata Folder string - // The resource version + // The resource version. ResourceVersion int64 // Timestamp when the event is created Timestamp int64 } -// A function to write events +// EventAppender is a function to write events. type EventAppender = func(context.Context, *WriteEvent) (int64, error) diff --git a/pkg/storage/unified/sql/backend.go b/pkg/storage/unified/sql/backend.go index 777164b9e2b..18b95019429 100644 --- a/pkg/storage/unified/sql/backend.go +++ b/pkg/storage/unified/sql/backend.go @@ -851,17 +851,15 @@ func (b *backend) poll(ctx context.Context, grp string, res string, since int64, prevRV = new(int64) } stream <- &resource.WrittenEvent{ - WriteEvent: resource.WriteEvent{ - Value: rec.Value, - Key: &resource.ResourceKey{ - Namespace: rec.Key.Namespace, - Group: rec.Key.Group, - Resource: rec.Key.Resource, - Name: rec.Key.Name, - }, - Type: resource.WatchEvent_Type(rec.Action), - PreviousRV: *prevRV, + Value: rec.Value, + Key: &resource.ResourceKey{ + Namespace: rec.Key.Namespace, + Group: rec.Key.Group, + Resource: rec.Key.Resource, + Name: rec.Key.Name, }, + Type: resource.WatchEvent_Type(rec.Action), + PreviousRV: *prevRV, Folder: rec.Folder, ResourceVersion: rec.ResourceVersion, // Timestamp: , // TODO: add timestamp