Skip to content

Commit f2f1e9b

Browse files
committed
chore: Fix variable names
1 parent 2093485 commit f2f1e9b

File tree

6 files changed

+30
-45
lines changed

6 files changed

+30
-45
lines changed

java-datastore/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ final class DatastoreImpl extends BaseService<DatastoreOptions> implements Datas
100100

101101
private final com.google.cloud.datastore.telemetry.TraceUtil otelTraceUtil =
102102
getOptions().getTraceUtil();
103-
private final DatastoreMetricsRecorder datastoreMetricsRecorder =
104-
getOptions().getMetricsRecorder();
103+
private final DatastoreMetricsRecorder metricsRecorder = getOptions().getMetricsRecorder();
105104
private final ReadOptionProtoPreparer readOptionProtoPreparer;
106105
private final AggregationQueryExecutor aggregationQueryExecutor;
107106

@@ -119,7 +118,7 @@ final class DatastoreImpl extends BaseService<DatastoreOptions> implements Datas
119118
.setTraceUtil(otelTraceUtil)
120119
.setRetrySettings(retrySettings)
121120
.setDatastoreOptions(options)
122-
.setMetricsRecorder(datastoreMetricsRecorder)
121+
.setMetricsRecorder(metricsRecorder)
123122
.build(),
124123
options);
125124
}
@@ -182,19 +181,19 @@ public boolean isClosed() {
182181
static class ReadWriteTransactionCallable<T> implements Callable<T> {
183182
private final Datastore datastore;
184183
private final TransactionCallable<T> callable;
185-
private final DatastoreMetricsRecorder datastoreMetricsRecorder;
184+
private final DatastoreMetricsRecorder metricsRecorder;
186185
private volatile TransactionOptions options;
187186
private volatile Transaction transaction;
188187

189188
ReadWriteTransactionCallable(
190189
Datastore datastore,
191190
TransactionCallable<T> callable,
192191
TransactionOptions options,
193-
DatastoreMetricsRecorder datastoreMetricsRecorder) {
192+
DatastoreMetricsRecorder metricsRecorder) {
194193
this.datastore = datastore;
195194
this.callable = callable;
196195
this.options = options;
197-
this.datastoreMetricsRecorder = datastoreMetricsRecorder;
196+
this.metricsRecorder = metricsRecorder;
198197
this.transaction = null;
199198
}
200199

@@ -255,7 +254,7 @@ private void recordAttempt(String status, TransportOptions transportOptions) {
255254
attributes.put(
256255
TelemetryConstants.ATTRIBUTES_KEY_TRANSPORT,
257256
TelemetryConstants.getTransportName(transportOptions));
258-
datastoreMetricsRecorder.recordTransactionAttemptCount(1, attributes);
257+
metricsRecorder.recordTransactionAttemptCount(1, attributes);
259258
}
260259
}
261260

@@ -270,8 +269,7 @@ public <T> T runInTransaction(
270269
TraceUtil.Span span = otelTraceUtil.startSpan(SPAN_NAME_TRANSACTION_RUN);
271270

272271
ReadWriteTransactionCallable<T> baseCallable =
273-
new ReadWriteTransactionCallable<>(
274-
this, callable, transactionOptions, datastoreMetricsRecorder);
272+
new ReadWriteTransactionCallable<>(this, callable, transactionOptions, metricsRecorder);
275273

276274
Callable<T> transactionCallable = baseCallable;
277275
if (getOptions().getOpenTelemetryOptions().isTracingEnabled()) {
@@ -301,7 +299,7 @@ public <T> T runInTransaction(
301299
attributes.put(
302300
TelemetryConstants.ATTRIBUTES_KEY_TRANSPORT,
303301
TelemetryConstants.getTransportName(getOptions().getTransportOptions()));
304-
datastoreMetricsRecorder.recordTransactionLatency(latencyMs, attributes);
302+
metricsRecorder.recordTransactionLatency(latencyMs, attributes);
305303
span.end();
306304
}
307305
}
@@ -809,8 +807,7 @@ private <T> T runWithObservability(
809807

810808
DatastoreOptions options = getOptions();
811809
Callable<T> attemptCallable =
812-
TelemetryUtils.attemptMetricsCallable(
813-
callable, datastoreMetricsRecorder, options, methodName);
810+
TelemetryUtils.attemptMetricsCallable(callable, metricsRecorder, options, methodName);
814811
try (TraceUtil.Scope ignored = span.makeCurrent()) {
815812
return RetryHelper.runWithRetries(
816813
attemptCallable, retrySettings, exceptionHandler, options.getClock());
@@ -820,7 +817,7 @@ private <T> T runWithObservability(
820817
throw DatastoreException.translateAndThrow(e);
821818
} finally {
822819
TelemetryUtils.recordOperationMetrics(
823-
datastoreMetricsRecorder, options, operationStopwatch, methodName, operationStatus);
820+
metricsRecorder, options, operationStopwatch, methodName, operationStatus);
824821
span.end();
825822
}
826823
}

java-datastore/google-cloud-datastore/src/main/java/com/google/cloud/datastore/RetryAndTraceDatastoreRpcDecorator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class RetryAndTraceDatastoreRpcDecorator implements DatastoreRpc {
6161
private final com.google.cloud.datastore.telemetry.TraceUtil otelTraceUtil;
6262
private final RetrySettings retrySettings;
6363
private final DatastoreOptions datastoreOptions;
64-
private final DatastoreMetricsRecorder datastoreMetricsRecorder;
64+
private final DatastoreMetricsRecorder metricsRecorder;
6565

6666
@ObsoleteApi("Prefer to create RetryAndTraceDatastoreRpcDecorator via the Builder")
6767
public RetryAndTraceDatastoreRpcDecorator(
@@ -73,15 +73,15 @@ public RetryAndTraceDatastoreRpcDecorator(
7373
this.retrySettings = retrySettings;
7474
this.datastoreOptions = datastoreOptions;
7575
this.otelTraceUtil = otelTraceUtil;
76-
this.datastoreMetricsRecorder = new NoOpDatastoreMetricsRecorder();
76+
this.metricsRecorder = new NoOpDatastoreMetricsRecorder();
7777
}
7878

7979
private RetryAndTraceDatastoreRpcDecorator(Builder builder) {
8080
this.datastoreRpc = builder.datastoreRpc;
8181
this.otelTraceUtil = builder.otelTraceUtil;
8282
this.retrySettings = builder.retrySettings;
8383
this.datastoreOptions = builder.datastoreOptions;
84-
this.datastoreMetricsRecorder = builder.datastoreMetricsRecorder;
84+
this.metricsRecorder = builder.datastoreMetricsRecorder;
8585
}
8686

8787
public static Builder newBuilder() {
@@ -207,7 +207,7 @@ <O> O invokeRpc(Callable<O> block, String startSpan, String methodName) {
207207
try (TraceUtil.Scope ignored = span.makeCurrent()) {
208208
Callable<O> callable =
209209
TelemetryUtils.attemptMetricsCallable(
210-
block, datastoreMetricsRecorder, datastoreOptions, methodName);
210+
block, metricsRecorder, datastoreOptions, methodName);
211211
O result =
212212
RetryHelper.runWithRetries(
213213
callable, this.retrySettings, EXCEPTION_HANDLER, this.datastoreOptions.getClock());
@@ -219,7 +219,7 @@ <O> O invokeRpc(Callable<O> block, String startSpan, String methodName) {
219219
throw DatastoreException.translateAndThrow(e);
220220
} finally {
221221
TelemetryUtils.recordOperationMetrics(
222-
datastoreMetricsRecorder, datastoreOptions, stopwatch, methodName, operationStatus);
222+
metricsRecorder, datastoreOptions, stopwatch, methodName, operationStatus);
223223
span.end();
224224
}
225225
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static DatastoreMetricsRecorder getInstance(@Nonnull DatastoreOptions datastoreO
6464
if (customOtel == null) {
6565
customOtel = GlobalOpenTelemetry.get();
6666
}
67-
return new OpenTelemetryDatastoreMetricsRecorder(customOtel, TelemetryConstants.METRIC_PREFIX);
67+
return new OpenTelemetryDatastoreMetricsRecorder(
68+
customOtel, TelemetryConstants.METRIC_PREFIX);
6869
}
6970

7071
return new NoOpDatastoreMetricsRecorder();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
/**
2323
* A no-op implementation of {@link DatastoreMetricsRecorder}.
2424
*
25-
* <p>Used to stub out metrics instrumentation when metrics are disabled or when no valid
26-
* recorder could be initialized.
25+
* <p>Used to stub out metrics instrumentation when metrics are disabled or when no valid recorder
26+
* could be initialized.
2727
*
2828
* <p>WARNING: This class is intended for internal use only. It was made public to be used across
2929
* packages as a default. It should not be used by external customers and its API may change without

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ public class TelemetryConstants {
7171
*
7272
* <p>Cloud Monitoring is strict about label schemas: exporting a label that was not present when
7373
* the metric descriptor was first created will cause the entire {@code createTimeSeries} call to
74-
* fail. Registering OTel Views that filter to this set (see {@link DatastoreBuiltInMetricsView})
75-
* prevents unexpected labels from leaking into the export and causing silent data loss.
76-
*
77-
* <p>Using {@code AttributeKey<?>} (wildcard) rather than the raw {@code AttributeKey} type
78-
* preserves generic type safety while still allowing keys of any value type in the set.
74+
* fail.
7975
*/
8076
public static final Set<AttributeKey<?>> COMMON_ATTRIBUTES =
8177
ImmutableSet.of(

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,52 +65,44 @@ public static Map<String, String> buildMetricAttributes(
6565
* Records operation-level metrics. This method should be called after the entire operation across
6666
* all retry attempts has completed.
6767
*
68-
* <p>Metrics are recorded for all transport types (gRPC and HTTP). Previously this method only
69-
* recorded metrics for HTTP transport because gRPC metrics were collected separately through
70-
* GAX's {@code MetricsTracerFactory}. That mechanism was removed in favour of recording at this
71-
* single, transport-agnostic layer so that the built-in Cloud Monitoring exporter captures every
72-
* operation regardless of transport.
68+
* <p>Metrics are recorded for both transport types (gRPC and HTTP).
7369
*
74-
* @param datastoreMetricsRecorder The metrics recorder.
70+
* @param metricsRecorder The metrics recorder.
7571
* @param datastoreOptions The DatastoreOptions object.
7672
* @param operationStopwatch The stopwatch tracking the duration of the entire operation.
7773
* @param methodName The name of the API method.
7874
* @param status The final status of the operation after all retries.
7975
*/
8076
public static void recordOperationMetrics(
81-
DatastoreMetricsRecorder datastoreMetricsRecorder,
77+
DatastoreMetricsRecorder metricsRecorder,
8278
DatastoreOptions datastoreOptions,
8379
Stopwatch operationStopwatch,
8480
String methodName,
8581
String status) {
8682
if (methodName != null) {
8783
Map<String, String> attributes = buildMetricAttributes(datastoreOptions, methodName, status);
88-
datastoreMetricsRecorder.recordOperationLatency(
84+
metricsRecorder.recordOperationLatency(
8985
operationStopwatch.elapsed(TimeUnit.MILLISECONDS), attributes);
90-
datastoreMetricsRecorder.recordOperationCount(1, attributes);
86+
metricsRecorder.recordOperationCount(1, attributes);
9187
}
9288
}
9389

9490
/**
9591
* Wraps a callable with logic to record attempt-level metrics. Attempt metrics are recorded for
9692
* each individual execution of the callable, regardless of whether it succeeds or fails.
9793
*
98-
* <p>Metrics are recorded for all transport types (gRPC and HTTP). Previously this wrapper only
99-
* recorded metrics for HTTP transport because gRPC metrics were collected separately through
100-
* GAX's {@code MetricsTracerFactory}. That mechanism was removed in favour of recording at this
101-
* single, transport-agnostic layer so that the built-in Cloud Monitoring exporter captures every
102-
* attempt regardless of transport.
94+
* <p>Metrics are recorded for both transport types (gRPC and HTTP).
10395
*
10496
* @param callable The original callable to execute.
105-
* @param datastoreMetricsRecorder The metrics recorder.
97+
* @param metricsRecorder The metrics recorder.
10698
* @param datastoreOptions The DatastoreOptions object.
10799
* @param methodName The name of the API method.
108100
* @param <T> The return type of the callable.
109101
* @return A wrapped callable that includes attempt-level metrics recording.
110102
*/
111103
public static <T> Callable<T> attemptMetricsCallable(
112104
Callable<T> callable,
113-
DatastoreMetricsRecorder datastoreMetricsRecorder,
105+
DatastoreMetricsRecorder metricsRecorder,
114106
DatastoreOptions datastoreOptions,
115107
String methodName) {
116108
return () -> {
@@ -126,9 +118,8 @@ public static <T> Callable<T> attemptMetricsCallable(
126118
} finally {
127119
Map<String, String> attributes =
128120
buildMetricAttributes(datastoreOptions, methodName, status);
129-
datastoreMetricsRecorder.recordAttemptLatency(
130-
stopwatch.elapsed(TimeUnit.MILLISECONDS), attributes);
131-
datastoreMetricsRecorder.recordAttemptCount(1, attributes);
121+
metricsRecorder.recordAttemptLatency(stopwatch.elapsed(TimeUnit.MILLISECONDS), attributes);
122+
metricsRecorder.recordAttemptCount(1, attributes);
132123
}
133124
};
134125
}

0 commit comments

Comments
 (0)