Skip to content

Commit 05d20aa

Browse files
committed
chore: Clean up the code
1 parent 481e613 commit 05d20aa

6 files changed

Lines changed: 29 additions & 15 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public OpenTelemetry createOpenTelemetry(
131131
*
132132
* @return the detected location, or "global" if detection fails.
133133
*/
134-
public String detectClientLocation() {
134+
String detectClientLocation() {
135135
if (location == null) {
136136
location = "global";
137137
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,47 @@ class CompositeDatastoreMetricsRecorder implements DatastoreMetricsRecorder {
3939
this.recorders = recorders;
4040
}
4141

42+
/** {@inheritDoc} */
4243
@Override
4344
public void recordTransactionLatency(double latencyMs, Map<String, String> attributes) {
4445
for (DatastoreMetricsRecorder recorder : recorders) {
4546
recorder.recordTransactionLatency(latencyMs, attributes);
4647
}
4748
}
4849

50+
/** {@inheritDoc} */
4951
@Override
5052
public void recordTransactionAttemptCount(long count, Map<String, String> attributes) {
5153
for (DatastoreMetricsRecorder recorder : recorders) {
5254
recorder.recordTransactionAttemptCount(count, attributes);
5355
}
5456
}
5557

58+
/** {@inheritDoc} */
5659
@Override
5760
public void recordAttemptLatency(double latencyMs, Map<String, String> attributes) {
5861
for (DatastoreMetricsRecorder recorder : recorders) {
5962
recorder.recordAttemptLatency(latencyMs, attributes);
6063
}
6164
}
6265

66+
/** {@inheritDoc} */
6367
@Override
6468
public void recordAttemptCount(long count, Map<String, String> attributes) {
6569
for (DatastoreMetricsRecorder recorder : recorders) {
6670
recorder.recordAttemptCount(count, attributes);
6771
}
6872
}
6973

74+
/** {@inheritDoc} */
7075
@Override
7176
public void recordOperationLatency(double latencyMs, Map<String, String> attributes) {
7277
for (DatastoreMetricsRecorder recorder : recorders) {
7378
recorder.recordOperationLatency(latencyMs, attributes);
7479
}
7580
}
7681

82+
/** {@inheritDoc} */
7783
@Override
7884
public void recordOperationCount(long count, Map<String, String> attributes) {
7985
for (DatastoreMetricsRecorder recorder : recorders) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ private DatastoreBuiltInMetricsView() {}
7171
* <p>This method acts as the central configuration point for the metrics pipeline, stitching
7272
* together the recording (SDK), the processing (Views), and the delivery (Exporter).
7373
*
74+
* <p>Views are scoped to the SdkMeterProvider they are registered on. This method is called
75+
* exclusively from BuiltInDatastoreMetricsProvider, which constructs a private SdkMeterProvider
76+
* for the built-in Cloud Monitoring export path. A user-provided OpenTelemetry instance has its
77+
* own independent MeterProvider, so these views never affect user-configured backends.
78+
*
7479
* @param metricExporter the exporter to use for metrics.
7580
* @param builder the builder to register views and the {@link PeriodicMetricReader} on.
7681
*/
77-
// Views are scoped to the SdkMeterProvider they are registered on. This method is called
78-
// exclusively from BuiltInDatastoreMetricsProvider, which constructs a private SdkMeterProvider
79-
// for the built-in Cloud Monitoring export path. A user-provided OpenTelemetry instance has its
80-
// own independent MeterProvider, so these views never affect user-configured backends.
8182
static void registerBuiltinMetrics(
8283
MetricExporter metricExporter, SdkMeterProviderBuilder builder) {
8384
registerGaxViews(builder);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ static List<TimeSeries> convertToDatastoreTimeSeries(
8585
// Metrics should already been filtered for Gax and Datastore related ones
8686
for (MetricData metricData : collection) {
8787
// TODO(b/405457573): The monitored resource is currently written to `global` because the
88-
// Firestore
89-
// namespace in Cloud Monitoring has not been deployed yet. Once the namespace is available,
90-
// database_id and location labels should be added here using RESOURCE_LABEL_DATABASE_ID
91-
// and RESOURCE_LABEL_LOCATION respectively.
88+
// Firestore namespace in Cloud Monitoring has not been deployed yet. Once the namespace
89+
// is available, database_id and location labels should be added here using
90+
// RESOURCE_LABEL_DATABASE_ID and RESOURCE_LABEL_LOCATION respectively.
9291

9392
// Map OTel resource attributes to the specific monitored resource labels.
9493
MonitoredResource.Builder monitoredResourceBuilder =

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class OpenTelemetryDatastoreMetricsRecorder extends OpenTelemetryMetricsRecorder
6666
/**
6767
* Creates a recorder, specifying whether this instance owns the {@link OpenTelemetry} lifecycle.
6868
*
69+
* <p>Note: Standard GAX RPC metrics (operation_latency, attempt_latency, etc.) are handled by the
70+
* base OpenTelemetryMetricsRecorder class. Those metrics are inherited from the parent classes.
71+
* However, the internal metrics expect plural suffixes (e.g. `latencies` instead of `latency`).
72+
* The discrepancy between the singular GAX names and the plural internal Cloud Monitoring names
73+
* is handled by configuring OpenTelemetry Views.
74+
*
6975
* @param isBuiltIn {@code true} if this recorder created the instance and should shut it down on
7076
* {@link #close()}; {@code false} if the user provided it.
7177
*/
@@ -75,12 +81,6 @@ class OpenTelemetryDatastoreMetricsRecorder extends OpenTelemetryMetricsRecorder
7581
this.openTelemetry = openTelemetry;
7682
this.isBuiltIn = isBuiltIn;
7783

78-
// Note: Standard GAX RPC metrics (operation_latency, attempt_latency, etc.) are handled by the
79-
// base OpenTelemetryMetricsRecorder class. Those metrics are inherited from the parent classes.
80-
// However, the internal metrics expect plural suffixes (e.g. `latencies` instead of `latency`).
81-
// The discrepancy between the singular GAX names and the plural internal Cloud Monitoring names
82-
// is handled by configuring OpenTelemetry Views.
83-
8484
Meter meter = openTelemetry.getMeter(TelemetryConstants.DATASTORE_METER_NAME);
8585

8686
this.transactionLatency =

java-datastore/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.google.api.gax.grpc.ChannelPoolSettings;
2727
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
28+
import com.google.auth.Credentials;
2829
import com.google.cloud.NoCredentials;
2930
import com.google.cloud.datastore.spi.DatastoreRpcFactory;
3031
import com.google.cloud.datastore.spi.v1.DatastoreRpc;
@@ -321,10 +322,17 @@ public void builtInMetricsExport_isDisabledByDefault() {
321322

322323
@Test
323324
public void bothBackendsActive_recorderIsComposite() {
325+
Credentials credentials = EasyMock.createMock(Credentials.class);
326+
EasyMock.expect(credentials.getMetricsCredentialType())
327+
.andReturn(com.google.auth.CredentialTypeForMetrics.DO_NOT_SEND)
328+
.anyTimes();
329+
EasyMock.replay(credentials);
330+
324331
DatastoreOptions options =
325332
DatastoreOptions.newBuilder()
326333
.setProjectId(PROJECT_ID)
327334
.setDatabaseId(DATABASE_ID)
335+
.setCredentials(credentials)
328336
.setOpenTelemetryOptions(
329337
DatastoreOpenTelemetryOptions.newBuilder()
330338
.setMetricsEnabled(true)

0 commit comments

Comments
 (0)