Skip to content

Commit 5dc702f

Browse files
committed
chore: Remove duplicate declaration of attempt and operation metrics
1 parent 0bf197b commit 5dc702f

File tree

2 files changed

+10
-41
lines changed

2 files changed

+10
-41
lines changed

java-datastore/google-cloud-datastore/src/main/java/com/google/cloud/datastore/telemetry/OpenTelemetryDatastoreMetricsRecorder.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ class OpenTelemetryDatastoreMetricsRecorder extends OpenTelemetryMetricsRecorder
4949
private final DoubleHistogram transactionLatency;
5050
private final LongCounter transactionAttemptCount;
5151

52-
// GAX operation/attempt latency metrics re-registered under the Datastore meter with the
53-
// plural names required by the internal Cloud Monitoring descriptor. These override the
54-
// singular-named histograms registered by the parent GAX class.
55-
private final DoubleHistogram operationLatency;
56-
private final DoubleHistogram attemptLatency;
57-
52+
// Note: Standard GAX RPC metrics (operation_latency, attempt_latency, etc.) are handled by the
53+
// base OpenTelemetryMetricsRecorder class. Those metrics are inherited from the parent classes.
54+
// However, the internal metrics expect plural suffixes (e.g. `latencies` instead of `latency`).
55+
// The discrepancy between the singular GAX names and the plural internal Cloud Monitoring names
56+
// is handled by configuring OpenTelemetry Views.
5857
OpenTelemetryDatastoreMetricsRecorder(@Nonnull OpenTelemetry openTelemetry, String metricPrefix) {
5958
super(openTelemetry, metricPrefix);
6059
this.openTelemetry = openTelemetry;
@@ -73,37 +72,12 @@ class OpenTelemetryDatastoreMetricsRecorder extends OpenTelemetryMetricsRecorder
7372
.counterBuilder(TelemetryConstants.METRIC_NAME_TRANSACTION_ATTEMPT_COUNT)
7473
.setDescription("Number of attempts to commit a transaction")
7574
.build();
76-
77-
this.operationLatency =
78-
meter
79-
.histogramBuilder(TelemetryConstants.METRIC_NAME_OPERATION_LATENCY)
80-
.setDescription(
81-
"Total time until final operation success or failure, including retries and backoff.")
82-
.setUnit("ms")
83-
.build();
84-
85-
this.attemptLatency =
86-
meter
87-
.histogramBuilder(TelemetryConstants.METRIC_NAME_ATTEMPT_LATENCY)
88-
.setDescription("Time an individual attempt took")
89-
.setUnit("ms")
90-
.build();
9175
}
9276

9377
OpenTelemetry getOpenTelemetry() {
9478
return openTelemetry;
9579
}
9680

97-
@Override
98-
public void recordOperationLatency(double latencyMs, Map<String, String> attributes) {
99-
operationLatency.record(latencyMs, toOtelAttributes(attributes));
100-
}
101-
102-
@Override
103-
public void recordAttemptLatency(double latencyMs, Map<String, String> attributes) {
104-
attemptLatency.record(latencyMs, toOtelAttributes(attributes));
105-
}
106-
10781
@Override
10882
public void recordTransactionLatency(double latencyMs, Map<String, String> attributes) {
10983
transactionLatency.record(latencyMs, toOtelAttributes(attributes));

java-datastore/google-cloud-datastore/src/test/java/com/google/cloud/datastore/telemetry/OpenTelemetryDatastoreMetricsRecorderTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,11 @@ public void recordAttemptLatency_recordsHistogramWithAttributes() {
175175
Collection<MetricData> metrics = metricReader.collectAllMetrics();
176176
MetricData metric =
177177
metrics.stream()
178-
.filter(m -> m.getName().equals(TelemetryConstants.METRIC_NAME_ATTEMPT_LATENCY))
178+
.filter(m -> m.getName().equals(TelemetryConstants.METRIC_PREFIX + "/attempt_latency"))
179179
.findFirst()
180180
.orElse(null);
181181

182182
assertThat(metric).isNotNull();
183-
assertThat(metric.getDescription()).isEqualTo("Time an individual attempt took");
184183
assertThat(metric.getUnit()).isEqualTo("ms");
185184

186185
HistogramPointData point =
@@ -206,12 +205,11 @@ public void recordAttemptCount_recordsCounterWithAttributes() {
206205
Collection<MetricData> metrics = metricReader.collectAllMetrics();
207206
MetricData metric =
208207
metrics.stream()
209-
.filter(m -> m.getName().equals(TelemetryConstants.METRIC_NAME_ATTEMPT_COUNT))
208+
.filter(m -> m.getName().equals(TelemetryConstants.METRIC_PREFIX + "/attempt_count"))
210209
.findFirst()
211210
.orElse(null);
212211

213212
assertThat(metric).isNotNull();
214-
assertThat(metric.getDescription()).isEqualTo("Number of Attempts");
215213

216214
LongPointData point = metric.getLongSumData().getPoints().stream().findFirst().orElse(null);
217215
assertThat(point).isNotNull();
@@ -229,14 +227,12 @@ public void recordOperationLatency_recordsHistogramWithAttributes() {
229227
Collection<MetricData> metrics = metricReader.collectAllMetrics();
230228
MetricData metric =
231229
metrics.stream()
232-
.filter(m -> m.getName().equals(TelemetryConstants.METRIC_NAME_OPERATION_LATENCY))
230+
.filter(
231+
m -> m.getName().equals(TelemetryConstants.METRIC_PREFIX + "/operation_latency"))
233232
.findFirst()
234233
.orElse(null);
235234

236235
assertThat(metric).isNotNull();
237-
assertThat(metric.getDescription())
238-
.isEqualTo(
239-
"Total time until final operation success or failure, including retries and backoff.");
240236
assertThat(metric.getUnit()).isEqualTo("ms");
241237

242238
HistogramPointData point =
@@ -258,12 +254,11 @@ public void recordOperationCount_recordsCounterWithAttributes() {
258254
Collection<MetricData> metrics = metricReader.collectAllMetrics();
259255
MetricData metric =
260256
metrics.stream()
261-
.filter(m -> m.getName().equals(TelemetryConstants.METRIC_NAME_OPERATION_COUNT))
257+
.filter(m -> m.getName().equals(TelemetryConstants.METRIC_PREFIX + "/operation_count"))
262258
.findFirst()
263259
.orElse(null);
264260

265261
assertThat(metric).isNotNull();
266-
assertThat(metric.getDescription()).isEqualTo("Number of Operations");
267262

268263
LongPointData point = metric.getLongSumData().getPoints().stream().findFirst().orElse(null);
269264
assertThat(point).isNotNull();

0 commit comments

Comments
 (0)