ObjectStore: update dev protobuf definitions (#56428)

pull/55350/head^2
Ryan McKinley 3 years ago committed by GitHub
parent 8300702524
commit b4e23e5d32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      pkg/services/store/object/auth.go
  2. 57
      pkg/services/store/object/dummy/dummy_server.go
  3. 757
      pkg/services/store/object/object.pb.go
  4. 68
      pkg/services/store/object/object.proto
  5. 51
      pkg/services/store/object/tests/server_integration_test.go

@ -2,6 +2,7 @@ package object
import (
"context"
"fmt"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
@ -24,3 +25,14 @@ func UserFromContext(ctx context.Context) *user.SignedInUser {
return c.SignedInUser
}
// Really just spitballing here :) this should hook into a system that can give better display info
func GetUserIDString(user *user.SignedInUser) string {
if user == nil {
return ""
}
if user.IsRealUser() {
return fmt.Sprintf("user:%d:%s", user.UserID, user.Login)
}
return fmt.Sprintf("sys:%d:%s", user.UserID, user.Login)
}

@ -29,7 +29,7 @@ type RawObjectWithHistory struct {
var (
// increment when RawObject changes
rawObjectVersion = 2
rawObjectVersion = 3
)
func ProvideDummyObjectServer(cfg *setting.Cfg, grpcServerProvider grpcserver.Provider) object.ObjectStoreServer {
@ -159,14 +159,11 @@ func (i dummyObjectServer) update(ctx context.Context, r *object.WriteObjectRequ
Created: i.Created,
CreatedBy: i.CreatedBy,
Updated: time.Now().Unix(),
UpdatedBy: &object.UserInfo{
Id: modifier.UserID,
Login: modifier.Login,
},
Size: int64(len(r.Body)),
ETag: createContentsHash(r.Body),
Body: r.Body,
Version: fmt.Sprintf("%d", prevVersion+1),
UpdatedBy: object.GetUserIDString(modifier),
Size: int64(len(r.Body)),
ETag: createContentsHash(r.Body),
Body: r.Body,
Version: fmt.Sprintf("%d", prevVersion+1),
}
versionInfo := &ObjectVersionWithBody{
@ -208,24 +205,18 @@ func (i dummyObjectServer) update(ctx context.Context, r *object.WriteObjectRequ
}
func (i dummyObjectServer) insert(ctx context.Context, r *object.WriteObjectRequest, namespace string) (*object.WriteObjectResponse, error) {
modifier := object.UserFromContext(ctx)
modifier := object.GetUserIDString(object.UserFromContext(ctx))
rawObj := &object.RawObject{
UID: r.UID,
Kind: r.Kind,
Updated: time.Now().Unix(),
Created: time.Now().Unix(),
CreatedBy: &object.UserInfo{
Id: modifier.UserID,
Login: modifier.Login,
},
UpdatedBy: &object.UserInfo{
Id: modifier.UserID,
Login: modifier.Login,
},
Size: int64(len(r.Body)),
ETag: createContentsHash(r.Body),
Body: r.Body,
Version: fmt.Sprintf("%d", 1),
UID: r.UID,
Kind: r.Kind,
Updated: time.Now().Unix(),
Created: time.Now().Unix(),
CreatedBy: modifier,
UpdatedBy: modifier,
Size: int64(len(r.Body)),
ETag: createContentsHash(r.Body),
Body: r.Body,
Version: fmt.Sprintf("%d", 1),
}
info := &object.ObjectVersionInfo{
@ -338,12 +329,20 @@ func (i dummyObjectServer) Search(ctx context.Context, r *object.ObjectSearchReq
return nil, err
}
rawObjects := make([]*object.RawObject, 0)
searchResults := make([]*object.ObjectSearchResult, 0)
for _, o := range objects {
rawObjects = append(rawObjects, o.RawObject)
searchResults = append(searchResults, &object.ObjectSearchResult{
UID: o.UID,
Kind: o.Kind,
Version: o.Version,
Updated: o.Updated,
UpdatedBy: o.UpdatedBy,
Name: "? name from summary",
Body: o.Body,
})
}
return &object.ObjectSearchResponse{
Results: rawObjects,
Results: searchResults,
}, nil
}

File diff suppressed because it is too large Load Diff

@ -3,15 +3,6 @@ package object;
option go_package = "./;object";
// Will be replaced with something from the SDK
message UserInfo {
// internal grafana user ID
int64 id = 1;
// login name
string login = 2; // string ID?
}
// The canonical object/document data -- this represents the raw bytes and storage level metadata
message RawObject {
// Unique ID
@ -28,10 +19,10 @@ message RawObject {
int64 updated = 4;
// Who created the object
UserInfo created_by = 5;
string created_by = 5;
// Who updated the object
UserInfo updated_by = 6;
string updated_by = 6;
// Content Length
int64 size = 7;
@ -80,7 +71,7 @@ message ObjectVersionInfo {
int64 updated = 2;
// Who updated the object
UserInfo updated_by = 3;
string updated_by = 3;
// Content Length
int64 size = 4;
@ -250,16 +241,59 @@ message ObjectSearchRequest {
// Sorting instructions `field ASC/DESC`
repeated string sort = 7;
// TODO, limit the set of fields we actually want returned
// Only supported in the QueryResponse flavor?
repeated string fields = 8;
// Return the full body in each payload
bool with_body = 8;
// Return the full body in each payload
bool with_body = 9;
bool with_labels = 9;
// Return the full body in each payload
bool with_fields = 10;
}
// Search result metadata for each object
message ObjectSearchResult {
// Unique ID
string UID = 1;
// Identify the object kind. This kind will be used to apply a schema to the body and
// will trigger additional indexing behavior.
string kind = 2;
// The current veresion of this object
string version = 3;
// Time in epoch milliseconds that the object was updated
int64 updated = 4;
// Who updated the object
string updated_by = 5;
// Optionally include the full object body
bytes body = 6;
//----------------------------------------
// Derived from body in the summary
//----------------------------------------
// Always included
string name = 7;
// Always included
string description = 8;
// The structured labels
map<string,string> labels = 9;
// Optionally include extracted JSON
string fields_json = 10;
// ObjectErrorInfo in json
string error_json = 11;
}
message ObjectSearchResponse {
repeated RawObject results = 1;
repeated ObjectSearchResult results = 1;
// More results exist... pass this in the next request
string next_page_token = 2;

@ -6,7 +6,6 @@ import (
"encoding/hex"
"fmt"
"reflect"
"strings"
"testing"
"time"
@ -25,38 +24,20 @@ type rawObjectMatcher struct {
kind *string
createdRange []time.Time
updatedRange []time.Time
createdBy *object.UserInfo
updatedBy *object.UserInfo
createdBy string
updatedBy string
body []byte
version *string
}
type objectVersionMatcher struct {
updatedRange []time.Time
updatedBy *object.UserInfo
updatedBy string
version *string
etag *string
comment *string
}
func userInfoMatches(expected *object.UserInfo, actual *object.UserInfo) (bool, string) {
var mismatches []string
if actual == nil && expected != nil {
return true, "Missing user info"
}
if expected.Id != actual.Id {
mismatches = append(mismatches, fmt.Sprintf("expected ID %d, actual ID: %d", expected.Id, actual.Id))
}
if expected.Login != actual.Login {
mismatches = append(mismatches, fmt.Sprintf("expected login %s, actual login: %s", expected.Login, actual.Login))
}
return len(mismatches) == 0, strings.Join(mismatches, ", ")
}
func timestampInRange(ts int64, tsRange []time.Time) bool {
return ts >= tsRange[0].Unix() && ts <= tsRange[1].Unix()
}
@ -82,18 +63,12 @@ func requireObjectMatch(t *testing.T, obj *object.RawObject, m rawObjectMatcher)
mismatches += fmt.Sprintf("expected updatedRange range: [from %s to %s], actual updated: %s\n", m.updatedRange[0], m.updatedRange[1], time.Unix(obj.Updated, 0))
}
if m.createdBy != nil {
userInfoMatches, msg := userInfoMatches(m.createdBy, obj.CreatedBy)
if !userInfoMatches {
mismatches += fmt.Sprintf("createdBy: %s\n", msg)
}
if m.createdBy != "" && m.createdBy != obj.CreatedBy {
mismatches += fmt.Sprintf("createdBy: expected:%s, found:%s\n", m.createdBy, obj.CreatedBy)
}
if m.updatedBy != nil {
userInfoMatches, msg := userInfoMatches(m.updatedBy, obj.UpdatedBy)
if !userInfoMatches {
mismatches += fmt.Sprintf("updatedBy: %s\n", msg)
}
if m.updatedBy != "" && m.updatedBy != obj.UpdatedBy {
mismatches += fmt.Sprintf("updatedBy: expected:%s, found:%s\n", m.updatedBy, obj.UpdatedBy)
}
if !reflect.DeepEqual(m.body, obj.Body) {
@ -125,11 +100,8 @@ func requireVersionMatch(t *testing.T, obj *object.ObjectVersionInfo, m objectVe
mismatches += fmt.Sprintf("expected updatedRange range: [from %s to %s], actual updated: %s\n", m.updatedRange[0], m.updatedRange[1], time.Unix(obj.Updated, 0))
}
if m.updatedBy != nil {
userInfoMatches, msg := userInfoMatches(m.updatedBy, obj.UpdatedBy)
if !userInfoMatches {
mismatches += fmt.Sprintf("updatedBy: %s\n", msg)
}
if m.updatedBy != "" && m.updatedBy != obj.UpdatedBy {
mismatches += fmt.Sprintf("updatedBy: expected:%s, found:%s\n", m.updatedBy, obj.UpdatedBy)
}
if m.version != nil && *m.version != obj.Version {
@ -148,10 +120,7 @@ func TestObjectServer(t *testing.T) {
testCtx := createTestContext(t)
ctx = metadata.AppendToOutgoingContext(ctx, "authorization", fmt.Sprintf("Bearer %s", testCtx.authToken))
fakeUser := &object.UserInfo{
Login: testCtx.user.Login,
Id: testCtx.user.UserID,
}
fakeUser := fmt.Sprintf("user:%d:%s", testCtx.user.UserID, testCtx.user.Login)
firstVersion := "1"
kind := "dashboard"
uid := "my-test-entity"

Loading…
Cancel
Save