Code refactoring for bpa operator
[icn.git] / cmd / bpa-operator / vendor / go.opencensus.io / plugin / ocgrpc / server_metrics.go
1 // Copyright 2017, OpenCensus Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15
16 package ocgrpc
17
18 import (
19         "go.opencensus.io/stats"
20         "go.opencensus.io/stats/view"
21         "go.opencensus.io/tag"
22 )
23
24 // The following variables are measures are recorded by ServerHandler:
25 var (
26         ServerReceivedMessagesPerRPC = stats.Int64("grpc.io/server/received_messages_per_rpc", "Number of messages received in each RPC. Has value 1 for non-streaming RPCs.", stats.UnitDimensionless)
27         ServerReceivedBytesPerRPC    = stats.Int64("grpc.io/server/received_bytes_per_rpc", "Total bytes received across all messages per RPC.", stats.UnitBytes)
28         ServerSentMessagesPerRPC     = stats.Int64("grpc.io/server/sent_messages_per_rpc", "Number of messages sent in each RPC. Has value 1 for non-streaming RPCs.", stats.UnitDimensionless)
29         ServerSentBytesPerRPC        = stats.Int64("grpc.io/server/sent_bytes_per_rpc", "Total bytes sent in across all response messages per RPC.", stats.UnitBytes)
30         ServerLatency                = stats.Float64("grpc.io/server/server_latency", "Time between first byte of request received to last byte of response sent, or terminal error.", stats.UnitMilliseconds)
31 )
32
33 // TODO(acetechnologist): This is temporary and will need to be replaced by a
34 // mechanism to load these defaults from a common repository/config shared by
35 // all supported languages. Likely a serialized protobuf of these defaults.
36
37 // Predefined views may be registered to collect data for the above measures.
38 // As always, you may also define your own custom views over measures collected by this
39 // package. These are declared as a convenience only; none are registered by
40 // default.
41 var (
42         ServerReceivedBytesPerRPCView = &view.View{
43                 Name:        "grpc.io/server/received_bytes_per_rpc",
44                 Description: "Distribution of received bytes per RPC, by method.",
45                 Measure:     ServerReceivedBytesPerRPC,
46                 TagKeys:     []tag.Key{KeyServerMethod},
47                 Aggregation: DefaultBytesDistribution,
48         }
49
50         ServerSentBytesPerRPCView = &view.View{
51                 Name:        "grpc.io/server/sent_bytes_per_rpc",
52                 Description: "Distribution of total sent bytes per RPC, by method.",
53                 Measure:     ServerSentBytesPerRPC,
54                 TagKeys:     []tag.Key{KeyServerMethod},
55                 Aggregation: DefaultBytesDistribution,
56         }
57
58         ServerLatencyView = &view.View{
59                 Name:        "grpc.io/server/server_latency",
60                 Description: "Distribution of server latency in milliseconds, by method.",
61                 TagKeys:     []tag.Key{KeyServerMethod},
62                 Measure:     ServerLatency,
63                 Aggregation: DefaultMillisecondsDistribution,
64         }
65
66         ServerCompletedRPCsView = &view.View{
67                 Name:        "grpc.io/server/completed_rpcs",
68                 Description: "Count of RPCs by method and status.",
69                 TagKeys:     []tag.Key{KeyServerMethod, KeyServerStatus},
70                 Measure:     ServerLatency,
71                 Aggregation: view.Count(),
72         }
73
74         ServerReceivedMessagesPerRPCView = &view.View{
75                 Name:        "grpc.io/server/received_messages_per_rpc",
76                 Description: "Distribution of messages received count per RPC, by method.",
77                 TagKeys:     []tag.Key{KeyServerMethod},
78                 Measure:     ServerReceivedMessagesPerRPC,
79                 Aggregation: DefaultMessageCountDistribution,
80         }
81
82         ServerSentMessagesPerRPCView = &view.View{
83                 Name:        "grpc.io/server/sent_messages_per_rpc",
84                 Description: "Distribution of messages sent count per RPC, by method.",
85                 TagKeys:     []tag.Key{KeyServerMethod},
86                 Measure:     ServerSentMessagesPerRPC,
87                 Aggregation: DefaultMessageCountDistribution,
88         }
89 )
90
91 // DefaultServerViews are the default server views provided by this package.
92 var DefaultServerViews = []*view.View{
93         ServerReceivedBytesPerRPCView,
94         ServerSentBytesPerRPCView,
95         ServerLatencyView,
96         ServerCompletedRPCsView,
97 }