stats: add BeginTime to stats.End (#1907)

This commit is contained in:
Brian Tiger Chow
2018-03-12 16:16:36 +00:00
committed by dfawley
parent 3a9e1bab62
commit 2c2d834e8e
4 changed files with 26 additions and 10 deletions

View File

@ -205,11 +205,13 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
}
ctx = newContextWithRPCInfo(ctx, c.failFast)
sh := cc.dopts.copts.StatsHandler
var beginTime time.Time
if sh != nil {
ctx = sh.TagRPC(ctx, &stats.RPCTagInfo{FullMethodName: method, FailFast: c.failFast})
beginTime = time.Now()
begin := &stats.Begin{
Client: true,
BeginTime: time.Now(),
BeginTime: beginTime,
FailFast: c.failFast,
}
sh.HandleRPC(ctx, begin)
@ -217,8 +219,10 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
if err != nil {
// Only handle end stats if err != nil.
end := &stats.End{
Client: true,
Error: err,
Client: true,
Error: err,
BeginTime: beginTime,
EndTime: time.Now(),
}
sh.HandleRPC(ctx, end)
}
@ -283,6 +287,7 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
statsCtx: ctx,
statsHandler: cc.dopts.copts.StatsHandler,
beginTime: beginTime,
}
if desc != unaryStreamDesc {
// Listen on cc and stream contexts to cleanup when the user closes the
@ -337,6 +342,7 @@ type clientStream struct {
// so that all the generated stats for a particular RPC can be associated in the processing phase.
statsCtx context.Context
statsHandler stats.Handler
beginTime time.Time
}
func (cs *clientStream) Context() context.Context {
@ -512,9 +518,10 @@ func (cs *clientStream) finish(err error) {
}
if cs.statsHandler != nil {
end := &stats.End{
Client: true,
EndTime: time.Now(),
Error: err,
Client: true,
BeginTime: cs.beginTime,
EndTime: time.Now(),
Error: err,
}
cs.statsHandler.HandleRPC(cs.statsCtx, end)
}