Debian Codegraph @

src/cpp/ext/filters/census/measures.cc

raw
1 /*
2 *
3 * Copyright 2018 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <grpc/support/port_platform.h>
20
21 #include "src/cpp/ext/filters/census/measures.h"
22
23 #include "opencensus/stats/stats.h"
24
25 #include <grpcpp/opencensus.h>
26
27 namespace grpc {
28
29 using ::opencensus::stats::MeasureDouble;
30 using ::opencensus::stats::MeasureInt64;
31
32 // These measure definitions should be kept in sync across opencensus
33 // implementations--see
34 // https://github.com/census-instrumentation/opencensus-java/blob/master/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java.
35
36 namespace {
37
38 // Unit constants
39 constexpr char kUnitBytes[] = "By";
40 constexpr char kUnitMilliseconds[] = "ms";
41 constexpr char kCount[] = "1";
42
43 } // namespace
44
45 // Client
46 MeasureDouble RpcClientSentBytesPerRpc() {
47 static const auto measure = MeasureDouble::Register(
48 experimental::kRpcClientSentBytesPerRpcMeasureName,
49 "Total bytes sent across all request messages per RPC", kUnitBytes);
50 return measure;
51 }
52
53 MeasureDouble RpcClientReceivedBytesPerRpc() {
54 static const auto measure = MeasureDouble::Register(
55 experimental::kRpcClientReceivedBytesPerRpcMeasureName,
56 "Total bytes received across all response messages per RPC", kUnitBytes);
57 return measure;
58 }
59
60 MeasureDouble RpcClientRoundtripLatency() {
61 static const auto measure = MeasureDouble::Register(
62 experimental::kRpcClientRoundtripLatencyMeasureName,
63 "Time between first byte of request sent to last byte of response "
64 "received, or terminal error",
65 kUnitMilliseconds);
66 return measure;
67 }
68
69 MeasureDouble RpcClientServerLatency() {
70 static const auto measure = MeasureDouble::Register(
71 experimental::kRpcClientServerLatencyMeasureName,
72 "Time between first byte of request received to last byte of response "
73 "sent, or terminal error (propagated from the server)",
74 kUnitMilliseconds);
75 return measure;
76 }
77
78 MeasureInt64 RpcClientSentMessagesPerRpc() {
79 static const auto measure = MeasureInt64::Register(
80 experimental::kRpcClientSentMessagesPerRpcMeasureName,
81 "Number of messages sent per RPC", kCount);
82 return measure;
83 }
84
85 MeasureInt64 RpcClientReceivedMessagesPerRpc() {
86 static const auto measure = MeasureInt64::Register(
87 experimental::kRpcClientReceivedMessagesPerRpcMeasureName,
88 "Number of messages received per RPC", kCount);
89 return measure;
90 }
91
92 MeasureInt64 RpcClientStartedRpcs() {
93 static const auto measure =
94 MeasureInt64::Register(experimental::kRpcClientStartedRpcsMeasureName,
95 "The total number of client RPCs ever opened, "
96 "including those that have not been completed.",
97 kCount);
98 return measure;
99 }
100
101 // Client per-overall-client-call measures
102 MeasureInt64 RpcClientRetriesPerCall() {
103 static const auto measure =
104 MeasureInt64::Register(experimental::kRpcClientRetriesPerCallMeasureName,
105 "Number of retry or hedging attempts excluding "
106 "transparent retries made during the client call",
107 kCount);
108 return measure;
109 }
110
111 MeasureInt64 RpcClientTransparentRetriesPerCall() {
112 static const auto measure = MeasureInt64::Register(
113 experimental::kRpcClientTransparentRetriesPerCallMeasureName,
114 "Number of transparent retries made during the client call", kCount);
115 return measure;
116 }
117
118 MeasureDouble RpcClientRetryDelayPerCall() {
119 static const auto measure = MeasureDouble::Register(
120 experimental::kRpcClientRetryDelayPerCallMeasureName,
121 "Total time of delay while there is no active "
122 "attempt during the client call",
123 kUnitMilliseconds);
124 return measure;
125 }
126
127 // Server
128 MeasureDouble RpcServerSentBytesPerRpc() {
129 static const auto measure = MeasureDouble::Register(
130 experimental::kRpcServerSentBytesPerRpcMeasureName,
131 "Total bytes sent across all messages per RPC", kUnitBytes);
132 return measure;
133 }
134
135 MeasureDouble RpcServerReceivedBytesPerRpc() {
136 static const auto measure = MeasureDouble::Register(
137 experimental::kRpcServerReceivedBytesPerRpcMeasureName,
138 "Total bytes received across all messages per RPC", kUnitBytes);
139 return measure;
140 }
141
142 MeasureDouble RpcServerServerLatency() {
143 static const auto measure = MeasureDouble::Register(
144 experimental::kRpcServerServerLatencyMeasureName,
145 "Time between first byte of request received to last byte of response "
146 "sent, or terminal error",
147 kUnitMilliseconds);
148 return measure;
149 }
150
151 MeasureInt64 RpcServerStartedRpcs() {
152 static const auto measure =
153 MeasureInt64::Register(experimental::kRpcServerStartedRpcsMeasureName,
154 "The total number of server RPCs ever opened, "
155 "including those that have not been completed.",
156 kCount);
157 return measure;
158 }
159
160 MeasureInt64 RpcServerSentMessagesPerRpc() {
161 static const auto measure = MeasureInt64::Register(
162 experimental::kRpcServerSentMessagesPerRpcMeasureName,
163 "Number of messages sent per RPC", kCount);
164 return measure;
165 }
166
167 MeasureInt64 RpcServerReceivedMessagesPerRpc() {
168 static const auto measure = MeasureInt64::Register(
169 experimental::kRpcServerReceivedMessagesPerRpcMeasureName,
170 "Number of messages received per RPC", kCount);
171 return measure;
172 }
173
174 } // namespace grpc