From 69f0e9dd0c5f6513e95706f68f631ce4d87e82e5 Mon Sep 17 00:00:00 2001
From: Pawan Rawal <pawan0201@gmail.com>
Date: Wed, 11 May 2016 11:33:08 +0530
Subject: [PATCH] Adding Latency to protocol buffer response.

---
 client/go/main.go               |  4 +-
 query/graph/graphresponse.pb.go | 89 ++++++++++++++++++++++++---------
 query/graph/graphresponse.proto | 13 ++++-
 server/main.go                  | 13 +++--
 4 files changed, 90 insertions(+), 29 deletions(-)

diff --git a/client/go/main.go b/client/go/main.go
index 3912bb9d..d824a893 100644
--- a/client/go/main.go
+++ b/client/go/main.go
@@ -42,12 +42,12 @@ func main() {
 
 	c := graph.NewDGraphClient(conn)
 
-	r, err := c.Query(context.Background(), &graph.Request{Query: *q})
+	resp, err := c.Query(context.Background(), &graph.Request{Query: *q})
 	if err != nil {
 		x.Err(glog, err).Fatal("Error in getting response from server")
 	}
 
 	// TODO(pawan): Remove this later
-	fmt.Printf("Subgraph %+v", r)
+	fmt.Printf("Subgraph %+v", resp.N)
 
 }
diff --git a/query/graph/graphresponse.pb.go b/query/graph/graphresponse.pb.go
index fefbbb2b..14a86faa 100644
--- a/query/graph/graphresponse.pb.go
+++ b/query/graph/graphresponse.pb.go
@@ -11,7 +11,9 @@ It is generated from these files:
 It has these top-level messages:
 	Request
 	Value
+	Latency
 	Node
+	Response
 */
 package graph
 
@@ -51,6 +53,17 @@ func (m *Value) String() string            { return proto.CompactTextString(m) }
 func (*Value) ProtoMessage()               {}
 func (*Value) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
 
