Skip to content

Commit

Permalink
resolved review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaji-kharse committed Oct 28, 2024
1 parent 12913dd commit 941afc0
Show file tree
Hide file tree
Showing 11 changed files with 1,192 additions and 1,121 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/golang/geo v0.0.0-20230421003525-6adc56603217
github.com/golang/glog v1.2.2
github.com/golang/protobuf v1.5.4
github.com/golang/snappy v0.0.4
github.com/google/codesearch v1.2.0
github.com/google/go-cmp v0.6.0
Expand Down Expand Up @@ -98,7 +99,6 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions graphql/admin/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func resolveRestore(ctx context.Context, m schema.Mutation) (*resolve.Resolved,
func restore(ctx context.Context, m schema.Mutation, req pb.RestoreRequest) (*resolve.Resolved, bool) {
wg := &sync.WaitGroup{}
if err := worker.ProcessRestoreRequest(context.Background(), &req, wg); err != nil {
pb.Redact(req.ProtoReflect().Interface())
glog.Warningf("error processing restore request: %+v, err: %v", req, err)

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

Sensitive data returned by an access to SecretKey
flows to a logging call.
Sensitive data returned by an access to SecretKey
flows to a logging call.
Sensitive data returned by an access to SecretKey
flows to a logging call.
return resolve.DataResult(
m,
Expand Down
100 changes: 25 additions & 75 deletions graphql/admin/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,25 @@ import (
)

type membershipState struct {
Counter uint64 `json:"counter"`
Groups []clusterGroup `json:"groups"`
Zeros []member `json:"zeros"`
MaxUID uint64 `json:"maxUID"`
MaxNsID uint64 `json:"maxNsID"`
MaxTxnTs uint64 `json:"maxTxnTs"`
MaxRaftId uint64 `json:"maxRaftId"`
Removed []*pb.Member `json:"removed"`
Cid string `json:"cid"`
License *pb.License `json:"license"`
Namespaces []uint64 `json:"namespaces"`
Counter uint64 `json:"counter,omitempty"`
Groups []clusterGroup `json:"groups,omitempty"`
Zeros []*pb.Member `json:"zeros,omitempty"`
MaxUID uint64 `json:"maxUID,omitempty"`
MaxNsID uint64 `json:"maxNsID,omitempty"`
MaxTxnTs uint64 `json:"maxTxnTs,omitempty"`
MaxRaftId uint64 `json:"maxRaftId,omitempty"`
Removed []*pb.Member `json:"removed,omitempty"`
Cid string `json:"cid,omitempty"`
License *pb.License `json:"license,omitempty"`
Namespaces []uint64 `json:"namespaces,omitempty"`
}

type clusterGroup struct {
Id uint32 `json:"id"`
Members []member `json:"members"`
Tablets []tablet `json:"tablets"`
SnapshotTs uint64 `json:"snapshotTs"`
Checksum uint64 `json:"checksum"`
}

type member struct {
Id uint64 `json:"id"`
GroupId uint32 `json:"groupId"`
Addr string `json:"addr"`
Leader bool `json:"leader"`
AmDead bool `json:"amDead"`
LastUpdate uint64 `json:"lastUpdate"`
ClusterInfoOnly bool `json:"clusterInfoOnly"`
Learner bool `json:"learner"`
ForceGroupId bool `json:"forceGroupId"`
}

type tablet struct {
GroupId uint32 `json:"groupId"`
Predicate string `json:"predicate"`
Force bool `json:"force"`
OnDiskBytes int64 `json:"onDiskBytes"`
Remove bool `json:"remove"`
ReadOnly bool `json:"readOnly"`
MoveTs uint64 `json:"moveTs"`
UncompressedBytes int64 `json:"uncompressedBytes"`
Id uint32 `json:"id,omitempty"`
Members []*pb.Member `json:"members,omitempty"`
Tablets []*pb.Tablet `json:"tablets,omitempty"`
SnapshotTs uint64 `json:"snapshotTs,omitempty"`
Checksum uint64 `json:"checksum,omitempty"`
}

func resolveState(ctx context.Context, q schema.Query) *resolve.Resolved {
Expand All @@ -74,7 +51,7 @@ func resolveState(ctx context.Context, q schema.Query) *resolve.Resolved {

ns, _ := x.ExtractNamespace(ctx)
// map to graphql response structure. Only guardian of galaxy can list the namespaces.
state := convertToGraphQLResp(&ms, ns == x.GalaxyNamespace)
state := convertToGraphQLResp(ms, ns == x.GalaxyNamespace)
b, err := json.Marshal(state)
if err != nil {
return resolve.EmptyResult(q, err)
Expand All @@ -98,39 +75,21 @@ func resolveState(ctx context.Context, q schema.Query) *resolve.Resolved {
// values and not the keys. For pb.MembershipState.Group, the keys are the group IDs
// and pb.Group didn't contain this ID, so we are creating a custom clusterGroup type,
// which is same as pb.Group and also contains the ID for the group.
func convertToGraphQLResp(ms *pb.MembershipState, listNs bool) membershipState {
func convertToGraphQLResp(ms pb.MembershipState, listNs bool) membershipState {
var state membershipState

// namespaces stores set of namespaces
namespaces := make(map[uint64]struct{})

state.Counter = ms.Counter
for k, v := range ms.Groups {
var members = make([]member, 0, len(v.Members))
for id, v1 := range v.Members {
members = append(members, member{
Id: id,
GroupId: v1.GroupId,
Addr: v1.Addr,
Leader: v1.Leader,
AmDead: v1.AmDead,
LastUpdate: v1.LastUpdate,
ClusterInfoOnly: v1.ClusterInfoOnly,
ForceGroupId: v1.ForceGroupId,
})
var members = make([]*pb.Member, 0, len(v.Members))
for _, v1 := range v.Members {
members = append(members, v1)
}
var tablets = make([]tablet, 0, len(v.Tablets))
var tablets = make([]*pb.Tablet, 0, len(v.Tablets))
for name, v1 := range v.Tablets {
tablets = append(tablets, tablet{
GroupId: v1.GroupId,
Predicate: v1.Predicate,
Force: v1.Force,
OnDiskBytes: v1.OnDiskBytes,
Remove: v1.Remove,
ReadOnly: v1.ReadOnly,
MoveTs: v1.MoveTs,
UncompressedBytes: v1.UncompressedBytes,
})
tablets = append(tablets, v1)
if listNs {
namespaces[x.ParseNamespace(name)] = struct{}{}
}
Expand All @@ -143,18 +102,9 @@ func convertToGraphQLResp(ms *pb.MembershipState, listNs bool) membershipState {
Checksum: v.Checksum,
})
}
state.Zeros = make([]member, 0, len(ms.Zeros))
state.Zeros = make([]*pb.Member, 0, len(ms.Zeros))
for _, v := range ms.Zeros {
state.Zeros = append(state.Zeros, member{
Id: v.Id,
GroupId: v.GroupId,
Addr: v.Addr,
Leader: v.Leader,
AmDead: v.AmDead,
LastUpdate: v.LastUpdate,
ClusterInfoOnly: v.ClusterInfoOnly,
ForceGroupId: v.ForceGroupId,
})
state.Zeros = append(state.Zeros, v)
}
state.MaxUID = ms.MaxUID
state.MaxTxnTs = ms.MaxTxnTs
Expand Down
66 changes: 21 additions & 45 deletions graphql/e2e/common/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,43 +448,20 @@ func adminState(t *testing.T) {
gqlResponse := queryParams.ExecuteAsPost(t, GraphqlAdminURL)
RequireNoGQLErrors(t, gqlResponse)

type Member struct {
Id uint64 `json:"id"`
GroupId uint32 `json:"groupId"`
Addr string `json:"addr"`
Leader bool `json:"leader"`
AmDead bool `json:"amDead"`
LastUpdate uint64 `json:"lastUpdate"`
ClusterInfoOnly bool `json:"clusterInfoOnly"`
Learner bool `json:"learner"`
ForceGroupId bool `json:"forceGroupId"`
}

type Tablet struct {
GroupId uint32 `json:"groupId"`
Predicate string `json:"predicate"`
Force bool `json:"force"`
OnDiskBytes int64 `json:"onDiskBytes"`
Remove bool `json:"remove"`
ReadOnly bool `json:"readOnly"`
MoveTs uint64 `json:"moveTs"`
UncompressedBytes int64 `json:"uncompressedBytes"`
}

var result struct {
State struct {
Groups []struct {
Id uint32
Members []Member
Tablets []Tablet
Members []*pb.Member
Tablets []*pb.Tablet
SnapshotTs uint64
}
Zeros []Member
Zeros []*pb.Member
MaxUID uint64
MaxTxnTs uint64
MaxNsID uint64
MaxRaftId uint64
Removed []Member
Removed []*pb.Member
Cid string
License struct {
User string
Expand All @@ -495,7 +472,22 @@ func adminState(t *testing.T) {
}
}

validateMember := func(expected *pb.Member, actual Member) {
err := json.Unmarshal(gqlResponse.Data, &result)
require.NoError(t, err)

var state pb.MembershipState
resp, err := http.Get(dgraphStateURL)
require.NoError(t, err)
defer func() {
if err := resp.Body.Close(); err != nil {
glog.Warningf("error closing body: %v", err)
}
}()
stateRes, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, protojson.Unmarshal(stateRes, &state))

validateMember := func(expected *pb.Member, actual *pb.Member) {
require.Equal(t, expected.Id, actual.Id)
require.Equal(t, expected.GroupId, actual.GroupId)
require.Equal(t, expected.Addr, actual.Addr)
Expand All @@ -504,10 +496,9 @@ func adminState(t *testing.T) {
require.Equal(t, expected.LastUpdate, actual.LastUpdate)
require.Equal(t, expected.ClusterInfoOnly, actual.ClusterInfoOnly)
require.Equal(t, expected.ForceGroupId, actual.ForceGroupId)
require.Equal(t, expected.Learner, actual.Learner)
}

validateTablet := func(expected *pb.Tablet, actual Tablet) {
validateTablet := func(expected *pb.Tablet, actual *pb.Tablet) {
require.Equal(t, expected.GroupId, actual.GroupId)
require.Equal(t, expected.Predicate, actual.Predicate)
require.Equal(t, expected.Force, actual.Force)
Expand All @@ -518,21 +509,6 @@ func adminState(t *testing.T) {
require.Equal(t, expected.UncompressedBytes, actual.UncompressedBytes)
}

err := json.Unmarshal(gqlResponse.Data, &result)
require.NoError(t, err)

var state pb.MembershipState
resp, err := http.Get(dgraphStateURL)
require.NoError(t, err)
defer func() {
if err := resp.Body.Close(); err != nil {
glog.Warningf("error closing body: %v", err)
}
}()
stateRes, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, protojson.Unmarshal(stateRes, &state))

for _, group := range result.State.Groups {
require.Contains(t, state.Groups, group.Id)
expectedGroup := state.Groups[group.Id]
Expand Down
28 changes: 17 additions & 11 deletions protos/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ package pb;

import "github.com/dgraph-io/dgo/v240/protos/api.proto";
import "github.com/dgraph-io/badger/v4/pb/pb.proto";
import "google/protobuf/descriptor.proto";


option go_package = "./pb";

extend google.protobuf.FieldOptions {
bool dataSensitive = 50010;
}

message List {
repeated fixed64 uids = 1;
}
Expand Down Expand Up @@ -122,15 +128,15 @@ message RaftContext {
// have one RAFT node per server serving that group.
message Member {
fixed64 id = 1;
uint32 group_id = 2 ;
uint32 groupId = 2 ;
string addr = 3;
bool leader = 4;
bool am_dead = 5 ;
uint64 last_update = 6 ;
bool amDead = 5 ;
uint64 lastUpdate = 6 ;
bool learner = 7;

bool cluster_info_only = 13;
bool force_group_id = 14 ;
bool clusterInfoOnly = 13;
bool forceGroupId = 14 ;
}

message Group {
Expand Down Expand Up @@ -205,14 +211,14 @@ message HealthInfo {
}

message Tablet {
uint32 group_id = 1;
uint32 groupId = 1;
string predicate = 2;
bool force = 3; // Used while moving predicate.
int64 on_disk_bytes = 7;
int64 OnDiskBytes = 7;
bool remove = 8;
bool read_only = 9;
bool ReadOnly = 9;
uint64 move_ts = 10 ;
int64 uncompressed_bytes =
int64 UncompressedBytes =
11; // Estimated uncompressed size of tablet in bytes
}

Expand Down Expand Up @@ -294,8 +300,8 @@ message RestoreRequest {
string backup_id = 4;

// Credentials when using a minio or S3 bucket as the backup location.
string access_key = 5;
string secret_key = 6;
string access_key = 5 [(dataSensitive) = true];
string secret_key = 6 [(dataSensitive) = true];
string session_token = 7;
bool anonymous = 8;

Expand Down
Loading

0 comments on commit 941afc0

Please sign in to comment.