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 total bytes sent across all request messages per RPC. 117 * 118 * @since 0.13 119 */ 120 public static final MeasureDouble GRPC_CLIENT_SENT_BYTES_PER_RPC = 121 Measure.MeasureDouble.create( 122 "grpc.io/client/sent_bytes_per_rpc", 123 "Total bytes sent across all request messages per RPC", 124 BYTE); 125 126 /** 127 * {@link Measure} for total bytes received across all response messages per RPC. 128 * 129 * @since 0.13 130 */ 131 public static final MeasureDouble GRPC_CLIENT_RECEIVED_BYTES_PER_RPC = 132 Measure.MeasureDouble.create( 133 "grpc.io/client/received_bytes_per_rpc", 134 "Total bytes received across all response messages per RPC", 135 BYTE); 136 137 /** 138 * {@link Measure} for total bytes sent per method, recorded real-time as bytes are sent. 139 * 140 * @since 0.18 141 */ 142 public static final MeasureDouble GRPC_CLIENT_SENT_BYTES_PER_METHOD = 143 Measure.MeasureDouble.create( 144 "grpc.io/client/sent_bytes_per_method", 145 "Total bytes sent per method, recorded real-time as bytes are sent.", 146 BYTE); 147 148 /** 149 * {@link Measure} for total bytes received per method, recorded real-time as bytes are received. 150 * 151 * @since 0.18 152 */ 153 public static final MeasureDouble GRPC_CLIENT_RECEIVED_BYTES_PER_METHOD = 154 Measure.MeasureDouble.create( 155 "grpc.io/client/received_bytes_per_method", 156 "Total bytes received per method, recorded real-time as bytes are received.", 157 BYTE); 158 159 /** 160 * {@link Measure} for total client sent messages. 161 * 162 * @since 0.18 163 */ 164 public static final MeasureLong GRPC_CLIENT_SENT_MESSAGES_PER_METHOD = 165 Measure.MeasureLong.create( 166 "grpc.io/client/sent_messages_per_method", "Total messages sent per method.", COUNT); 167 168 /** 169 * {@link Measure} for total client received messages. 170 * 171 * @since 0.18 172 */ 173 public static final MeasureLong GRPC_CLIENT_RECEIVED_MESSAGES_PER_METHOD = 174 Measure.MeasureLong.create( 175 "grpc.io/client/received_messages_per_method", 176 "Total messages received per method.", 177 COUNT); 178 179 /** 180 * {@link Measure} for gRPC client roundtrip latency in milliseconds. 181 * 182 * @since 0.13 183 */ 184 public static final MeasureDouble GRPC_CLIENT_ROUNDTRIP_LATENCY = 185 Measure.MeasureDouble.create( 186 "grpc.io/client/roundtrip_latency", 187 "Time between first byte of request sent to last byte of response received, " 188 + "or terminal error.", 189 MILLISECOND); 190 191 /** 192 * {@link Measure} for number of messages sent in the RPC. 193 * 194 * @since 0.13 195 */ 196 public static final MeasureLong GRPC_CLIENT_SENT_MESSAGES_PER_RPC = 197 Measure.MeasureLong.create( 198 "grpc.io/client/sent_messages_per_rpc", "Number of messages sent in the RPC", COUNT); 199 200 /** 201 * {@link Measure} for number of response messages received per RPC. 202 * 203 * @since 0.13 204 */ 205 public static final MeasureLong GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC = 206 Measure.MeasureLong.create( 207 "grpc.io/client/received_messages_per_rpc", 208 "Number of response messages received per RPC", 209 COUNT); 210 211 /** 212 * {@link Measure} for gRPC server latency in milliseconds. 213 * 214 * @since 0.13 215 */ 216 public static final MeasureDouble GRPC_CLIENT_SERVER_LATENCY = 217 Measure.MeasureDouble.create( 218 "grpc.io/client/server_latency", "Server latency in msecs", MILLISECOND); 219 220 /** 221 * {@link Measure} for total number of client RPCs ever opened, including those that have not 222 * completed. 223 * 224 * @since 0.14 225 */ 226 public static final MeasureLong GRPC_CLIENT_STARTED_RPCS = 227 Measure.MeasureLong.create( 228 "grpc.io/client/started_rpcs", "Number of started client RPCs.", COUNT); 229 230 /** 231 * {@link Measure} for total number of retry or hedging attempts excluding transparent retries 232 * made during the client call. 233 * 234 * @since 0.31.0 235 */ 236 public static final MeasureLong GRPC_CLIENT_RETRIES_PER_CALL = 237 Measure.MeasureLong.create( 238 "grpc.io/client/retries_per_call", "Number of retries per call", COUNT); 239 240 /** 241 * {@link Measure} for total number of transparent retries made during the client call. 242 * 243 * @since 0.28 244 */ 245 public static final MeasureLong GRPC_CLIENT_TRANSPARENT_RETRIES_PER_CALL = 246 Measure.MeasureLong.create( 247 "grpc.io/client/transparent_retries_per_call", "Transparent retries per call", COUNT); 248 249 /** 250 * {@link Measure} for total time of delay while there is no active attempt during the client 251 * call. 252 * 253 * @since 0.28 254 */ 255 public static final MeasureDouble GRPC_CLIENT_RETRY_DELAY_PER_CALL = 256 Measure.MeasureDouble.create( 257 "grpc.io/client/retry_delay_per_call", "Retry delay per call", MILLISECOND); 258 259 /** 260 * {@link Measure} for gRPC client error counts. 261 * 262 * @since 0.8 263 * @deprecated because error counts can be computed on your metrics backend by totalling the 264 * different per-status values. 265 */ 266 @Deprecated 267 public static final MeasureLong RPC_CLIENT_ERROR_COUNT = 268 Measure.MeasureLong.create("grpc.io/client/error_count", "RPC Errors", COUNT); 269 270 /** 271 * {@link Measure} for gRPC client request bytes. 272 * 273 * @since 0.8 274 * @deprecated in favor of {@link #GRPC_CLIENT_SENT_BYTES_PER_RPC}. 275 */ 276 @Deprecated 277 public static final MeasureDouble RPC_CLIENT_REQUEST_BYTES = GRPC_CLIENT_SENT_BYTES_PER_RPC; 278 279 /** 280 * {@link Measure} for gRPC client response bytes. 281 * 282 * @since 0.8 283 * @deprecated in favor of {@link #GRPC_CLIENT_RECEIVED_BYTES_PER_RPC}. 284 */ 285 @Deprecated 286 public static final MeasureDouble RPC_CLIENT_RESPONSE_BYTES = GRPC_CLIENT_RECEIVED_BYTES_PER_RPC; 287 288 /** 289 * {@link Measure} for gRPC client roundtrip latency in milliseconds. 290 * 291 * @since 0.8 292 * @deprecated in favor of {@link #GRPC_CLIENT_ROUNDTRIP_LATENCY}. 293 */ 294 @Deprecated 295 public static final MeasureDouble RPC_CLIENT_ROUNDTRIP_LATENCY = GRPC_CLIENT_ROUNDTRIP_LATENCY; 296 297 /** 298 * {@link Measure} for gRPC client server elapsed time in milliseconds. 299 * 300 * @since 0.8 301 * @deprecated in favor of {@link #GRPC_CLIENT_SERVER_LATENCY}. 302 */ 303 @Deprecated 304 public static final MeasureDouble RPC_CLIENT_SERVER_ELAPSED_TIME = GRPC_CLIENT_SERVER_LATENCY; 305 306 /** 307 * {@link Measure} for gRPC client uncompressed request bytes. 308 * 309 * @since 0.8 310 * @deprecated in favor of {@link #GRPC_CLIENT_SENT_BYTES_PER_RPC}. 311 */ 312 @Deprecated 313 public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES = 314 Measure.MeasureDouble.create( 315 "grpc.io/client/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE); 316 317 /** 318 * {@link Measure} for gRPC client uncompressed response bytes. 319 * 320 * @since 0.8 321 * @deprecated in favor of {@link #GRPC_CLIENT_RECEIVED_BYTES_PER_RPC}. 322 */ 323 @Deprecated 324 public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES = 325 Measure.MeasureDouble.create( 326 "grpc.io/client/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE); 327 328 /** 329 * {@link Measure} for number of started client RPCs. 330 * 331 * @since 0.8 332 * @deprecated in favor of {@link #GRPC_CLIENT_STARTED_RPCS}. 333 */ 334 @Deprecated public static final MeasureLong RPC_CLIENT_STARTED_COUNT = GRPC_CLIENT_STARTED_RPCS; 335 336 /** 337 * {@link Measure} for number of finished client RPCs. 338 * 339 * @since 0.8 340 * @deprecated since finished count can be inferred with a {@code Count} aggregation on {@link 341 * #GRPC_CLIENT_SERVER_LATENCY}. 342 */ 343 @Deprecated 344 public static final MeasureLong RPC_CLIENT_FINISHED_COUNT = 345 Measure.MeasureLong.create( 346 "grpc.io/client/finished_count", "Number of client RPCs (streams) finished", COUNT); 347 348 /** 349 * {@link Measure} for client RPC request message counts. 350 * 351 * @since 0.8 352 * @deprecated in favor of {@link #GRPC_CLIENT_SENT_MESSAGES_PER_RPC}. 353 */ 354 @Deprecated 355 public static final MeasureLong RPC_CLIENT_REQUEST_COUNT = GRPC_CLIENT_SENT_MESSAGES_PER_RPC; 356 357 /** 358 * {@link Measure} for client RPC response message counts. 359 * 360 * @deprecated in favor of {@link #GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC}. 361 * @since 0.8 362 */ 363 @Deprecated 364 public static final MeasureLong RPC_CLIENT_RESPONSE_COUNT = GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC; 365 366 // RPC server Measures. 367 368 /** 369 * {@link Measure} for total bytes sent across all response messages per RPC. 370 * 371 * @since 0.13 372 */ 373 public static final MeasureDouble GRPC_SERVER_SENT_BYTES_PER_RPC = 374 Measure.MeasureDouble.create( 375 "grpc.io/server/sent_bytes_per_rpc", 376 "Total bytes sent across all response messages per RPC", 377 BYTE); 378 379 /** 380 * {@link Measure} for total bytes received across all messages per RPC. 381 * 382 * @since 0.13 383 */ 384 public static final MeasureDouble GRPC_SERVER_RECEIVED_BYTES_PER_RPC = 385 Measure.MeasureDouble.create( 386 "grpc.io/server/received_bytes_per_rpc", 387 "Total bytes received across all messages per RPC", 388 BYTE); 389 390 /** 391 * {@link Measure} for total bytes sent per method, recorded real-time as bytes are sent. 392 * 393 * @since 0.18 394 */ 395 public static final MeasureDouble GRPC_SERVER_SENT_BYTES_PER_METHOD = 396 Measure.MeasureDouble.create( 397 "grpc.io/server/sent_bytes_per_method", 398 "Total bytes sent per method, recorded real-time as bytes are sent.", 399 BYTE); 400 401 /** 402 * {@link Measure} for total bytes received per method, recorded real-time as bytes are received. 403 * 404 * @since 0.18 405 */ 406 public static final MeasureDouble GRPC_SERVER_RECEIVED_BYTES_PER_METHOD = 407 Measure.MeasureDouble.create( 408 "grpc.io/server/received_bytes_per_method", 409 "Total bytes received per method, recorded real-time as bytes are received.", 410 BYTE); 411 412 /** 413 * {@link Measure} for total server sent messages. 414 * 415 * @since 0.18 416 */ 417 public static final MeasureLong GRPC_SERVER_SENT_MESSAGES_PER_METHOD = 418 Measure.MeasureLong.create( 419 "grpc.io/server/sent_messages_per_method", "Total messages sent per method.", COUNT); 420 421 /** 422 * {@link Measure} for total server received messages. 423 * 424 * @since 0.18 425 */ 426 public static final MeasureLong GRPC_SERVER_RECEIVED_MESSAGES_PER_METHOD = 427 Measure.MeasureLong.create( 428 "grpc.io/server/received_messages_per_method", 429 "Total messages received per method.", 430 COUNT); 431 432 /** 433 * {@link Measure} for number of messages sent in each RPC. 434 * 435 * @since 0.13 436 */ 437 public static final MeasureLong GRPC_SERVER_SENT_MESSAGES_PER_RPC = 438 Measure.MeasureLong.create( 439 "grpc.io/server/sent_messages_per_rpc", "Number of messages sent in each RPC", COUNT); 440 441 /** 442 * {@link Measure} for number of messages received in each RPC. 443 * 444 * @since 0.13 445 */ 446 public static final MeasureLong GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC = 447 Measure.MeasureLong.create( 448 "grpc.io/server/received_messages_per_rpc", 449 "Number of messages received in each RPC", 450 COUNT); 451 452 /** 453 * {@link Measure} for gRPC server latency in milliseconds. 454 * 455 * @since 0.13 456 */ 457 public static final MeasureDouble GRPC_SERVER_SERVER_LATENCY = 458 Measure.MeasureDouble.create( 459 "grpc.io/server/server_latency", 460 "Time between first byte of request received to last byte of response sent, " 461 + "or terminal error.", 462 MILLISECOND); 463 464 /** 465 * {@link Measure} for total number of server RPCs ever opened, including those that have not 466 * completed. 467 * 468 * @since 0.14 469 */ 470 public static final MeasureLong GRPC_SERVER_STARTED_RPCS = 471 Measure.MeasureLong.create( 472 "grpc.io/server/started_rpcs", "Number of started server RPCs.", COUNT); 473 474 /** 475 * {@link Measure} for gRPC server error counts. 476 * 477 * @since 0.8 478 * @deprecated because error counts can be computed on your metrics backend by totalling the 479 * different per-status values. 480 */ 481 @Deprecated 482 public static final MeasureLong RPC_SERVER_ERROR_COUNT = 483 Measure.MeasureLong.create("grpc.io/server/error_count", "RPC Errors", COUNT); 484 485 /** 486 * {@link Measure} for gRPC server request bytes. 487 * 488 * @since 0.8 489 * @deprecated in favor of {@link #GRPC_SERVER_RECEIVED_BYTES_PER_RPC}. 490 */ 491 @Deprecated 492 public static final MeasureDouble RPC_SERVER_REQUEST_BYTES = GRPC_SERVER_RECEIVED_BYTES_PER_RPC; 493 494 /** 495 * {@link Measure} for gRPC server response bytes. 496 * 497 * @since 0.8 498 * @deprecated in favor of {@link #GRPC_SERVER_SENT_BYTES_PER_RPC}. 499 */ 500 @Deprecated 501 public static final MeasureDouble RPC_SERVER_RESPONSE_BYTES = GRPC_SERVER_SENT_BYTES_PER_RPC; 502 503 /** 504 * {@link Measure} for gRPC server elapsed time in milliseconds. 505 * 506 * @since 0.8 507 * @deprecated in favor of {@link #GRPC_SERVER_SERVER_LATENCY}. 508 */ 509 @Deprecated 510 public static final MeasureDouble RPC_SERVER_SERVER_ELAPSED_TIME = 511 Measure.MeasureDouble.create( 512 "grpc.io/server/server_elapsed_time", "Server elapsed time in msecs", MILLISECOND); 513 514 /** 515 * {@link Measure} for gRPC server latency in milliseconds. 516 * 517 * @since 0.8 518 * @deprecated in favor of {@link #GRPC_SERVER_SERVER_LATENCY}. 519 */ 520 @Deprecated 521 public static final MeasureDouble RPC_SERVER_SERVER_LATENCY = GRPC_SERVER_SERVER_LATENCY; 522 523 /** 524 * {@link Measure} for gRPC server uncompressed request bytes. 525 * 526 * @since 0.8 527 * @deprecated in favor of {@link #GRPC_SERVER_RECEIVED_BYTES_PER_RPC}. 528 */ 529 @Deprecated 530 public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES = 531 Measure.MeasureDouble.create( 532 "grpc.io/server/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE); 533 534 /** 535 * {@link Measure} for gRPC server uncompressed response bytes. 536 * 537 * @since 0.8 538 * @deprecated in favor of {@link #GRPC_SERVER_SENT_BYTES_PER_RPC}. 539 */ 540 @Deprecated 541 public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES = 542 Measure.MeasureDouble.create( 543 "grpc.io/server/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE); 544 545 /** 546 * {@link Measure} for number of started server RPCs. 547 * 548 * @since 0.8 549 * @deprecated in favor of {@link #GRPC_SERVER_STARTED_RPCS}. 550 */ 551 @Deprecated public static final MeasureLong RPC_SERVER_STARTED_COUNT = GRPC_SERVER_STARTED_RPCS; 552 553 /** 554 * {@link Measure} for number of finished server RPCs. 555 * 556 * @since 0.8 557 * @deprecated since finished count can be inferred with a {@code Count} aggregation on {@link 558 * #GRPC_SERVER_SERVER_LATENCY}. 559 */ 560 @Deprecated 561 public static final MeasureLong RPC_SERVER_FINISHED_COUNT = 562 Measure.MeasureLong.create( 563 "grpc.io/server/finished_count", "Number of server RPCs (streams) finished", COUNT); 564 565 /** 566 * {@link Measure} for server RPC request message counts. 567 * 568 * @since 0.8 569 * @deprecated in favor of {@link #GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC}. 570 */ 571 @Deprecated 572 public static final MeasureLong RPC_SERVER_REQUEST_COUNT = GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC; 573 574 /** 575 * {@link Measure} for server RPC response message counts. 576 * 577 * @since 0.8 578 * @deprecated in favor of {@link #GRPC_SERVER_SENT_MESSAGES_PER_RPC}. 579 */ 580 @Deprecated 581 public static final MeasureLong RPC_SERVER_RESPONSE_COUNT = GRPC_SERVER_SENT_MESSAGES_PER_RPC; 582 RpcMeasureConstants()583 private RpcMeasureConstants() {} 584 } 585