diff --git a/client/client.go b/client/client.go deleted file mode 100644 index 1f71857a182e96683795632c30c31f2bc74ea529..0000000000000000000000000000000000000000 --- a/client/client.go +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2016 DGraph Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package client - -import ( - "github.com/Sirupsen/logrus" - "github.com/dgraph-io/dgraph/query/pb" - "github.com/dgraph-io/dgraph/x" -) - -var glog = x.Log("client") - -type Entity struct { - Attribute string - gr *pb.GraphResponse // Reference to iteratively build the entity - uid uint64 - children []*Entity -} - -// This function performs a binary search on the uids slice and returns the -// index at which it finds the uid, else returns -1 -func indexOf(uid uint64, uids []uint64) int { - low, mid, high := 0, 0, len(uids)-1 - for low <= high { - mid = (low + high) / 2 - if uids[mid] == uid { - return mid - } else if uids[mid] > uid { - high = mid - 1 - } else { - low = mid + 1 - } - } - return -1 -} - -// This method is used to initialize the root entity -func NewEntity(root *pb.GraphResponse) *Entity { - e := new(Entity) - e.Attribute = root.Attribute - e.uid = root.Result.Uidmatrix[0].Uids[0] - e.gr = root - return e -} - -// This method returns the list of properties for an entity. -func (e *Entity) Properties() []string { - m := []string{} - if e.gr == nil { - glog.WithField("attribute", e.Attribute).Fatal("Nil graphResponse") - return m - } - - for _, predChild := range e.gr.Children { - // Skipping non-leaf nodes. - if len(predChild.Children) > 0 { - continue - } - m = append(m, predChild.Attribute) - } - return m -} - -// This method returns whether a property exists for an entity or not. -func (e *Entity) HasValue(property string) bool { - for _, predChild := range e.gr.Children { - if len(predChild.Children) > 0 { - continue - } - if predChild.Attribute == property { - return true - } - } - return false -} - -// This method returns the value corresponding to a property if one exists. -func (e *Entity) Value(property string) []byte { - for _, predChild := range e.gr.Children { - if predChild.Attribute == property { - idx := indexOf(e.uid, predChild.Query.Uids) - if idx == -1 { - glog.WithFields(logrus.Fields{ - "uid": e.uid, - "attribute": e.Attribute, - "childAttribute": predChild.Attribute, - }).Fatal("Attribute with uid not found in child Query uids") - return []byte{} - } - return predChild.Result.Values[idx] - } - } - return []byte{} -} - -// This method creates the children for an entity and returns them. -func (e *Entity) Children() []*Entity { - var children []*Entity - // If length of children is zero, that means children have not been created - // yet or no Child nodes exist - if len(e.children) > 0 { - return e.children - } - if e.gr == nil { - glog.WithField("attribute", e.Attribute).Fatal("Nil graphResponse") - return children - } - for _, predChild := range e.gr.Children { - // Index of the uid of the parent node in the query uids of the child. - // This is used to get the appropriate uidList for the child - idx := indexOf(e.uid, predChild.Query.Uids) - if idx == -1 { - glog.WithFields(logrus.Fields{ - "uid": e.uid, - "attribute": e.Attribute, - "childAttribute": predChild.Attribute, - }).Fatal("Attribute with uid not found in child Query uids") - return children - } - if len(predChild.Children) != 0 { - // Creating a child for each entry in the uidList - for _, uid := range predChild.Result.Uidmatrix[idx].Uids { - cEntity := new(Entity) - cEntity.gr = predChild - cEntity.Attribute = predChild.Attribute - cEntity.uid = uid - children = append(children, cEntity) - } - } - } - e.children = children - return children -} - -// This method returns the number of children for an entity. -func (e *Entity) NumChildren() int { - return len(e.Children()) -} diff --git a/client/client_test.go b/client/client_test.go deleted file mode 100644 index bae4ed01dc4bcfaff3b05a0ad6a092bbf34dec46..0000000000000000000000000000000000000000 --- a/client/client_test.go +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright 2016 DGraph Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package client - -import ( - "io/ioutil" - "os" - "testing" - "time" - - "github.com/dgraph-io/dgraph/commit" - "github.com/dgraph-io/dgraph/gql" - "github.com/dgraph-io/dgraph/posting" - "github.com/dgraph-io/dgraph/query" - "github.com/dgraph-io/dgraph/store" - "github.com/dgraph-io/dgraph/worker" - "github.com/dgraph-io/dgraph/x" -) - -func addEdge(t *testing.T, edge x.DirectedEdge, l *posting.List) { - if err := l.AddMutation(edge, posting.Set); err != nil { - t.Error(err) - } -} - -func populateGraph(t *testing.T) (string, *store.Store) { - // logrus.SetLevel(logrus.DebugLevel) - dir, err := ioutil.TempDir("", "storetest_") - if err != nil { - t.Error(err) - return "", nil - } - - ps := new(store.Store) - ps.Init(dir) - - worker.Init(ps, nil, 0, 1) - - clog := commit.NewLogger(dir, "mutations", 50<<20) - clog.Init() - posting.Init(clog) - - // So, user we're interested in has uid: 1. - // She has 4 friends: 23, 24, 25, 31, and 101 - edge := x.DirectedEdge{ - ValueId: 23, - Source: "testing", - Timestamp: time.Now(), - } - addEdge(t, edge, posting.GetOrCreate(posting.Key(1, "friend"), ps)) - - edge.ValueId = 24 - addEdge(t, edge, posting.GetOrCreate(posting.Key(1, "friend"), ps)) - - edge.ValueId = 25 - addEdge(t, edge, posting.GetOrCreate(posting.Key(1, "friend"), ps)) - - edge.ValueId = 31 - addEdge(t, edge, posting.GetOrCreate(posting.Key(1, "friend"), ps)) - - edge.ValueId = 101 - addEdge(t, edge, posting.GetOrCreate(posting.Key(1, "friend"), ps)) - - // Now let's add a few properties for the main user. - edge.Value = "Michonne" - addEdge(t, edge, posting.GetOrCreate(posting.Key(1, "name"), ps)) - - edge.Value = "female" - addEdge(t, edge, posting.GetOrCreate(posting.Key(1, "gender"), ps)) - - edge.Value = "alive" - addEdge(t, edge, posting.GetOrCreate(posting.Key(1, "status"), ps)) - - // Now let's add a name for each of the friends, except 101. - edge.Value = "Rick Grimes" - addEdge(t, edge, posting.GetOrCreate(posting.Key(23, "name"), ps)) - - edge.Value = "Glenn Rhee" - addEdge(t, edge, posting.GetOrCreate(posting.Key(24, "name"), ps)) - - edge.Value = "Daryl Dixon" - addEdge(t, edge, posting.GetOrCreate(posting.Key(25, "name"), ps)) - - edge.Value = "Andrea" - addEdge(t, edge, posting.GetOrCreate(posting.Key(31, "name"), ps)) - - return dir, ps -} - -func TestQuery(t *testing.T) { - dir, _ := populateGraph(t) - defer os.RemoveAll(dir) - - q0 := ` - { - me(_uid_:0x01) { - name - gender - status - friend { - name - } - } - } - ` - - // Parse GQL into internal query representation. - gq, _, err := gql.Parse(q0) - if err != nil { - t.Error(err) - return - } - g, err := query.ToSubGraph(gq) - if err != nil { - t.Error(err) - return - } - - ch := make(chan error) - go query.ProcessGraph(g, ch) - if err := <-ch; err != nil { - t.Error(err) - return - } - resp, err := g.PreTraverse() - if err != nil { - t.Error(err) - return - } - - root := NewEntity(resp) - - if root.Attribute != "_root_" { - t.Errorf("Expected attribute _root_, Got: %v", root.Attribute) - } - if len(root.Properties()) != 3 { - t.Errorf("Expected 3 properties for entity, Got: %v", - len(root.Properties())) - } - if root.Properties()[0] != "name" { - t.Errorf("Expected first property to be name, Got: %v", - root.Properties()[0]) - } - if !root.HasValue("name") { - t.Errorf("Expected entity to have value for name, Got: false") - } - if root.HasValue("names") { - t.Errorf("Expected entity to not have value for names, Got: true") - } - if string(root.Value("name")) != "Michonne" { - t.Errorf("Expected value for name to be Michonne, Got: %v", - string(root.Value("name"))) - } - if len(root.Value("names")) != 0 { - t.Errorf("Expected values for names to return empty byte slice, Got: len", - len(root.Value("names"))) - } - if root.NumChildren() != 5 { - t.Errorf("Expected entity to have 5 children, Got: %v", root.NumChildren()) - } - - child := root.Children()[0] - if !child.HasValue("name") { - t.Errorf("Expected entity to have value for name, Got: false") - } - if child.HasValue("gender") { - t.Errorf("Expected entity to not have value for gender, Got: true") - } - if child.NumChildren() != 0 { - t.Errorf("Expected entity to have zero children, Got: %v", - child.NumChildren()) - } - if string(child.Value("name")) != "Rick Grimes" { - t.Errorf("Expected child to have name value Rick Grimes, Got: ", - string(child.Value("name"))) - } - child = root.Children()[1] - if string(child.Value("name")) != "Glenn Rhee" { - t.Errorf("Expected child to have name value Glenn Rhee, Got: ", - string(child.Value("name"))) - } - child = root.Children()[2] - if string(child.Value("name")) != "Daryl Dixon" { - t.Errorf("Expected child to have name value Daryl Dixon, Got: ", - string(child.Value("name"))) - } - child = root.Children()[3] - if string(child.Value("name")) != "Andrea" { - t.Errorf("Expected child to have name value Andrea, Got: ", - string(child.Value("name"))) - } - child = root.Children()[4] - if string(child.Value("name")) != "" { - t.Errorf("Expected child to have name empty name value, Got: ", - string(child.Value("name"))) - } -} diff --git a/query/pb/graphresponse.pb.go b/query/pb/graphresponse.pb.go index 2fd972a71b0eac8ffc8b8f4081bc82d4f4722c92..b76e1525c2c6b0d9a93a238d7061c57495e269c7 100644 --- a/query/pb/graphresponse.pb.go +++ b/query/pb/graphresponse.pb.go @@ -10,6 +10,7 @@ It is generated from these files: It has these top-level messages: GraphRequest + Value GraphResponse */ package pb @@ -41,18 +42,27 @@ func (m *GraphRequest) String() string { return proto.CompactTextStri func (*GraphRequest) ProtoMessage() {} func (*GraphRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } +type Value struct { + Byte []byte `protobuf:"bytes,1,opt,name=byte,proto3" json:"byte,omitempty"` +} + +func (m *Value) Reset() { *m = Value{} } +func (m *Value) String() string { return proto.CompactTextString(m) } +func (*Value) ProtoMessage() {} +func (*Value) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + type GraphResponse struct { Attribute string `protobuf:"bytes,1,opt,name=attribute" json:"attribute,omitempty"` - Values map[string][]byte `protobuf:"bytes,2,rep,name=values" json:"values,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value,proto3"` + Values map[string]*Value `protobuf:"bytes,2,rep,name=values" json:"values,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` Children []*GraphResponse `protobuf:"bytes,3,rep,name=children" json:"children,omitempty"` } func (m *GraphResponse) Reset() { *m = GraphResponse{} } func (m *GraphResponse) String() string { return proto.CompactTextString(m) } func (*GraphResponse) ProtoMessage() {} -func (*GraphResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } +func (*GraphResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } -func (m *GraphResponse) GetValues() map[string][]byte { +func (m *GraphResponse) GetValues() map[string]*Value { if m != nil { return m.Values } @@ -68,6 +78,7 @@ func (m *GraphResponse) GetChildren() []*GraphResponse { func init() { proto.RegisterType((*GraphRequest)(nil), "pb.GraphRequest") + proto.RegisterType((*Value)(nil), "pb.Value") proto.RegisterType((*GraphResponse)(nil), "pb.GraphResponse") } @@ -143,20 +154,21 @@ var _DGraph_serviceDesc = grpc.ServiceDesc{ } var fileDescriptor0 = []byte{ - // 227 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0x2f, 0x4a, 0x2c, - 0xc8, 0x28, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, - 0x62, 0x2a, 0x48, 0x52, 0x52, 0xe1, 0xe2, 0x71, 0x07, 0x49, 0x05, 0xa5, 0x16, 0x96, 0xa6, 0x16, - 0x97, 0x08, 0x89, 0x70, 0xb1, 0x02, 0x19, 0x45, 0x95, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, - 0x10, 0x8e, 0xd2, 0x39, 0x46, 0x2e, 0x5e, 0xa8, 0x32, 0x88, 0x09, 0x42, 0x32, 0x5c, 0x9c, 0x89, - 0x25, 0x25, 0x45, 0x99, 0x49, 0xa5, 0x25, 0xa9, 0x50, 0xb5, 0x08, 0x01, 0x21, 0x53, 0x2e, 0xb6, - 0xb2, 0xc4, 0x1c, 0xa0, 0x81, 0x12, 0x4c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0xb2, 0x7a, 0x05, 0x49, - 0x7a, 0x28, 0x06, 0xe8, 0x85, 0x81, 0xe5, 0x5d, 0xf3, 0x4a, 0x8a, 0x2a, 0x83, 0xa0, 0x8a, 0x85, - 0x74, 0xb9, 0x38, 0x92, 0x33, 0x32, 0x73, 0x52, 0x8a, 0x52, 0xf3, 0x24, 0x98, 0xc1, 0x1a, 0x05, - 0x31, 0x34, 0x06, 0xc1, 0x95, 0x48, 0x59, 0x72, 0x71, 0x23, 0x99, 0x22, 0x24, 0xc0, 0xc5, 0x9c, - 0x9d, 0x0a, 0x73, 0x38, 0x88, 0x09, 0xf2, 0x0c, 0xd8, 0x64, 0xa0, 0x2b, 0x18, 0x35, 0x78, 0x82, - 0x20, 0x1c, 0x2b, 0x26, 0x0b, 0x46, 0x23, 0x0b, 0x2e, 0x36, 0x17, 0xb0, 0xb1, 0x42, 0x7a, 0x5c, - 0xac, 0x81, 0x20, 0x3f, 0x0a, 0x09, 0x20, 0x59, 0x05, 0x0e, 0x0b, 0x29, 0x4c, 0xcb, 0x95, 0x18, - 0x92, 0xd8, 0xc0, 0x61, 0x67, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x30, 0x75, 0x05, 0xc3, 0x52, - 0x01, 0x00, 0x00, + // 253 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x64, 0x90, 0x31, 0x4f, 0xc3, 0x30, + 0x10, 0x85, 0x71, 0x42, 0x22, 0x72, 0x2d, 0x52, 0x39, 0x18, 0xa2, 0x02, 0xa2, 0x8a, 0x18, 0xba, + 0xe0, 0xa1, 0x08, 0xa9, 0x62, 0x2e, 0x62, 0xc6, 0x03, 0x7b, 0x0c, 0x27, 0x5a, 0x51, 0x25, 0xc6, + 0x76, 0x90, 0xf2, 0x53, 0xf9, 0x37, 0xc4, 0x97, 0x00, 0x45, 0xdd, 0xce, 0x77, 0xf7, 0xbe, 0x77, + 0x7e, 0x70, 0xfa, 0x66, 0x4b, 0xb3, 0xb6, 0xe4, 0x4c, 0x5d, 0x39, 0x92, 0xc6, 0xd6, 0xbe, 0xc6, + 0xc8, 0xe8, 0xe2, 0x1a, 0xc6, 0x8f, 0x61, 0xa4, 0xe8, 0xa3, 0x21, 0xe7, 0xf1, 0x0c, 0x92, 0xae, + 0xb0, 0x6d, 0x2e, 0x66, 0x62, 0x9e, 0xa9, 0xfe, 0x51, 0x9c, 0x43, 0xf2, 0x5c, 0x6e, 0x1b, 0x42, + 0x84, 0x43, 0xdd, 0x7a, 0xe2, 0xe9, 0x58, 0x71, 0x5d, 0x7c, 0x09, 0x38, 0x1e, 0x18, 0x3d, 0x1e, + 0x2f, 0x20, 0x2b, 0xbd, 0xb7, 0x1b, 0xdd, 0x0c, 0xab, 0x99, 0xfa, 0x6b, 0xe0, 0x1d, 0xa4, 0x9f, + 0x01, 0xe6, 0xf2, 0x68, 0x16, 0xcf, 0x47, 0x8b, 0x4b, 0x69, 0xb4, 0xfc, 0x07, 0x90, 0x6c, 0xe6, + 0x1e, 0x2a, 0x6f, 0x5b, 0x35, 0x2c, 0xe3, 0x0d, 0x1c, 0xbd, 0xac, 0x37, 0xdb, 0x57, 0x4b, 0x55, + 0x1e, 0xb3, 0xf0, 0x64, 0x4f, 0xa8, 0x7e, 0x57, 0xa6, 0x2b, 0x18, 0xed, 0x50, 0x70, 0x02, 0xf1, + 0x3b, 0xfd, 0xfc, 0x2a, 0x94, 0x78, 0x05, 0x09, 0x93, 0xbb, 0x2b, 0x44, 0x07, 0xcb, 0x02, 0x8c, + 0x15, 0xaa, 0xef, 0xdf, 0x47, 0x4b, 0xb1, 0x58, 0x42, 0xba, 0x62, 0x07, 0x94, 0x90, 0x3c, 0x85, + 0x2c, 0x70, 0xb2, 0xe3, 0xca, 0x99, 0x4d, 0xf7, 0xef, 0x28, 0x0e, 0x74, 0xca, 0x19, 0xdf, 0x7e, + 0x07, 0x00, 0x00, 0xff, 0xff, 0xfb, 0x05, 0xc8, 0x3f, 0x7a, 0x01, 0x00, 0x00, } diff --git a/query/pb/graphresponse.proto b/query/pb/graphresponse.proto index 532e60c2d3fa9e6c590574c9b8a70cf4615e652d..e85286e2dc3c7b75e1dbb470080e1c1f7876968c 100644 --- a/query/pb/graphresponse.proto +++ b/query/pb/graphresponse.proto @@ -12,8 +12,12 @@ message GraphRequest { string query = 1; } +message Value { + bytes byte = 1; +} + message GraphResponse { string attribute = 1; - map<string, bytes> values = 2; + map<string, Value> values = 2; repeated GraphResponse children = 3; // Each node can have multiple children } diff --git a/query/query.go b/query/query.go index ba2713437505944e2ae72bc5e99d1cfd5c8a2aa4..35a410a9b5d46083c1b021a17cc74bcf823ab8d3 100644 --- a/query/query.go +++ b/query/query.go @@ -89,10 +89,11 @@ import ( var glog = x.Log("query") type Latency struct { - Start time.Time `json:"-"` - Parsing time.Duration `json:"query_parsing"` - Processing time.Duration `json:"processing"` - Json time.Duration `json:"json_conversion"` + Start time.Time `json:"-"` + Parsing time.Duration `json:"query_parsing"` + Processing time.Duration `json:"processing"` + Json time.Duration `json:"json_conversion"` + ProtocolBuffer time.Duration `json:"pb_conversion"` } func (l *Latency) ToMap() map[string]string { @@ -310,7 +311,8 @@ type sgreference struct { // This method converts a subgraph to a protocol buffer response. It transforms // the predicate based subgraph to an entity based protocol buffer subgraph. -func (g *SubGraph) ToProtocolBuffer() (gr *pb.GraphResponse, rerr error) { +func (g *SubGraph) ToProtocolBuffer(l *Latency) (gr *pb.GraphResponse, + rerr error) { gr = &pb.GraphResponse{} gr.Attribute = g.Attr @@ -341,6 +343,8 @@ func (g *SubGraph) ToProtocolBuffer() (gr *pb.GraphResponse, rerr error) { x.Err(glog, rerr).Error("Error while traversal") return gr, rerr } + l.ProtocolBuffer = time.Since(l.Start) - l.Parsing - l.Processing + return gr, nil } @@ -362,9 +366,9 @@ func indexOf(uid uint64, uids []uint64) int { } // This method gets the values and children for a GraphResponse. -func (re *sgreference) pretraverse() (map[string][]byte, +func (re *sgreference) pretraverse() (map[string]*pb.Value, []*pb.GraphResponse, error) { - vals := make(map[string][]byte) + vals := make(map[string]*pb.Value) var children []*pb.GraphResponse for _, child := range re.sg.Children { @@ -383,9 +387,19 @@ func (re *sgreference) pretraverse() (map[string][]byte, } idx := indexOf(re.uid, query) + if idx == -1 { + glog.WithFields(logrus.Fields{ + "uid": re.uid, + "attribute": re.sg.Attr, + "childAttribute": child.Attr, + }).Fatal("Attribute with uid not found in child Query uids") + return vals, children, fmt.Errorf("Attribute with uid not found") + } if len(child.Children) == 0 { - vals[child.Attr] = result.values[idx] + val := new(pb.Value) + val.Byte = result.values[idx] + vals[child.Attr] = val } else { uids := result.uidmatrix[idx] // We create as many predicate children as the number of uids. diff --git a/query/query_test.go b/query/query_test.go index b25b63f5af5b2e3c3f360036b88b297fc1ca826f..2e2396d983b6e19e45ae552544c2761abdb4c9f8 100644 --- a/query/query_test.go +++ b/query/query_test.go @@ -353,7 +353,8 @@ func TestToProtocolBuffer(t *testing.T) { t.Error(err) } - gr, err := sg.ToProtocolBuffer() + var l Latency + gr, err := sg.ToProtocolBuffer(&l) if err != nil { t.Error(err) } @@ -365,9 +366,9 @@ func TestToProtocolBuffer(t *testing.T) { t.Errorf("Expected values map to contain 3 properties, Got: %v", len(gr.Values)) } - if string(gr.Values["name"]) != "Michonne" { + if string(gr.Values["name"].Byte) != "Michonne" { t.Errorf("Expected property name to have value Michonne, Got: %v", - string(gr.Values["name"])) + string(gr.Values["name"].Byte)) } if len(gr.Children) != 5 { t.Errorf("Expected 5 children, Got: %v", len(gr.Children)) @@ -381,9 +382,9 @@ func TestToProtocolBuffer(t *testing.T) { t.Errorf("Expected values map to contain 1 property, Got: %v", len(child.Values)) } - if string(child.Values["name"]) != "Rick Grimes" { + if string(child.Values["name"].Byte) != "Rick Grimes" { t.Errorf("Expected property name to have value Rick Grimes, Got: %v", - string(child.Values["name"])) + string(child.Values["name"].Byte)) } if len(child.Children) != 0 { t.Errorf("Expected 0 children, Got: %v", len(child.Children)) diff --git a/server/main.go b/server/main.go index 332d41e14d5a0dfa5faeb788e7853becc8ed8673..0bd9712beecd025a731467afaf4d768bac358568 100644 --- a/server/main.go +++ b/server/main.go @@ -216,6 +216,8 @@ func (s *server) Query(ctx context.Context, return resp, fmt.Errorf("Empty query") } + var l query.Latency + l.Start = time.Now() // TODO(pawan): Refactor query parsing and graph processing code to a common // function used by Query and queryHandler glog.WithField("q", req.Query).Debug("Query received.") @@ -230,6 +232,7 @@ func (s *server) Query(ctx context.Context, x.Err(glog, err).Error("While conversion to internal format") return resp, err } + l.Parsing = time.Since(l.Start) glog.WithField("q", req.Query).Debug("Query parsed.") rch := make(chan error) @@ -239,9 +242,10 @@ func (s *server) Query(ctx context.Context, x.Err(glog, err).Error("While executing query") return resp, err } - + l.Processing = time.Since(l.Start) - l.Parsing glog.WithField("q", req.Query).Debug("Graph processed.") - resp, err = sg.ToProtocolBuffer() + + resp, err = sg.ToProtocolBuffer(&l) if err != nil { x.Err(glog, err).Error("While converting to protocol buffer.") return resp, err