Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(933)

Side by Side Diff: appengine/tsmon/grpc.go

Issue 2123853002: Added unit annotation supports onto tsmon in go. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Specify the unit of logdog/collector/subscription/processing_time_ms with types.Milliseconds Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/tsmon/global_callback_test.go ('k') | appengine/tsmon/middleware_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package tsmon 5 package tsmon
6 6
7 import ( 7 import (
8 "time" 8 "time"
9 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
11 "google.golang.org/grpc" 11 "google.golang.org/grpc"
12 12
13 "github.com/luci/luci-go/common/clock" 13 "github.com/luci/luci-go/common/clock"
14 "github.com/luci/luci-go/common/tsmon/distribution" 14 "github.com/luci/luci-go/common/tsmon/distribution"
15 "github.com/luci/luci-go/common/tsmon/field" 15 "github.com/luci/luci-go/common/tsmon/field"
16 "github.com/luci/luci-go/common/tsmon/metric" 16 "github.com/luci/luci-go/common/tsmon/metric"
17 "github.com/luci/luci-go/common/tsmon/types"
17 ) 18 )
18 19
19 var ( 20 var (
20 grpcServerCount = metric.NewCounter( 21 grpcServerCount = metric.NewCounter(
21 "grpc/server/count", 22 "grpc/server/count",
22 "Total number of RPCs.", 23 "Total number of RPCs.",
24 types.MetricMetadata{},
23 field.String("method"), // full name of the grpc method 25 field.String("method"), // full name of the grpc method
24 field.Int("code")) // grpc.Code of the result 26 field.Int("code")) // grpc.Code of the result
25 27
26 grpcServerDuration = metric.NewCumulativeDistribution( 28 grpcServerDuration = metric.NewCumulativeDistribution(
27 "grpc/server/duration", 29 "grpc/server/duration",
28 "Distribution of server-side RPC duration (in milliseconds).", 30 "Distribution of server-side RPC duration (in milliseconds).",
31 types.MetricMetadata{},
29 distribution.DefaultBucketer, 32 distribution.DefaultBucketer,
30 field.String("method"), // full name of the grpc method 33 field.String("method"), // full name of the grpc method
31 field.Int("code")) // grpc.Code of the result 34 field.Int("code")) // grpc.Code of the result
32 ) 35 )
33 36
34 // NewGrpcUnaryInterceptor returns an interceptor that gathers RPC handler 37 // NewGrpcUnaryInterceptor returns an interceptor that gathers RPC handler
35 // metrics and sends them to tsmon. 38 // metrics and sends them to tsmon.
36 // 39 //
37 // It can be optionally chained with other interceptor. The reported metrics 40 // It can be optionally chained with other interceptor. The reported metrics
38 // include time spent in this other interceptor too. 41 // include time spent in this other interceptor too.
(...skipping 15 matching lines...) Expand all
54 57
55 // reportRPCMetrics sends metrics after RPC handler has finished. 58 // reportRPCMetrics sends metrics after RPC handler has finished.
56 func reportRPCMetrics(ctx context.Context, method string, err error, dur time.Du ration) { 59 func reportRPCMetrics(ctx context.Context, method string, err error, dur time.Du ration) {
57 code := 0 60 code := 0
58 if err != nil { 61 if err != nil {
59 code = int(grpc.Code(err)) 62 code = int(grpc.Code(err))
60 } 63 }
61 grpcServerCount.Add(ctx, 1, method, code) 64 grpcServerCount.Add(ctx, 1, method, code)
62 grpcServerDuration.Add(ctx, float64(dur.Nanoseconds()/1000000), method, code) 65 grpcServerDuration.Add(ctx, float64(dur.Nanoseconds()/1000000), method, code)
63 } 66 }
OLDNEW
« no previous file with comments | « appengine/tsmon/global_callback_test.go ('k') | appengine/tsmon/middleware_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698