Chore: Replace entity GRN with infra/grn GRN (#74198)

replace entity GRN with infra/grn GRN
This commit is contained in:
Dan Cech
2023-08-31 15:43:35 -04:00
committed by GitHub
parent 27c4362135
commit 85a207fceb
24 changed files with 983 additions and 843 deletions
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/grafana/grafana/pkg/infra/appcontext"
"github.com/grafana/grafana/pkg/infra/grn"
"github.com/grafana/grafana/pkg/services/playlist"
"github.com/grafana/grafana/pkg/services/sqlstore/session"
"github.com/grafana/grafana/pkg/services/store/entity"
@@ -55,10 +56,10 @@ func (s *entityStoreImpl) sync() {
}
body, _ := json.Marshal(dto)
_, _ = s.store.Write(ctx, &entity.WriteEntityRequest{
GRN: &entity.GRN{
TenantId: info.OrgID,
UID: info.UID,
Kind: entity.StandardKindPlaylist,
GRN: &grn.GRN{
TenantID: info.OrgID,
ResourceIdentifier: info.UID,
ResourceKind: entity.StandardKindPlaylist,
},
Body: body,
})
@@ -73,9 +74,9 @@ func (s *entityStoreImpl) Create(ctx context.Context, cmd *playlist.CreatePlayli
return rsp, fmt.Errorf("unable to write playlist to store")
}
_, err = s.store.Write(ctx, &entity.WriteEntityRequest{
GRN: &entity.GRN{
Kind: entity.StandardKindPlaylist,
UID: rsp.UID,
GRN: &grn.GRN{
ResourceKind: entity.StandardKindPlaylist,
ResourceIdentifier: rsp.UID,
},
Body: body,
})
@@ -94,9 +95,9 @@ func (s *entityStoreImpl) Update(ctx context.Context, cmd *playlist.UpdatePlayli
return rsp, fmt.Errorf("unable to write playlist to store")
}
_, err = s.store.Write(ctx, &entity.WriteEntityRequest{
GRN: &entity.GRN{
UID: rsp.Uid,
Kind: entity.StandardKindPlaylist,
GRN: &grn.GRN{
ResourceIdentifier: rsp.Uid,
ResourceKind: entity.StandardKindPlaylist,
},
Body: body,
})
@@ -111,9 +112,9 @@ func (s *entityStoreImpl) Delete(ctx context.Context, cmd *playlist.DeletePlayli
err := s.sqlimpl.store.Delete(ctx, cmd)
if err == nil {
_, err = s.store.Delete(ctx, &entity.DeleteEntityRequest{
GRN: &entity.GRN{
UID: cmd.UID,
Kind: entity.StandardKindPlaylist,
GRN: &grn.GRN{
ResourceIdentifier: cmd.UID,
ResourceKind: entity.StandardKindPlaylist,
},
})
if err != nil {
@@ -142,9 +143,9 @@ func (s *entityStoreImpl) GetWithoutItems(ctx context.Context, q *playlist.GetPl
func (s *entityStoreImpl) Get(ctx context.Context, q *playlist.GetPlaylistByUidQuery) (*playlist.PlaylistDTO, error) {
rsp, err := s.store.Read(ctx, &entity.ReadEntityRequest{
GRN: &entity.GRN{
UID: q.UID,
Kind: entity.StandardKindPlaylist,
GRN: &grn.GRN{
ResourceIdentifier: q.UID,
ResourceKind: entity.StandardKindPlaylist,
},
WithBody: true,
})
@@ -178,7 +179,7 @@ func (s *entityStoreImpl) Search(ctx context.Context, q *playlist.GetPlaylistsQu
err = json.Unmarshal(res.Body, found)
}
playlists = append(playlists, &playlist.Playlist{
UID: res.GRN.UID,
UID: res.GRN.ResourceIdentifier,
Name: res.Name,
Interval: found.Interval,
})
File diff suppressed because it is too large Load Diff
+13 -24
View File
@@ -1,25 +1,14 @@
syntax = "proto3";
package entity;
option go_package = "./;entity";
option go_package = "github.com/grafana/grafana/pkg/services/store/entity";
message GRN {
// the tenant/org id
int64 tenant_id = 1;
// Identify the entity kind. This kind will be used to apply a schema to the body and
// will trigger additional indexing behavior.
string kind = 3;
// Unique ID
// 40 characters or less, no slashes or other special characters
string UID = 4;
}
import "pkg/infra/grn/grn.proto";
// The canonical entity/document data -- this represents the raw bytes and storage level metadata
message Entity {
// Entity identifier
GRN GRN = 1;
// Entity identifier -- tenant_id, kind, uid
grn.GRN GRN = 1;
// The version will change when the entity is saved. It is not necessarily sortable
string version = 2;
@@ -109,7 +98,7 @@ message EntityVersionInfo {
message ReadEntityRequest {
// Entity identifier
GRN GRN = 1;
grn.GRN GRN = 1;
// Fetch an explicit version
string version = 2;
@@ -139,7 +128,7 @@ message BatchReadEntityResponse {
message WriteEntityRequest {
// Entity identifier
GRN GRN = 1;
grn.GRN GRN = 1;
// Where to save the entity (empty will leave it unchanged)
string folder = 2;
@@ -159,7 +148,7 @@ message WriteEntityRequest {
// This process can bypass the forced checks that
message AdminWriteEntityRequest {
// Entity identifier
GRN GRN = 1;
grn.GRN GRN = 1;
// Where to save the entity (empty will leave it unchanged)
string folder = 2;
@@ -207,7 +196,7 @@ message WriteEntityResponse {
EntityErrorInfo error = 1;
// Entity identifier
GRN GRN = 2;
grn.GRN GRN = 2;
// Entity details with the body removed
EntityVersionInfo entity = 3;
@@ -233,7 +222,7 @@ message WriteEntityResponse {
message DeleteEntityRequest {
// Entity identifier
GRN GRN = 1;
grn.GRN GRN = 1;
// Used for optimistic locking. If missing, the previous version will be replaced regardless
string previous_version = 3;
@@ -249,7 +238,7 @@ message DeleteEntityResponse {
message EntityHistoryRequest {
// Entity identifier
GRN GRN = 1;
grn.GRN GRN = 1;
// Maximum number of items to return
int64 limit = 3;
@@ -260,7 +249,7 @@ message EntityHistoryRequest {
message EntityHistoryResponse {
// Entity identifier
GRN GRN = 1;
grn.GRN GRN = 1;
// Entity metadata without the raw bytes
repeated EntityVersionInfo versions = 2;
@@ -309,7 +298,7 @@ message EntitySearchRequest {
// Search result metadata for each entity
message EntitySearchResult {
// Entity identifier
GRN GRN = 1;
grn.GRN GRN = 1;
// The current version of this entity
string version = 2;
@@ -368,7 +357,7 @@ message EntityWatchRequest {
int64 since = 1;
// Watch sppecific entities
repeated GRN GRN = 2;
repeated grn.GRN GRN = 2;
// limit to a specific kind (empty is all)
repeated string kind = 3;
+51 -37
View File
@@ -1,14 +1,13 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.12
// - protoc-gen-go-grpc v1.3.0
// - protoc v4.23.4
// source: entity.proto
package entity
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
@@ -19,6 +18,17 @@ import (
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
EntityStore_Read_FullMethodName = "/entity.EntityStore/Read"
EntityStore_BatchRead_FullMethodName = "/entity.EntityStore/BatchRead"
EntityStore_Write_FullMethodName = "/entity.EntityStore/Write"
EntityStore_Delete_FullMethodName = "/entity.EntityStore/Delete"
EntityStore_History_FullMethodName = "/entity.EntityStore/History"
EntityStore_Search_FullMethodName = "/entity.EntityStore/Search"
EntityStore_Watch_FullMethodName = "/entity.EntityStore/Watch"
EntityStore_AdminWrite_FullMethodName = "/entity.EntityStore/AdminWrite"
)
// EntityStoreClient is the client API for EntityStore service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
@@ -44,7 +54,7 @@ func NewEntityStoreClient(cc grpc.ClientConnInterface) EntityStoreClient {
func (c *entityStoreClient) Read(ctx context.Context, in *ReadEntityRequest, opts ...grpc.CallOption) (*Entity, error) {
out := new(Entity)
err := c.cc.Invoke(ctx, "/entity.EntityStore/Read", in, out, opts...)
err := c.cc.Invoke(ctx, EntityStore_Read_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@@ -53,7 +63,7 @@ func (c *entityStoreClient) Read(ctx context.Context, in *ReadEntityRequest, opt
func (c *entityStoreClient) BatchRead(ctx context.Context, in *BatchReadEntityRequest, opts ...grpc.CallOption) (*BatchReadEntityResponse, error) {
out := new(BatchReadEntityResponse)
err := c.cc.Invoke(ctx, "/entity.EntityStore/BatchRead", in, out, opts...)
err := c.cc.Invoke(ctx, EntityStore_BatchRead_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@@ -62,7 +72,7 @@ func (c *entityStoreClient) BatchRead(ctx context.Context, in *BatchReadEntityRe
func (c *entityStoreClient) Write(ctx context.Context, in *WriteEntityRequest, opts ...grpc.CallOption) (*WriteEntityResponse, error) {
out := new(WriteEntityResponse)
err := c.cc.Invoke(ctx, "/entity.EntityStore/Write", in, out, opts...)
err := c.cc.Invoke(ctx, EntityStore_Write_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@@ -71,7 +81,7 @@ func (c *entityStoreClient) Write(ctx context.Context, in *WriteEntityRequest, o
func (c *entityStoreClient) Delete(ctx context.Context, in *DeleteEntityRequest, opts ...grpc.CallOption) (*DeleteEntityResponse, error) {
out := new(DeleteEntityResponse)
err := c.cc.Invoke(ctx, "/entity.EntityStore/Delete", in, out, opts...)
err := c.cc.Invoke(ctx, EntityStore_Delete_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@@ -80,7 +90,7 @@ func (c *entityStoreClient) Delete(ctx context.Context, in *DeleteEntityRequest,
func (c *entityStoreClient) History(ctx context.Context, in *EntityHistoryRequest, opts ...grpc.CallOption) (*EntityHistoryResponse, error) {
out := new(EntityHistoryResponse)
err := c.cc.Invoke(ctx, "/entity.EntityStore/History", in, out, opts...)
err := c.cc.Invoke(ctx, EntityStore_History_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@@ -89,7 +99,7 @@ func (c *entityStoreClient) History(ctx context.Context, in *EntityHistoryReques
func (c *entityStoreClient) Search(ctx context.Context, in *EntitySearchRequest, opts ...grpc.CallOption) (*EntitySearchResponse, error) {
out := new(EntitySearchResponse)
err := c.cc.Invoke(ctx, "/entity.EntityStore/Search", in, out, opts...)
err := c.cc.Invoke(ctx, EntityStore_Search_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@@ -97,7 +107,7 @@ func (c *entityStoreClient) Search(ctx context.Context, in *EntitySearchRequest,
}
func (c *entityStoreClient) Watch(ctx context.Context, in *EntityWatchRequest, opts ...grpc.CallOption) (EntityStore_WatchClient, error) {
stream, err := c.cc.NewStream(ctx, &EntityStore_ServiceDesc.Streams[0], "/entity.EntityStore/Watch", opts...)
stream, err := c.cc.NewStream(ctx, &EntityStore_ServiceDesc.Streams[0], EntityStore_Watch_FullMethodName, opts...)
if err != nil {
return nil, err
}
@@ -130,7 +140,7 @@ func (x *entityStoreWatchClient) Recv() (*EntityWatchResponse, error) {
func (c *entityStoreClient) AdminWrite(ctx context.Context, in *AdminWriteEntityRequest, opts ...grpc.CallOption) (*WriteEntityResponse, error) {
out := new(WriteEntityResponse)
err := c.cc.Invoke(ctx, "/entity.EntityStore/AdminWrite", in, out, opts...)
err := c.cc.Invoke(ctx, EntityStore_AdminWrite_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@@ -192,7 +202,7 @@ func RegisterEntityStoreServer(s grpc.ServiceRegistrar, srv EntityStoreServer) {
s.RegisterService(&EntityStore_ServiceDesc, srv)
}
func _EntityStore_Read_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
func _EntityStore_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ReadEntityRequest)
if err := dec(in); err != nil {
return nil, err
@@ -202,15 +212,15 @@ func _EntityStore_Read_Handler(srv any, ctx context.Context, dec func(any) error
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/entity.EntityStore/Read",
FullMethod: EntityStore_Read_FullMethodName,
}
handler := func(ctx context.Context, req any) (any, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EntityStoreServer).Read(ctx, req.(*ReadEntityRequest))
}
return interceptor(ctx, in, info, handler)
}
func _EntityStore_BatchRead_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
func _EntityStore_BatchRead_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(BatchReadEntityRequest)
if err := dec(in); err != nil {
return nil, err
@@ -220,15 +230,15 @@ func _EntityStore_BatchRead_Handler(srv any, ctx context.Context, dec func(any)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/entity.EntityStore/BatchRead",
FullMethod: EntityStore_BatchRead_FullMethodName,
}
handler := func(ctx context.Context, req any) (any, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EntityStoreServer).BatchRead(ctx, req.(*BatchReadEntityRequest))
}
return interceptor(ctx, in, info, handler)
}
func _EntityStore_Write_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
func _EntityStore_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(WriteEntityRequest)
if err := dec(in); err != nil {
return nil, err
@@ -238,15 +248,15 @@ func _EntityStore_Write_Handler(srv any, ctx context.Context, dec func(any) erro
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/entity.EntityStore/Write",
FullMethod: EntityStore_Write_FullMethodName,
}
handler := func(ctx context.Context, req any) (any, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EntityStoreServer).Write(ctx, req.(*WriteEntityRequest))
}
return interceptor(ctx, in, info, handler)
}
func _EntityStore_Delete_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
func _EntityStore_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeleteEntityRequest)
if err := dec(in); err != nil {
return nil, err
@@ -256,15 +266,15 @@ func _EntityStore_Delete_Handler(srv any, ctx context.Context, dec func(any) err
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/entity.EntityStore/Delete",
FullMethod: EntityStore_Delete_FullMethodName,
}
handler := func(ctx context.Context, req any) (any, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EntityStoreServer).Delete(ctx, req.(*DeleteEntityRequest))
}
return interceptor(ctx, in, info, handler)
}
func _EntityStore_History_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
func _EntityStore_History_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(EntityHistoryRequest)
if err := dec(in); err != nil {
return nil, err
@@ -274,15 +284,15 @@ func _EntityStore_History_Handler(srv any, ctx context.Context, dec func(any) er
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/entity.EntityStore/History",
FullMethod: EntityStore_History_FullMethodName,
}
handler := func(ctx context.Context, req any) (any, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EntityStoreServer).History(ctx, req.(*EntityHistoryRequest))
}
return interceptor(ctx, in, info, handler)
}
func _EntityStore_Search_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
func _EntityStore_Search_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(EntitySearchRequest)
if err := dec(in); err != nil {
return nil, err
@@ -292,15 +302,15 @@ func _EntityStore_Search_Handler(srv any, ctx context.Context, dec func(any) err
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/entity.EntityStore/Search",
FullMethod: EntityStore_Search_FullMethodName,
}
handler := func(ctx context.Context, req any) (any, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EntityStoreServer).Search(ctx, req.(*EntitySearchRequest))
}
return interceptor(ctx, in, info, handler)
}
func _EntityStore_Watch_Handler(srv any, stream grpc.ServerStream) error {
func _EntityStore_Watch_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(EntityWatchRequest)
if err := stream.RecvMsg(m); err != nil {
return err
@@ -321,7 +331,7 @@ func (x *entityStoreWatchServer) Send(m *EntityWatchResponse) error {
return x.ServerStream.SendMsg(m)
}
func _EntityStore_AdminWrite_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
func _EntityStore_AdminWrite_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AdminWriteEntityRequest)
if err := dec(in); err != nil {
return nil, err
@@ -331,9 +341,9 @@ func _EntityStore_AdminWrite_Handler(srv any, ctx context.Context, dec func(any)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/entity.EntityStore/AdminWrite",
FullMethod: EntityStore_AdminWrite_FullMethodName,
}
handler := func(ctx context.Context, req any) (any, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EntityStoreServer).AdminWrite(ctx, req.(*AdminWriteEntityRequest))
}
return interceptor(ctx, in, info, handler)
@@ -385,6 +395,10 @@ var EntityStore_ServiceDesc = grpc.ServiceDesc{
Metadata: "entity.proto",
}
const (
EntityStoreAdmin_AdminWrite_FullMethodName = "/entity.EntityStoreAdmin/AdminWrite"
)
// EntityStoreAdminClient is the client API for EntityStoreAdmin service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
@@ -402,7 +416,7 @@ func NewEntityStoreAdminClient(cc grpc.ClientConnInterface) EntityStoreAdminClie
func (c *entityStoreAdminClient) AdminWrite(ctx context.Context, in *AdminWriteEntityRequest, opts ...grpc.CallOption) (*WriteEntityResponse, error) {
out := new(WriteEntityResponse)
err := c.cc.Invoke(ctx, "/entity.EntityStoreAdmin/AdminWrite", in, out, opts...)
err := c.cc.Invoke(ctx, EntityStoreAdmin_AdminWrite_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@@ -435,7 +449,7 @@ func RegisterEntityStoreAdminServer(s grpc.ServiceRegistrar, srv EntityStoreAdmi
s.RegisterService(&EntityStoreAdmin_ServiceDesc, srv)
}
func _EntityStoreAdmin_AdminWrite_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
func _EntityStoreAdmin_AdminWrite_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AdminWriteEntityRequest)
if err := dec(in); err != nil {
return nil, err
@@ -445,9 +459,9 @@ func _EntityStoreAdmin_AdminWrite_Handler(srv any, ctx context.Context, dec func
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/entity.EntityStoreAdmin/AdminWrite",
FullMethod: EntityStoreAdmin_AdminWrite_FullMethodName,
}
handler := func(ctx context.Context, req any) (any, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EntityStoreAdminServer).AdminWrite(ctx, req.(*AdminWriteEntityRequest))
}
return interceptor(ctx, in, info, handler)
+9 -6
View File
@@ -1,11 +1,10 @@
#!/bin/bash
# To compile all protobuf files in this repository, run
# "mage protobuf" at the top-level.
# "make protobuf" at the top-level.
set -eu
#DST_DIR=../genproto/entity
DST_DIR=./
SOURCE="${BASH_SOURCE[0]}"
@@ -14,8 +13,12 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
cd "$DIR"
protoc -I ./ \
protoc \
-I ./ \
-I ../../../../ \
--go_out=${DST_DIR} \
--go-grpc_out=${DST_DIR} --go-grpc_opt=require_unimplemented_servers=false \
entity.proto
--go_opt=paths=source_relative \
--go-grpc_out=${DST_DIR} \
--go-grpc_opt=paths=source_relative \
--go-grpc_opt=require_unimplemented_servers=false \
*.proto
-21
View File
@@ -1,21 +0,0 @@
package entity
import (
"fmt"
)
// Check if the two GRNs reference to the same object
// we can not use simple `*x == *b` because of the internal settings
func (x *GRN) Equals(b *GRN) bool {
if b == nil {
return false
}
return x == b || (x.TenantId == b.TenantId &&
x.Kind == b.Kind &&
x.UID == b.UID)
}
// Set an OID based on the GRN
func (x *GRN) ToGRNString() string {
return fmt.Sprintf("grn:%d/%s/%s", x.TenantId, x.Kind, x.UID)
}
@@ -10,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/api/routing"
"github.com/grafana/grafana/pkg/infra/grn"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/middleware"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
@@ -59,7 +60,7 @@ func (s *httpEntityStore) RegisterHTTPRoutes(route routing.RouteRegister) {
// This function will extract UID+Kind from the requested path "*" in our router
// This is far from ideal! but is at least consistent for these endpoints.
// This will quickly be revisited as we explore how to encode UID+Kind in a "GRN" format
func (s *httpEntityStore) getGRNFromRequest(c *contextmodel.ReqContext) (*entity.GRN, map[string]string, error) {
func (s *httpEntityStore) getGRNFromRequest(c *contextmodel.ReqContext) (*grn.GRN, map[string]string, error) {
params := web.Params(c.Req)
// Read parameters that are encoded in the URL
vals := c.Req.URL.Query()
@@ -68,10 +69,10 @@ func (s *httpEntityStore) getGRNFromRequest(c *contextmodel.ReqContext) (*entity
params[k] = v[0]
}
}
return &entity.GRN{
TenantId: c.OrgID,
Kind: params[":kind"],
UID: params[":uid"],
return &grn.GRN{
TenantID: c.OrgID,
ResourceKind: params[":kind"],
ResourceIdentifier: params[":uid"],
}, params, nil
}
@@ -124,7 +125,7 @@ func (s *httpEntityStore) doGetRawEntity(c *contextmodel.ReqContext) response.Re
if err != nil {
return response.Error(500, "?", err)
}
info, err := s.kinds.GetInfo(grn.Kind)
info, err := s.kinds.GetInfo(grn.ResourceKind)
if err != nil {
return response.Error(400, "Unsupported kind", err)
}
@@ -263,10 +264,10 @@ func (s *httpEntityStore) doUpload(c *contextmodel.ReqContext) response.Response
return response.Error(500, "Internal Server Error", err)
}
grn := &entity.GRN{
UID: uid,
Kind: kind.ID,
TenantId: c.OrgID,
grn := &grn.GRN{
ResourceIdentifier: uid,
ResourceKind: kind.ID,
TenantID: c.OrgID,
}
if !overwriteExistingFile {
+3 -1
View File
@@ -7,6 +7,8 @@ import (
"unsafe"
jsoniter "github.com/json-iterator/go"
"github.com/grafana/grafana/pkg/infra/grn"
)
func init() { //nolint:gochecknoinits
@@ -128,7 +130,7 @@ func readEntity(iter *jsoniter.Iterator, raw *Entity) {
for l1Field := iter.ReadObject(); l1Field != ""; l1Field = iter.ReadObject() {
switch l1Field {
case "GRN":
raw.GRN = &GRN{}
raw.GRN = &grn.GRN{}
iter.ReadVal(raw.GRN)
case "updatedAt":
raw.UpdatedAt = iter.ReadInt64()
+7 -5
View File
@@ -5,6 +5,8 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/infra/grn"
)
func TestRawEncoders(t *testing.T) {
@@ -15,9 +17,9 @@ func TestRawEncoders(t *testing.T) {
require.NoError(t, err)
raw := &Entity{
GRN: &GRN{
UID: "a",
Kind: "b",
GRN: &grn.GRN{
ResourceIdentifier: "a",
ResourceKind: "b",
},
Version: "c",
ETag: "d",
@@ -31,8 +33,8 @@ func TestRawEncoders(t *testing.T) {
require.JSONEq(t, `{
"GRN": {
"kind": "b",
"UID": "a"
"ResourceKind": "b",
"ResourceIdentifier": "a"
},
"version": "c",
"body": {
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"github.com/grafana/grafana/pkg/infra/grn"
"github.com/grafana/grafana/pkg/services/sqlstore/session"
"github.com/grafana/grafana/pkg/services/store/entity"
)
@@ -140,12 +141,12 @@ func setMPTTOrder(folder *folderInfo, stack []*folderInfo, idx int32) (int32, er
func insertFolderInfo(ctx context.Context, tx *session.SessionTx, tenant int64, folder *folderInfo, isDetached bool) error {
js, _ := json.Marshal(folder.stack)
grn := entity.GRN{TenantId: tenant, Kind: entity.StandardKindFolder, UID: folder.UID}
grn2 := grn.GRN{TenantID: tenant, ResourceKind: entity.StandardKindFolder, ResourceIdentifier: folder.UID}
_, err := tx.Exec(ctx,
`INSERT INTO entity_folder `+
"(grn, tenant_id, uid, slug_path, tree, depth, left, right, detached) "+
`VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
grn.ToGRNString(),
grn2.ToGRNString(),
tenant,
folder.UID,
folder.Slug,
@@ -11,6 +11,7 @@ import (
"github.com/grafana/grafana/pkg/infra/appcontext"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/grn"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/slugify"
"github.com/grafana/grafana/pkg/services/grpcserver"
@@ -63,13 +64,13 @@ func getReadSelect(r *entity.ReadEntityRequest) string {
func (s *sqlEntityServer) rowToReadEntityResponse(ctx context.Context, rows *sql.Rows, r *entity.ReadEntityRequest) (*entity.Entity, error) {
raw := &entity.Entity{
GRN: &entity.GRN{},
GRN: &grn.GRN{},
Origin: &entity.EntityOriginInfo{},
}
summaryjson := &summarySupport{}
args := []any{
&raw.GRN.TenantId, &raw.GRN.Kind, &raw.GRN.UID, &raw.Folder,
&raw.GRN.TenantID, &raw.GRN.ResourceKind, &raw.GRN.ResourceIdentifier, &raw.Folder,
&raw.Version, &raw.Size, &raw.ETag, &summaryjson.errors,
&raw.CreatedAt, &raw.CreatedBy,
&raw.UpdatedAt, &raw.UpdatedBy,
@@ -106,7 +107,7 @@ func (s *sqlEntityServer) rowToReadEntityResponse(ctx context.Context, rows *sql
return raw, nil
}
func (s *sqlEntityServer) validateGRN(ctx context.Context, grn *entity.GRN) (*entity.GRN, error) {
func (s *sqlEntityServer) validateGRN(ctx context.Context, grn *grn.GRN) (*grn.GRN, error) {
if grn == nil {
return nil, fmt.Errorf("missing GRN")
}
@@ -114,22 +115,22 @@ func (s *sqlEntityServer) validateGRN(ctx context.Context, grn *entity.GRN) (*en
if err != nil {
return nil, err
}
if grn.TenantId == 0 {
grn.TenantId = user.OrgID
} else if grn.TenantId != user.OrgID {
if grn.TenantID == 0 {
grn.TenantID = user.OrgID
} else if grn.TenantID != user.OrgID {
return nil, fmt.Errorf("tenant ID does not match userID")
}
if grn.Kind == "" {
return nil, fmt.Errorf("GRN missing kind")
if grn.ResourceKind == "" {
return nil, fmt.Errorf("GRN missing ResourceKind")
}
if grn.UID == "" {
return nil, fmt.Errorf("GRN missing UID")
if grn.ResourceIdentifier == "" {
return nil, fmt.Errorf("GRN missing ResourceIdentifier")
}
if len(grn.UID) > 40 {
return nil, fmt.Errorf("GRN UID is too long (>40)")
if len(grn.ResourceIdentifier) > 64 {
return nil, fmt.Errorf("GRN ResourceIdentifier is too long (>64)")
}
if strings.ContainsAny(grn.UID, "/#$@?") {
if strings.ContainsAny(grn.ResourceIdentifier, "/#$@?") {
return nil, fmt.Errorf("invalid character in GRN")
}
return grn, nil
@@ -199,9 +200,9 @@ func (s *sqlEntityServer) readFromHistory(ctx context.Context, r *entity.ReadEnt
// Dynamically create the summary
if r.WithSummary {
builder := s.kinds.GetSummaryBuilder(r.GRN.Kind)
builder := s.kinds.GetSummaryBuilder(r.GRN.ResourceKind)
if builder != nil {
val, out, err := builder(ctx, r.GRN.UID, raw.Body)
val, out, err := builder(ctx, r.GRN.ResourceIdentifier, raw.Body)
if err == nil {
raw.Body = out // cleaned up
raw.SummaryJson, err = json.Marshal(val)
@@ -438,7 +439,7 @@ func (s *sqlEntityServer) AdminWrite(ctx context.Context, r *entity.AdminWriteEn
" ?, ?, ?, "+
" ?, ?, ?, "+
" ?, ?, ?)",
oid, grn.TenantId, grn.Kind, grn.UID, r.Folder,
oid, grn.TenantID, grn.ResourceKind, grn.ResourceIdentifier, r.Folder,
versionInfo.Size, body, etag, versionInfo.Version,
updatedAt, createdBy, createdAt, createdBy,
summary.model.Name, summary.model.Description, summary.model.Slug,
@@ -446,8 +447,8 @@ func (s *sqlEntityServer) AdminWrite(ctx context.Context, r *entity.AdminWriteEn
origin.Source, origin.Key, origin.Time,
)
}
if err == nil && entity.StandardKindFolder == r.GRN.Kind {
err = updateFolderTree(ctx, tx, grn.TenantId)
if err == nil && entity.StandardKindFolder == r.GRN.ResourceKind {
err = updateFolderTree(ctx, tx, grn.TenantID)
}
if err == nil {
summary.folder = r.Folder
@@ -514,7 +515,7 @@ func (s *sqlEntityServer) selectForUpdate(ctx context.Context, tx *session.Sessi
func (s *sqlEntityServer) writeSearchInfo(
ctx context.Context,
tx *session.SessionTx,
grn string,
grn2 string,
summary *summarySupport,
) error {
parent_grn := summary.getParentGRN()
@@ -525,7 +526,7 @@ func (s *sqlEntityServer) writeSearchInfo(
`INSERT INTO entity_labels `+
"(grn, label, value, parent_grn) "+
`VALUES (?, ?, ?, ?)`,
grn, k, v, parent_grn,
grn2, k, v, parent_grn,
)
if err != nil {
return err
@@ -542,7 +543,7 @@ func (s *sqlEntityServer) writeSearchInfo(
"grn, parent_grn, family, type, id, "+
"resolved_ok, resolved_to, resolved_warning, resolved_time) "+
`VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
grn, parent_grn, ref.Family, ref.Type, ref.Identifier,
grn2, parent_grn, ref.Family, ref.Type, ref.Identifier,
resolved.OK, resolved.Key, resolved.Warning, resolved.Timestamp,
)
if err != nil {
@@ -553,10 +554,10 @@ func (s *sqlEntityServer) writeSearchInfo(
// Traverse entities and insert refs
if summary.model.Nested != nil {
for _, childModel := range summary.model.Nested {
grn = (&entity.GRN{
TenantId: summary.parent_grn.TenantId,
Kind: childModel.Kind,
UID: childModel.UID, // append???
grn2 = (&grn.GRN{
TenantID: summary.parent_grn.TenantID,
ResourceKind: childModel.Kind,
ResourceIdentifier: childModel.UID, // append???
}).ToGRNString()
child, err := newSummarySupport(childModel)
@@ -577,17 +578,16 @@ func (s *sqlEntityServer) writeSearchInfo(
" ?, ?, ?, ?,"+
" ?, ?,"+
" ?, ?, ?)",
*parent_grn, grn,
summary.parent_grn.TenantId, childModel.Kind, childModel.UID, summary.folder,
*parent_grn, grn2,
summary.parent_grn.TenantID, childModel.Kind, childModel.UID, summary.folder,
child.name, child.description,
child.labels, child.fields, child.errors,
)
if err != nil {
return err
}
err = s.writeSearchInfo(ctx, tx, grn, child)
err = s.writeSearchInfo(ctx, tx, grn2, child)
if err != nil {
return err
}
@@ -598,13 +598,12 @@ func (s *sqlEntityServer) writeSearchInfo(
}
func (s *sqlEntityServer) prepare(ctx context.Context, r *entity.AdminWriteEntityRequest) (*summarySupport, []byte, error) {
grn := r.GRN
builder := s.kinds.GetSummaryBuilder(grn.Kind)
builder := s.kinds.GetSummaryBuilder(r.GRN.ResourceKind)
if builder == nil {
return nil, nil, fmt.Errorf("unsupported kind")
}
summary, body, err := builder(ctx, grn.UID, r.Body)
summary, body, err := builder(ctx, r.GRN.ResourceIdentifier, r.Body)
if err != nil {
return nil, nil, err
}
@@ -613,7 +612,7 @@ func (s *sqlEntityServer) prepare(ctx context.Context, r *entity.AdminWriteEntit
if summary.Slug == "" {
t := summary.Name
if t == "" {
t = r.GRN.UID
t = r.GRN.ResourceIdentifier
}
summary.Slug = slugify.Slugify(t)
}
@@ -627,21 +626,21 @@ func (s *sqlEntityServer) prepare(ctx context.Context, r *entity.AdminWriteEntit
}
func (s *sqlEntityServer) Delete(ctx context.Context, r *entity.DeleteEntityRequest) (*entity.DeleteEntityResponse, error) {
grn, err := s.validateGRN(ctx, r.GRN)
grn2, err := s.validateGRN(ctx, r.GRN)
if err != nil {
return nil, err
}
rsp := &entity.DeleteEntityResponse{}
err = s.sess.WithTransaction(ctx, func(tx *session.SessionTx) error {
rsp.OK, err = doDelete(ctx, tx, grn)
rsp.OK, err = doDelete(ctx, tx, grn2)
return err
})
return rsp, err
}
func doDelete(ctx context.Context, tx *session.SessionTx, grn *entity.GRN) (bool, error) {
str := grn.ToGRNString()
func doDelete(ctx context.Context, tx *session.SessionTx, grn2 *grn.GRN) (bool, error) {
str := grn2.ToGRNString()
results, err := tx.Exec(ctx, "DELETE FROM entity WHERE grn=?", str)
if err != nil {
return false, err
@@ -669,18 +668,18 @@ func doDelete(ctx context.Context, tx *session.SessionTx, grn *entity.GRN) (bool
return false, err
}
if grn.Kind == entity.StandardKindFolder {
err = updateFolderTree(ctx, tx, grn.TenantId)
if grn2.ResourceKind == entity.StandardKindFolder {
err = updateFolderTree(ctx, tx, grn2.TenantID)
}
return rows > 0, err
}
func (s *sqlEntityServer) History(ctx context.Context, r *entity.EntityHistoryRequest) (*entity.EntityHistoryResponse, error) {
grn, err := s.validateGRN(ctx, r.GRN)
grn2, err := s.validateGRN(ctx, r.GRN)
if err != nil {
return nil, err
}
oid := grn.ToGRNString()
oid := grn2.ToGRNString()
page := ""
args := []any{oid}
@@ -789,12 +788,12 @@ func (s *sqlEntityServer) Search(ctx context.Context, r *entity.EntitySearchRequ
rsp := &entity.EntitySearchResponse{}
for rows.Next() {
result := &entity.EntitySearchResult{
GRN: &entity.GRN{},
GRN: &grn.GRN{},
}
summaryjson := summarySupport{}
args := []any{
&oid, &result.GRN.TenantId, &result.GRN.Kind, &result.GRN.UID,
&oid, &result.GRN.TenantID, &result.GRN.ResourceKind, &result.GRN.ResourceIdentifier,
&result.Version, &result.Folder, &result.Slug, &summaryjson.errors,
&result.Size, &result.UpdatedAt, &result.UpdatedBy,
&result.Name, &summaryjson.description,
@@ -3,6 +3,7 @@ package sqlstash
import (
"encoding/json"
"github.com/grafana/grafana/pkg/infra/grn"
"github.com/grafana/grafana/pkg/services/store/entity"
)
@@ -17,7 +18,7 @@ type summarySupport struct {
marshaled []byte
// metadata for nested objects
parent_grn *entity.GRN
parent_grn *grn.GRN
folder string
isNested bool // set when this is for a nested item
}
@@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"
"github.com/grafana/grafana/pkg/infra/grn"
"github.com/grafana/grafana/pkg/services/store"
"github.com/grafana/grafana/pkg/services/store/entity"
"github.com/grafana/grafana/pkg/util"
@@ -24,7 +25,7 @@ var (
)
type rawEntityMatcher struct {
grn *entity.GRN
grn *grn.GRN
createdRange []time.Time
updatedRange []time.Time
createdBy string
@@ -53,14 +54,14 @@ func requireEntityMatch(t *testing.T, obj *entity.Entity, m rawEntityMatcher) {
mismatches := ""
if m.grn != nil {
if m.grn.TenantId > 0 && m.grn.TenantId != obj.GRN.TenantId {
mismatches += fmt.Sprintf("expected tenant: %d, actual: %d\n", m.grn.TenantId, obj.GRN.TenantId)
if m.grn.TenantID > 0 && m.grn.TenantID != obj.GRN.TenantID {
mismatches += fmt.Sprintf("expected tenant: %d, actual: %d\n", m.grn.TenantID, obj.GRN.TenantID)
}
if m.grn.Kind != "" && m.grn.Kind != obj.GRN.Kind {
mismatches += fmt.Sprintf("expected Kind: %s, actual: %s\n", m.grn.Kind, obj.GRN.Kind)
if m.grn.ResourceKind != "" && m.grn.ResourceKind != obj.GRN.ResourceKind {
mismatches += fmt.Sprintf("expected ResourceKind: %s, actual: %s\n", m.grn.ResourceKind, obj.GRN.ResourceKind)
}
if m.grn.UID != "" && m.grn.UID != obj.GRN.UID {
mismatches += fmt.Sprintf("expected UID: %s, actual: %s\n", m.grn.UID, obj.GRN.UID)
if m.grn.ResourceIdentifier != "" && m.grn.ResourceIdentifier != obj.GRN.ResourceIdentifier {
mismatches += fmt.Sprintf("expected ResourceIdentifier: %s, actual: %s\n", m.grn.ResourceIdentifier, obj.GRN.ResourceIdentifier)
}
}
@@ -134,15 +135,15 @@ func TestIntegrationEntityServer(t *testing.T) {
fakeUser := store.GetUserIDString(testCtx.user)
firstVersion := "1"
kind := entity.StandardKindJSONObj
grn := &entity.GRN{
Kind: kind,
UID: "my-test-entity",
testGrn := &grn.GRN{
ResourceKind: kind,
ResourceIdentifier: "my-test-entity",
}
body := []byte("{\"name\":\"John\"}")
t.Run("should not retrieve non-existent objects", func(t *testing.T) {
resp, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
GRN: grn,
GRN: testGrn,
})
require.NoError(t, err)
@@ -153,7 +154,7 @@ func TestIntegrationEntityServer(t *testing.T) {
t.Run("should be able to read persisted objects", func(t *testing.T) {
before := time.Now()
writeReq := &entity.WriteEntityRequest{
GRN: grn,
GRN: testGrn,
Body: body,
Comment: "first entity!",
}
@@ -169,7 +170,7 @@ func TestIntegrationEntityServer(t *testing.T) {
requireVersionMatch(t, writeResp.Entity, versionMatcher)
readResp, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
GRN: grn,
GRN: testGrn,
Version: "",
WithBody: true,
})
@@ -179,12 +180,12 @@ func TestIntegrationEntityServer(t *testing.T) {
foundGRN := readResp.GRN
require.NotNil(t, foundGRN)
require.Equal(t, testCtx.user.OrgID, foundGRN.TenantId) // orgId becomes the tenant id when not set
require.Equal(t, grn.Kind, foundGRN.Kind)
require.Equal(t, grn.UID, foundGRN.UID)
require.Equal(t, testCtx.user.OrgID, foundGRN.TenantID) // orgId becomes the tenant id when not set
require.Equal(t, testGrn.ResourceKind, foundGRN.ResourceKind)
require.Equal(t, testGrn.ResourceIdentifier, foundGRN.ResourceIdentifier)
objectMatcher := rawEntityMatcher{
grn: grn,
grn: testGrn,
createdRange: []time.Time{before, time.Now()},
updatedRange: []time.Time{before, time.Now()},
createdBy: fakeUser,
@@ -195,14 +196,14 @@ func TestIntegrationEntityServer(t *testing.T) {
requireEntityMatch(t, readResp, objectMatcher)
deleteResp, err := testCtx.client.Delete(ctx, &entity.DeleteEntityRequest{
GRN: grn,
GRN: testGrn,
PreviousVersion: writeResp.Entity.Version,
})
require.NoError(t, err)
require.True(t, deleteResp.OK)
readRespAfterDelete, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
GRN: grn,
GRN: testGrn,
Version: "",
WithBody: true,
})
@@ -212,13 +213,13 @@ func TestIntegrationEntityServer(t *testing.T) {
t.Run("should be able to update an object", func(t *testing.T) {
before := time.Now()
grn := &entity.GRN{
Kind: kind,
UID: util.GenerateShortUID(),
testGrn := &grn.GRN{
ResourceKind: kind,
ResourceIdentifier: util.GenerateShortUID(),
}
writeReq1 := &entity.WriteEntityRequest{
GRN: grn,
GRN: testGrn,
Body: body,
Comment: "first entity!",
}
@@ -229,7 +230,7 @@ func TestIntegrationEntityServer(t *testing.T) {
body2 := []byte("{\"name\":\"John2\"}")
writeReq2 := &entity.WriteEntityRequest{
GRN: grn,
GRN: testGrn,
Body: body2,
Comment: "update1",
}
@@ -247,7 +248,7 @@ func TestIntegrationEntityServer(t *testing.T) {
body3 := []byte("{\"name\":\"John3\"}")
writeReq3 := &entity.WriteEntityRequest{
GRN: grn,
GRN: testGrn,
Body: body3,
Comment: "update3",
}
@@ -256,7 +257,7 @@ func TestIntegrationEntityServer(t *testing.T) {
require.NotEqual(t, writeResp3.Entity.Version, writeResp2.Entity.Version)
latestMatcher := rawEntityMatcher{
grn: grn,
grn: testGrn,
createdRange: []time.Time{before, time.Now()},
updatedRange: []time.Time{before, time.Now()},
createdBy: fakeUser,
@@ -265,7 +266,7 @@ func TestIntegrationEntityServer(t *testing.T) {
version: &writeResp3.Entity.Version,
}
readRespLatest, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
GRN: grn,
GRN: testGrn,
Version: "", // latest
WithBody: true,
})
@@ -274,7 +275,7 @@ func TestIntegrationEntityServer(t *testing.T) {
requireEntityMatch(t, readRespLatest, latestMatcher)
readRespFirstVer, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
GRN: grn,
GRN: testGrn,
Version: writeResp1.Entity.Version,
WithBody: true,
})
@@ -283,7 +284,7 @@ func TestIntegrationEntityServer(t *testing.T) {
require.Nil(t, readRespFirstVer.SummaryJson)
require.NotNil(t, readRespFirstVer)
requireEntityMatch(t, readRespFirstVer, rawEntityMatcher{
grn: grn,
grn: testGrn,
createdRange: []time.Time{before, time.Now()},
updatedRange: []time.Time{before, time.Now()},
createdBy: fakeUser,
@@ -293,7 +294,7 @@ func TestIntegrationEntityServer(t *testing.T) {
})
history, err := testCtx.client.History(ctx, &entity.EntityHistoryRequest{
GRN: grn,
GRN: testGrn,
})
require.NoError(t, err)
require.Equal(t, []*entity.EntityVersionInfo{
@@ -303,7 +304,7 @@ func TestIntegrationEntityServer(t *testing.T) {
}, history.Versions)
deleteResp, err := testCtx.client.Delete(ctx, &entity.DeleteEntityRequest{
GRN: grn,
GRN: testGrn,
PreviousVersion: writeResp3.Entity.Version,
})
require.NoError(t, err)
@@ -316,33 +317,33 @@ func TestIntegrationEntityServer(t *testing.T) {
uid4 := "uid4"
kind2 := entity.StandardKindPlaylist
w1, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
GRN: grn,
GRN: testGrn,
Body: body,
})
require.NoError(t, err)
w2, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
GRN: &entity.GRN{
UID: uid2,
Kind: kind,
GRN: &grn.GRN{
ResourceIdentifier: uid2,
ResourceKind: kind,
},
Body: body,
})
require.NoError(t, err)
w3, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
GRN: &entity.GRN{
UID: uid3,
Kind: kind2,
GRN: &grn.GRN{
ResourceIdentifier: uid3,
ResourceKind: kind2,
},
Body: body,
})
require.NoError(t, err)
w4, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
GRN: &entity.GRN{
UID: uid4,
Kind: kind2,
GRN: &grn.GRN{
ResourceIdentifier: uid4,
ResourceKind: kind2,
},
Body: body,
})
@@ -359,8 +360,8 @@ func TestIntegrationEntityServer(t *testing.T) {
kinds := make([]string, 0, len(search.Results))
version := make([]string, 0, len(search.Results))
for _, res := range search.Results {
uids = append(uids, res.GRN.UID)
kinds = append(kinds, res.GRN.Kind)
uids = append(uids, res.GRN.ResourceIdentifier)
kinds = append(kinds, res.GRN.ResourceKind)
version = append(version, res.Version)
}
require.Equal(t, []string{"my-test-entity", "uid2", "uid3", "uid4"}, uids)
@@ -381,8 +382,8 @@ func TestIntegrationEntityServer(t *testing.T) {
kinds = make([]string, 0, len(searchKind1.Results))
version = make([]string, 0, len(searchKind1.Results))
for _, res := range searchKind1.Results {
uids = append(uids, res.GRN.UID)
kinds = append(kinds, res.GRN.Kind)
uids = append(uids, res.GRN.ResourceIdentifier)
kinds = append(kinds, res.GRN.ResourceKind)
version = append(version, res.Version)
}
require.Equal(t, []string{"my-test-entity", "uid2"}, uids)
@@ -396,18 +397,18 @@ func TestIntegrationEntityServer(t *testing.T) {
t.Run("should be able to filter objects based on their labels", func(t *testing.T) {
kind := entity.StandardKindDashboard
_, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
GRN: &entity.GRN{
Kind: kind,
UID: "blue-green",
GRN: &grn.GRN{
ResourceKind: kind,
ResourceIdentifier: "blue-green",
},
Body: []byte(dashboardWithTagsBlueGreen),
})
require.NoError(t, err)
_, err = testCtx.client.Write(ctx, &entity.WriteEntityRequest{
GRN: &entity.GRN{
Kind: kind,
UID: "red-green",
GRN: &grn.GRN{
ResourceKind: kind,
ResourceIdentifier: "red-green",
},
Body: []byte(dashboardWithTagsRedGreen),
})
@@ -424,7 +425,7 @@ func TestIntegrationEntityServer(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, search)
require.Len(t, search.Results, 1)
require.Equal(t, search.Results[0].GRN.UID, "red-green")
require.Equal(t, search.Results[0].GRN.ResourceIdentifier, "red-green")
search, err = testCtx.client.Search(ctx, &entity.EntitySearchRequest{
Kind: []string{kind},
@@ -438,7 +439,7 @@ func TestIntegrationEntityServer(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, search)
require.Len(t, search.Results, 1)
require.Equal(t, search.Results[0].GRN.UID, "red-green")
require.Equal(t, search.Results[0].GRN.ResourceIdentifier, "red-green")
search, err = testCtx.client.Search(ctx, &entity.EntitySearchRequest{
Kind: []string{kind},