|
| 1 | +/* |
| 2 | + * Copyright 2023 Google LLC |
| 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 | + * https://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 | +package com.google.cloud.bigtable.data.v2.stub.metrics; |
| 17 | + |
| 18 | +import io.opentelemetry.api.common.Attributes; |
| 19 | +import io.opentelemetry.api.metrics.LongCounter; |
| 20 | +import io.opentelemetry.api.metrics.LongHistogram; |
| 21 | +import io.opentelemetry.api.metrics.Meter; |
| 22 | + |
| 23 | +class BuiltinInstruments extends BigtableInstruments { |
| 24 | + |
| 25 | + private static final String MILLISECOND = "ms"; |
| 26 | + private static final String COUNT = "1"; |
| 27 | + |
| 28 | + private final LongHistogram operationLatencies; |
| 29 | + private final LongHistogram attemptLatencies; |
| 30 | + private final LongHistogram serverLatencies; |
| 31 | + private final LongHistogram firstResponseLatencies; |
| 32 | + private final LongHistogram clientBlockingLatencies; |
| 33 | + private final LongHistogram applicationBlockingLatencies; |
| 34 | + private final LongCounter connectivityErrorCount; |
| 35 | + private final LongCounter retryCount; |
| 36 | + |
| 37 | + BuiltinInstruments(Meter meter) { |
| 38 | + operationLatencies = |
| 39 | + meter |
| 40 | + .histogramBuilder("operation_latencies") |
| 41 | + .ofLongs() |
| 42 | + .setDescription( |
| 43 | + "Total time until final operation success or failure, including retries and backoff.") |
| 44 | + .setUnit(MILLISECOND) |
| 45 | + .build(); |
| 46 | + attemptLatencies = |
| 47 | + meter |
| 48 | + .histogramBuilder("attempt_latencies") |
| 49 | + .ofLongs() |
| 50 | + .setDescription("Client observed latency per RPC attempt.") |
| 51 | + .setUnit(MILLISECOND) |
| 52 | + .build(); |
| 53 | + serverLatencies = |
| 54 | + meter |
| 55 | + .histogramBuilder("server_latencies") |
| 56 | + .ofLongs() |
| 57 | + .setDescription( |
| 58 | + "The latency measured from the moment that the RPC entered the Google data center until the RPC was completed.") |
| 59 | + .setUnit(MILLISECOND) |
| 60 | + .build(); |
| 61 | + firstResponseLatencies = |
| 62 | + meter |
| 63 | + .histogramBuilder("first_response_latencies") |
| 64 | + .ofLongs() |
| 65 | + .setDescription( |
| 66 | + "Latency from operation start until the response headers were received. The publishing of the measurement will be delayed until the attempt response has been received.") |
| 67 | + .setUnit(MILLISECOND) |
| 68 | + .build(); |
| 69 | + clientBlockingLatencies = |
| 70 | + meter |
| 71 | + .histogramBuilder("throttling_latencies") |
| 72 | + .ofLongs() |
| 73 | + .setDescription( |
| 74 | + "The artificial latency introduced by the client to limit the number of outstanding requests. The publishing of the measurement will be delayed until the attempt trailers have been received.") |
| 75 | + .setUnit(MILLISECOND) |
| 76 | + .build(); |
| 77 | + applicationBlockingLatencies = |
| 78 | + meter |
| 79 | + .histogramBuilder("application_latencies") |
| 80 | + .ofLongs() |
| 81 | + .setDescription( |
| 82 | + "The latency of the client application consuming available response data.") |
| 83 | + .setUnit(MILLISECOND) |
| 84 | + .build(); |
| 85 | + connectivityErrorCount = |
| 86 | + meter |
| 87 | + .counterBuilder("connectivity_error_count") |
| 88 | + .setDescription( |
| 89 | + "Number of requests that failed to reach the Google datacenter. (Requests without google response headers") |
| 90 | + .setUnit(COUNT) |
| 91 | + .build(); |
| 92 | + retryCount = |
| 93 | + meter |
| 94 | + .counterBuilder("retry_count") |
| 95 | + .setDescription("The number of additional RPCs sent after the initial attempt.") |
| 96 | + .setUnit(COUNT) |
| 97 | + .build(); |
| 98 | + } |
| 99 | + |
| 100 | + @Override |
| 101 | + void recordOperationLatencies(long value, Attributes attributes) { |
| 102 | + operationLatencies.record(value, attributes); |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + void recordAttemptLatencies(long value, Attributes attributes) { |
| 107 | + attemptLatencies.record(value, attributes); |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + void recordFirstResponseLatencies(long value, Attributes attributes) { |
| 112 | + firstResponseLatencies.record(value, attributes); |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + void recordRetryCount(long value, Attributes attributes) { |
| 117 | + retryCount.add(value, attributes); |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + void recordServerLatencies(long value, Attributes attributes) { |
| 122 | + serverLatencies.record(value, attributes); |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + void recordConnectivityErrorCount(long value, Attributes attributes) { |
| 127 | + connectivityErrorCount.add(value, attributes); |
| 128 | + } |
| 129 | + |
| 130 | + @Override |
| 131 | + void recordApplicationBlockingLatencies(long value, Attributes attributes) { |
| 132 | + applicationBlockingLatencies.record(value, attributes); |
| 133 | + } |
| 134 | + |
| 135 | + @Override |
| 136 | + void recordClientBlockingLatencies(long value, Attributes attributes) { |
| 137 | + clientBlockingLatencies.record(value, attributes); |
| 138 | + } |
| 139 | +} |
0 commit comments