+type Latency struct {
+	Parsing    string `protobuf:"bytes,1,opt,name=parsing" json:"parsing,omitempty"`
+	Processing string `protobuf:"bytes,2,opt,name=processing" json:"processing,omitempty"`
+	Pb         string `protobuf:"bytes,3,opt,name=pb" json:"pb,omitempty"`
+}
+
+func (m *Latency) Reset()                    { *m = Latency{} }
+func (m *Latency) String() string            { return proto.CompactTextString(m) }
+func (*Latency) ProtoMessage()               {}
+func (*Latency) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
+
 type Node struct {
 	Uid        uint64            `protobuf:"varint,1,opt,name=uid" json:"uid,omitempty"`
 	Xid        string            `protobuf:"bytes,2,opt,name=xid" json:"xid,omitempty"`
@@ -62,7 +75,7 @@ type Node struct {
 func (m *Node) Reset()                    { *m = Node{} }
 func (m *Node) String() string            { return proto.CompactTextString(m) }
 func (*Node) ProtoMessage()               {}
-func (*Node) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
+func (*Node) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
 
 func (m *Node) GetProperties() map[string]*Value {
 	if m != nil {
@@ -78,10 +91,36 @@ func (m *Node) GetChildren() []*Node {
 	return nil
 }
 
+type Response struct {
+	N *Node    `protobuf:"bytes,1,opt,name=n" json:"n,omitempty"`
+	L *Latency `protobuf:"bytes,2,opt,name=l" json:"l,omitempty"`
+}
+
+func (m *Response) Reset()                    { *m = Response{} }
+func (m *Response) String() string            { return proto.CompactTextString(m) }
+func (*Response) ProtoMessage()               {}
+func (*Response) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
+
+func (m *Response) GetN() *Node {
+	if m != nil {
+		return m.N
+	}
+	return nil
+}
+
+func (m *Response) GetL() *Latency {
+	if m != nil {
+		return m.L
+	}
+	return nil
+}
+
 func init() {
 	proto.RegisterType((*Request)(nil), "graph.Request")
 	proto.RegisterType((*Value)(nil), "graph.Value")
+	proto.RegisterType((*Latency)(nil), "graph.Latency")
 	proto.RegisterType((*Node)(nil), "graph.Node")
+	proto.RegisterType((*Response)(nil), "graph.Response")
 }
 
 // Reference imports to suppress errors if they are not otherwise used.
@@ -95,7 +134,7 @@ const _ = grpc.SupportPackageIsVersion2
 // Client API for DGraph service
 
 type DGraphClient interface {
-	Query(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Node, error)
+	Query(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
 }
 
 type dGraphClient struct {
@@ -106,8 +145,8 @@ func NewDGraphClient(cc *grpc.ClientConn) DGraphClient {
 	return &dGraphClient{cc}
 }
 
-func (c *dGraphClient) Query(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Node, error) {
-	out := new(Node)
+func (c *dGraphClient) Query(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
+	out := new(Response)
 	err := grpc.Invoke(ctx, "/graph.DGraph/Query", in, out, c.cc, opts...)
 	if err != nil {
 		return nil, err
@@ -118,7 +157,7 @@ func (c *dGraphClient) Query(ctx context.Context, in *Request, opts ...grpc.Call
 // Server API for DGraph service
 
 type DGraphServer interface {
-	Query(context.Context, *Request) (*Node, error)
+	Query(context.Context, *Request) (*Response, error)
 }
 
 func RegisterDGraphServer(s *grpc.Server, srv DGraphServer) {
@@ -156,22 +195,26 @@ var _DGraph_serviceDesc = grpc.ServiceDesc{
 }
 
 var fileDescriptor0 = []byte{
-	// 268 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x5c, 0x90, 0x41, 0x4f, 0x83, 0x40,
-	0x10, 0x85, 0xa5, 0xb0, 0xd5, 0x0e, 0x46, 0xcd, 0xea, 0x01, 0xab, 0x89, 0xcd, 0x1e, 0xb4, 0x27,
-	0x62, 0xf0, 0x62, 0xf4, 0xaa, 0xf1, 0x60, 0x62, 0x74, 0x0f, 0xde, 0xa9, 0x4c, 0x2c, 0xb1, 0x01,
-	0xdc, 0x5d, 0x8c, 0xfd, 0xed, 0x5e, 0x64, 0x06, 0x44, 0xd2, 0xdb, 0xe3, 0x7d, 0xb3, 0xc3, 0x9b,
-	0x07, 0x87, 0xef, 0x26, 0xad, 0x96, 0x06, 0x6d, 0x55, 0x16, 0x16, 0xe3, 0xca, 0x94, 0xae, 0x94,
-	0x82, 0x4d, 0x75, 0x06, 0xdb, 0x1a, 0x3f, 0x6b, 0xb4, 0x4e, 0x1e, 0x81, 0x68, 0x84, 0x59, 0x47,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xea, 0x64, 0x5a, 0x58, 0xe9, 0x3d, 0xfe, 0x09, 0xbc,
+	0xa5, 0xe8, 0x5c, 0x6a, 0x9b, 0x48, 0x13, 0x36, 0x46, 0xf5, 0x71, 0x77, 0x72, 0x1c, 0xd1, 0xbb,
+	0x23, 0x17, 0x11, 0xbd, 0x6e, 0xd4, 0x07, 0x65, 0xf5, 0x4a, 0x6c, 0xb5, 0xe3, 0x39, 0xb4, 0x67,
+	0xcb, 0x24, 0x9d, 0x6b, 0xa9, 0xc2, 0x80, 0x8e, 0x76, 0xb7, 0x8e, 0x8a, 0x8d, 0x38, 0x7c, 0x82,
+	0xfe, 0x8e, 0x8f, 0xbb, 0xe8, 0xa7, 0x5c, 0xcf, 0xd1, 0x41, 0xe4, 0x10, 0x7c, 0xbb, 0x29, 0xd2,
+	0xe5, 0xbb, 0x93, 0x7d, 0x6f, 0x45, 0x93, 0x15, 0x95, 0x74, 0x53, 0xbb, 0x66, 0xfc, 0x0e, 0xda,
+	0xc2, 0xef, 0x09, 0x07, 0xc0, 0x14, 0x79, 0xec, 0x44, 0x33, 0x55, 0xbe, 0x9b, 0xa5, 0xde, 0xaa,
+	0xe7, 0x25, 0xbf, 0x09, 0xc1, 0xd2, 0xc9, 0x15, 0x34, 0xef, 0x1f, 0x1d, 0x89, 0x17, 0x10, 0xbc,
+	0xb9, 0x2d, 0xe2, 0xba, 0xcb, 0xef, 0x7a, 0xd8, 0xdf, 0xd4, 0x55, 0x18, 0xdf, 0x9b, 0x36, 0xe9,
+	0x5f, 0x5c, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0xeb, 0x75, 0x69, 0x89, 0x2e, 0x02, 0x00, 0x00,
 }
diff --git a/query/graph/graphresponse.proto b/query/graph/graphresponse.proto
index 81545972..9c1086d8 100644
--- a/query/graph/graphresponse.proto
+++ b/query/graph/graphresponse.proto
@@ -5,7 +5,7 @@ syntax="proto3";
 package graph;
 
 service DGraph {
-  rpc Query (Request) returns (Node) {}
+  rpc Query (Request) returns (Response) {}
 }
 
 message Request {
@@ -16,6 +16,12 @@ message Value {
   string str = 1;
 }
 
+message Latency {
+  string parsing = 1;
+  string processing = 2;
+  string pb = 3;
+}
+
 message Node {
   uint64 uid = 1;
   string xid = 2;
@@ -23,3 +29,8 @@ message Node {
   map<string, Value> properties = 4;
   repeated Node children = 5; // Each node can have multiple children
 }
+
+message Response {
+  Node n = 1;
+  Latency l = 2;
+}
diff --git a/server/main.go b/server/main.go
index 1cea3b82..ea606ee0 100644
--- a/server/main.go
+++ b/server/main.go
@@ -209,8 +209,10 @@ type server struct{}
 // This method is used to execute the query and return the response to the
 // client as a protocol buffer message.
 func (s *server) Query(ctx context.Context,
-	req *graph.Request) (*graph.Node, error) {
-	resp := new(graph.Node)
+	req *graph.Request) (*graph.Response, error) {
+	node := new(graph.Node)
+	gl := new(graph.Latency)
+	resp := new(graph.Response)
 	if len(req.Query) == 0 {
 		glog.Error("While reading query")
 		return resp, fmt.Errorf("Empty query")
@@ -245,11 +247,16 @@ func (s *server) Query(ctx context.Context,
 	l.Processing = time.Since(l.Start) - l.Parsing
 	glog.WithField("q", req.Query).Debug("Graph processed.")
 
-	resp, err = sg.ToProtocolBuffer(&l)
+	node, err = sg.ToProtocolBuffer(&l)
 	if err != nil {
 		x.Err(glog, err).Error("While converting to protocol buffer.")
 		return resp, err
 	}
+	resp.N = node
+
+	gl.Parsing, gl.Processing, gl.Pb = l.Parsing.String(), l.Processing.String(),
+		l.ProtocolBuffer.String()
+	resp.L = gl
 
 	return resp, err
 }
-- 
GitLab