• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017, OpenCensus Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.opencensus.contrib.grpc.metrics;
18 
19 import io.opencensus.stats.Measure;
20 import io.opencensus.stats.Measure.MeasureDouble;
21 import io.opencensus.stats.Measure.MeasureLong;
22 import io.opencensus.tags.TagKey;
23 
24 /**
25  * Constants for collecting rpc stats.
26  *
27  * @since 0.8
28  */
29 public final class RpcMeasureConstants {
30 
31   /**
32    * Tag key that represents a gRPC canonical status. Refer to
33    * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md.
34    *
35    * @since 0.8
36    * @deprecated in favor of {@link #GRPC_CLIENT_STATUS} and {@link #GRPC_SERVER_STATUS}.
37    */
38   @Deprecated public static final TagKey RPC_STATUS = TagKey.create("canonical_status");
39 
40   /**
41    * Tag key that represents a gRPC method.
42    *
43    * @since 0.8
44    * @deprecated in favor of {@link #GRPC_CLIENT_METHOD} and {@link #GRPC_SERVER_METHOD}.
45    */
46   @Deprecated public static final TagKey RPC_METHOD = TagKey.create("method");
47 
48   /**
49    * Tag key that represents a client gRPC canonical status. Refer to
50    * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md.
51    *
52    * <p>{@link #GRPC_CLIENT_STATUS} is set when an outgoing request finishes and is only available
53    * around metrics recorded at the end of the outgoing request.
54    *
55    * @since 0.13
56    */
57   public static final TagKey GRPC_CLIENT_STATUS = TagKey.create("grpc_client_status");
58 
59   /**
60    * Tag key that represents a server gRPC canonical status. Refer to
61    * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md.
62    *
63    * <p>{@link #GRPC_SERVER_STATUS} is set when an incoming request finishes and is only available
64    * around metrics recorded at the end of the incoming request.
65    *
66    * @since 0.13
67    */
68   public static final TagKey GRPC_SERVER_STATUS = TagKey.create("grpc_server_status");
69 
70   /**
71    * Tag key that represents a client gRPC method.
72    *
73    * <p>{@link #GRPC_CLIENT_METHOD} is set when an outgoing request starts and is available in all
74    * the recorded metrics.
75    *
76    * @since 0.13
77    */
78   public static final TagKey GRPC_CLIENT_METHOD = TagKey.create("grpc_client_method");
79 
80   /**
81    * Tag key that represents a server gRPC method.
82    *
83    * <p>{@link #GRPC_SERVER_METHOD} is set when an incoming request starts and is available in the
84    * context for the entire RPC call handling.
85    *
86    * @since 0.13
87    */
88   public static final TagKey GRPC_SERVER_METHOD = TagKey.create("grpc_server_method");
89 
90   // Constants used to define the following Measures.
91 
92   /**
93    * Unit string for byte.
94    *
95    * @since 0.8
96    */
97   private static final String BYTE = "By";
98 
99   /**
100    * Unit string for count.
101    *
102    * @since 0.8
103    */
104   private static final String COUNT = "1";
105 
106   /**
107    * Unit string for millisecond.
108    *
109    * @since 0.8
110    */
111   private static final String MILLISECOND = "ms";
112 
113   // RPC client Measures.
114 
115   /**
116    * {@link Measure} for gRPC client error counts.
117    *
118    * @since 0.8
119    * @deprecated because error counts can be computed on your metrics backend by totalling the
120    *     different per-status values.
121    */
122   @Deprecated
123   public static final MeasureLong RPC_CLIENT_ERROR_COUNT =
124       Measure.MeasureLong.create("grpc.io/client/error_count", "RPC Errors", COUNT);
125 
126   /**
127    * {@link Measure} for gRPC client request bytes.
128    *
129    * @since 0.8
130    * @deprecated in favor of {@link #GRPC_CLIENT_SENT_BYTES_PER_RPC}.
131    */
132   @Deprecated
133   public static final MeasureDouble RPC_CLIENT_REQUEST_BYTES =
134       Measure.MeasureDouble.create("grpc.io/client/request_bytes", "Request bytes", BYTE);
135 
136   /**
137    * {@link Measure} for gRPC client response bytes.
138    *
139    * @since 0.8
140    * @deprecated in favor of {@link #GRPC_CLIENT_RECEIVED_BYTES_PER_RPC}.
141    */
142   @Deprecated
143   public static final MeasureDouble RPC_CLIENT_RESPONSE_BYTES =
144       Measure.MeasureDouble.create("grpc.io/client/response_bytes", "Response bytes", BYTE);
145 
146   /**
147    * {@link Measure} for gRPC client roundtrip latency in milliseconds.
148    *
149    * @since 0.8
150    * @deprecated in favor of {@link #GRPC_CLIENT_ROUNDTRIP_LATENCY}.
151    */
152   @Deprecated
153   public static final MeasureDouble RPC_CLIENT_ROUNDTRIP_LATENCY =
154       Measure.MeasureDouble.create(
155           "grpc.io/client/roundtrip_latency", "RPC roundtrip latency msec", MILLISECOND);
156 
157   /**
158    * {@link Measure} for gRPC client server elapsed time in milliseconds.
159    *
160    * @since 0.8
161    * @deprecated in favor of {@link #GRPC_CLIENT_SERVER_LATENCY}.
162    */
163   @Deprecated
164   public static final MeasureDouble RPC_CLIENT_SERVER_ELAPSED_TIME =
165       Measure.MeasureDouble.create(
166           "grpc.io/client/server_elapsed_time", "Server elapsed time in msecs", MILLISECOND);
167 
168   /**
169    * {@link Measure} for gRPC client uncompressed request bytes.
170    *
171    * @since 0.8
172    * @deprecated in favor of {@link #GRPC_CLIENT_SENT_BYTES_PER_RPC}.
173    */
174   @Deprecated
175   public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES =
176       Measure.MeasureDouble.create(
177           "grpc.io/client/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE);
178 
179   /**
180    * {@link Measure} for gRPC client uncompressed response bytes.
181    *
182    * @since 0.8
183    * @deprecated in favor of {@link #GRPC_CLIENT_RECEIVED_BYTES_PER_RPC}.
184    */
185   @Deprecated
186   public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES =
187       Measure.MeasureDouble.create(
188           "grpc.io/client/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE);
189 
190   /**
191    * {@link Measure} for number of started client RPCs.
192    *
193    * @since 0.8
194    * @deprecated in favor of {@link #GRPC_CLIENT_STARTED_RPCS}.
195    */
196   @Deprecated
197   public static final MeasureLong RPC_CLIENT_STARTED_COUNT =
198       Measure.MeasureLong.create(
199           "grpc.io/client/started_count", "Number of client RPCs (streams) started", COUNT);
200 
201   /**
202    * {@link Measure} for number of finished client RPCs.
203    *
204    * @since 0.8
205    * @deprecated since finished count can be inferred with a {@code Count} aggregation on {@link
206    *     #GRPC_CLIENT_SERVER_LATENCY}.
207    */
208   @Deprecated
209   public static final MeasureLong RPC_CLIENT_FINISHED_COUNT =
210       Measure.MeasureLong.create(
211           "grpc.io/client/finished_count", "Number of client RPCs (streams) finished", COUNT);
212 
213   /**
214    * {@link Measure} for client RPC request message counts.
215    *
216    * @since 0.8
217    * @deprecated in favor of {@link #GRPC_CLIENT_SENT_MESSAGES_PER_RPC}.
218    */
219   @Deprecated
220   public static final MeasureLong RPC_CLIENT_REQUEST_COUNT =
221       Measure.MeasureLong.create(
222           "grpc.io/client/request_count", "Number of client RPC request messages", COUNT);
223 
224   /**
225    * {@link Measure} for client RPC response message counts.
226    *
227    * @deprecated in favor of {@link #GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC}.
228    * @since 0.8
229    */
230   @Deprecated
231   public static final MeasureLong RPC_CLIENT_RESPONSE_COUNT =
232       Measure.MeasureLong.create(
233           "grpc.io/client/response_count", "Number of client RPC response messages", COUNT);
234 
235   /**
236    * {@link Measure} for total bytes sent across all request messages per RPC.
237    *
238    * @since 0.13
239    */
240   public static final MeasureDouble GRPC_CLIENT_SENT_BYTES_PER_RPC =
241       Measure.MeasureDouble.create(
242           "grpc.io/client/sent_bytes_per_rpc",
243           "Total bytes sent across all request messages per RPC",
244           BYTE);
245 
246   /**
247    * {@link Measure} for total bytes received across all response messages per RPC.
248    *
249    * @since 0.13
250    */
251   public static final MeasureDouble GRPC_CLIENT_RECEIVED_BYTES_PER_RPC =
252       Measure.MeasureDouble.create(
253           "grpc.io/client/received_bytes_per_rpc",
254           "Total bytes received across all response messages per RPC",
255           BYTE);
256 
257   /**
258    * {@link Measure} for gRPC client roundtrip latency in milliseconds.
259    *
260    * @since 0.13
261    */
262   public static final MeasureDouble GRPC_CLIENT_ROUNDTRIP_LATENCY =
263       Measure.MeasureDouble.create(
264           "grpc.io/client/roundtrip_latency",
265           "Time between first byte of request sent to last byte of response received, "
266               + "or terminal error.",
267           MILLISECOND);
268 
269   /**
270    * {@link Measure} for number of messages sent in the RPC.
271    *
272    * @since 0.13
273    */
274   public static final MeasureLong GRPC_CLIENT_SENT_MESSAGES_PER_RPC =
275       Measure.MeasureLong.create(
276           "grpc.io/client/sent_messages_per_rpc", "Number of messages sent in the RPC", COUNT);
277 
278   /**
279    * {@link Measure} for number of response messages received per RPC.
280    *
281    * @since 0.13
282    */
283   public static final MeasureLong GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC =
284       Measure.MeasureLong.create(
285           "grpc.io/client/received_messages_per_rpc",
286           "Number of response messages received per RPC",
287           COUNT);
288 
289   /**
290    * {@link Measure} for gRPC server latency in milliseconds.
291    *
292    * @since 0.13
293    */
294   public static final MeasureDouble GRPC_CLIENT_SERVER_LATENCY =
295       Measure.MeasureDouble.create(
296           "grpc.io/client/server_latency", "Server latency in msecs", MILLISECOND);
297 
298   /**
299    * {@link Measure} for total number of client RPCs ever opened, including those that have not
300    * completed.
301    *
302    * @since 0.14
303    */
304   public static final MeasureLong GRPC_CLIENT_STARTED_RPCS =
305       Measure.MeasureLong.create(
306           "grpc.io/client/started_rpcs", "Number of started client RPCs.", COUNT);
307 
308   // RPC server Measures.
309 
310   /**
311    * {@link Measure} for gRPC server error counts.
312    *
313    * @since 0.8
314    * @deprecated because error counts can be computed on your metrics backend by totalling the
315    *     different per-status values.
316    */
317   @Deprecated
318   public static final MeasureLong RPC_SERVER_ERROR_COUNT =
319       Measure.MeasureLong.create("grpc.io/server/error_count", "RPC Errors", COUNT);
320 
321   /**
322    * {@link Measure} for gRPC server request bytes.
323    *
324    * @since 0.8
325    * @deprecated in favor of {@link #GRPC_SERVER_RECEIVED_BYTES_PER_RPC}.
326    */
327   @Deprecated
328   public static final MeasureDouble RPC_SERVER_REQUEST_BYTES =
329       Measure.MeasureDouble.create("grpc.io/server/request_bytes", "Request bytes", BYTE);
330 
331   /**
332    * {@link Measure} for gRPC server response bytes.
333    *
334    * @since 0.8
335    * @deprecated in favor of {@link #GRPC_SERVER_SENT_BYTES_PER_RPC}.
336    */
337   @Deprecated
338   public static final MeasureDouble RPC_SERVER_RESPONSE_BYTES =
339       Measure.MeasureDouble.create("grpc.io/server/response_bytes", "Response bytes", BYTE);
340 
341   /**
342    * {@link Measure} for gRPC server elapsed time in milliseconds.
343    *
344    * @since 0.8
345    * @deprecated in favor of {@link #GRPC_SERVER_SERVER_LATENCY}.
346    */
347   @Deprecated
348   public static final MeasureDouble RPC_SERVER_SERVER_ELAPSED_TIME =
349       Measure.MeasureDouble.create(
350           "grpc.io/server/server_elapsed_time", "Server elapsed time in msecs", MILLISECOND);
351 
352   /**
353    * {@link Measure} for gRPC server latency in milliseconds.
354    *
355    * @since 0.8
356    * @deprecated in favor of {@link #GRPC_SERVER_SERVER_LATENCY}.
357    */
358   @Deprecated
359   public static final MeasureDouble RPC_SERVER_SERVER_LATENCY =
360       Measure.MeasureDouble.create(
361           "grpc.io/server/server_latency", "Latency in msecs", MILLISECOND);
362 
363   /**
364    * {@link Measure} for gRPC server uncompressed request bytes.
365    *
366    * @since 0.8
367    * @deprecated in favor of {@link #GRPC_SERVER_RECEIVED_BYTES_PER_RPC}.
368    */
369   @Deprecated
370   public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES =
371       Measure.MeasureDouble.create(
372           "grpc.io/server/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE);
373 
374   /**
375    * {@link Measure} for gRPC server uncompressed response bytes.
376    *
377    * @since 0.8
378    * @deprecated in favor of {@link #GRPC_SERVER_SENT_BYTES_PER_RPC}.
379    */
380   @Deprecated
381   public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES =
382       Measure.MeasureDouble.create(
383           "grpc.io/server/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE);
384 
385   /**
386    * {@link Measure} for number of started server RPCs.
387    *
388    * @since 0.8
389    * @deprecated in favor of {@link #GRPC_SERVER_STARTED_RPCS}.
390    */
391   @Deprecated
392   public static final MeasureLong RPC_SERVER_STARTED_COUNT =
393       Measure.MeasureLong.create(
394           "grpc.io/server/started_count", "Number of server RPCs (streams) started", COUNT);
395 
396   /**
397    * {@link Measure} for number of finished server RPCs.
398    *
399    * @since 0.8
400    * @deprecated since finished count can be inferred with a {@code Count} aggregation on {@link
401    *     #GRPC_SERVER_SERVER_LATENCY}.
402    */
403   @Deprecated
404   public static final MeasureLong RPC_SERVER_FINISHED_COUNT =
405       Measure.MeasureLong.create(
406           "grpc.io/server/finished_count", "Number of server RPCs (streams) finished", COUNT);
407 
408   /**
409    * {@link Measure} for server RPC request message counts.
410    *
411    * @since 0.8
412    * @deprecated in favor of {@link #GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC}.
413    */
414   @Deprecated
415   public static final MeasureLong RPC_SERVER_REQUEST_COUNT =
416       Measure.MeasureLong.create(
417           "grpc.io/server/request_count", "Number of server RPC request messages", COUNT);
418 
419   /**
420    * {@link Measure} for server RPC response message counts.
421    *
422    * @since 0.8
423    * @deprecated in favor of {@link #GRPC_SERVER_SENT_MESSAGES_PER_RPC}.
424    */
425   @Deprecated
426   public static final MeasureLong RPC_SERVER_RESPONSE_COUNT =
427       Measure.MeasureLong.create(
428           "grpc.io/server/response_count", "Number of server RPC response messages", COUNT);
429 
430   /**
431    * {@link Measure} for total bytes sent across all response messages per RPC.
432    *
433    * @since 0.13
434    */
435   public static final MeasureDouble GRPC_SERVER_SENT_BYTES_PER_RPC =
436       Measure.MeasureDouble.create(
437           "grpc.io/server/sent_bytes_per_rpc",
438           "Total bytes sent across all response messages per RPC",
439           BYTE);
440 
441   /**
442    * {@link Measure} for total bytes received across all messages per RPC.
443    *
444    * @since 0.13
445    */
446   public static final MeasureDouble GRPC_SERVER_RECEIVED_BYTES_PER_RPC =
447       Measure.MeasureDouble.create(
448           "grpc.io/server/received_bytes_per_rpc",
449           "Total bytes received across all messages per RPC",
450           BYTE);
451 
452   /**
453    * {@link Measure} for number of messages sent in each RPC.
454    *
455    * @since 0.13
456    */
457   public static final MeasureLong GRPC_SERVER_SENT_MESSAGES_PER_RPC =
458       Measure.MeasureLong.create(
459           "grpc.io/server/sent_messages_per_rpc", "Number of messages sent in each RPC", COUNT);
460 
461   /**
462    * {@link Measure} for number of messages received in each RPC.
463    *
464    * @since 0.13
465    */
466   public static final MeasureLong GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC =
467       Measure.MeasureLong.create(
468           "grpc.io/server/received_messages_per_rpc",
469           "Number of messages received in each RPC",
470           COUNT);
471 
472   /**
473    * {@link Measure} for gRPC server latency in milliseconds.
474    *
475    * @since 0.13
476    */
477   public static final MeasureDouble GRPC_SERVER_SERVER_LATENCY =
478       Measure.MeasureDouble.create(
479           "grpc.io/server/server_latency",
480           "Time between first byte of request received to last byte of response sent, "
481               + "or terminal error.",
482           MILLISECOND);
483 
484   /**
485    * {@link Measure} for total number of server RPCs ever opened, including those that have not
486    * completed.
487    *
488    * @since 0.14
489    */
490   public static final MeasureLong GRPC_SERVER_STARTED_RPCS =
491       Measure.MeasureLong.create(
492           "grpc.io/server/started_rpcs", "Number of started server RPCs.", COUNT);
493 
RpcMeasureConstants()494   private RpcMeasureConstants() {}
495 }
496