@@ -116,6 +116,9 @@ public final class GrpcStorageOptions extends StorageOptions
116
116
private final GrpcRetryAlgorithmManager retryAlgorithmManager ;
117
117
private final Duration terminationAwaitDuration ;
118
118
private final boolean attemptDirectPath ;
119
+ private final boolean enableGrpcClientMetrics ;
120
+
121
+ private final boolean grpcClientMetricsManuallyEnabled ;
119
122
private final GrpcInterceptorProvider grpcInterceptorProvider ;
120
123
private final BlobWriteSessionConfig blobWriteSessionConfig ;
121
124
@@ -129,6 +132,8 @@ private GrpcStorageOptions(Builder builder, GrpcStorageDefaults serviceDefaults)
129
132
MoreObjects .firstNonNull (
130
133
builder .terminationAwaitDuration , serviceDefaults .getTerminationAwaitDuration ());
131
134
this .attemptDirectPath = builder .attemptDirectPath ;
135
+ this .enableGrpcClientMetrics = builder .enableGrpcClientMetrics ;
136
+ this .grpcClientMetricsManuallyEnabled = builder .grpcMetricsManuallyEnabled ;
132
137
this .grpcInterceptorProvider = builder .grpcInterceptorProvider ;
133
138
this .blobWriteSessionConfig = builder .blobWriteSessionConfig ;
134
139
}
@@ -287,6 +292,16 @@ private Tuple<StorageSettings, Opts<UserProject>> resolveSettingsAndOpts() throw
287
292
if (scheme .equals ("http" )) {
288
293
channelProviderBuilder .setChannelConfigurator (ManagedChannelBuilder ::usePlaintext );
289
294
}
295
+
296
+ if (enableGrpcClientMetrics ) {
297
+ OpenTelemetryBootstrappingUtils .enableGrpcMetrics (
298
+ channelProviderBuilder ,
299
+ endpoint ,
300
+ this .getProjectId (),
301
+ this .getUniverseDomain (),
302
+ !grpcClientMetricsManuallyEnabled );
303
+ }
304
+
290
305
builder .setTransportChannelProvider (channelProviderBuilder .build ());
291
306
RetrySettings baseRetrySettings = getRetrySettings ();
292
307
RetrySettings readRetrySettings =
@@ -350,6 +365,7 @@ public int hashCode() {
350
365
retryAlgorithmManager ,
351
366
terminationAwaitDuration ,
352
367
attemptDirectPath ,
368
+ enableGrpcClientMetrics ,
353
369
grpcInterceptorProvider ,
354
370
blobWriteSessionConfig ,
355
371
baseHashCode ());
@@ -365,6 +381,7 @@ public boolean equals(Object o) {
365
381
}
366
382
GrpcStorageOptions that = (GrpcStorageOptions ) o ;
367
383
return attemptDirectPath == that .attemptDirectPath
384
+ && enableGrpcClientMetrics == that .enableGrpcClientMetrics
368
385
&& Objects .equals (retryAlgorithmManager , that .retryAlgorithmManager )
369
386
&& Objects .equals (terminationAwaitDuration , that .terminationAwaitDuration )
370
387
&& Objects .equals (grpcInterceptorProvider , that .grpcInterceptorProvider )
@@ -408,11 +425,15 @@ public static final class Builder extends StorageOptions.Builder {
408
425
private StorageRetryStrategy storageRetryStrategy ;
409
426
private Duration terminationAwaitDuration ;
410
427
private boolean attemptDirectPath = GrpcStorageDefaults .INSTANCE .isAttemptDirectPath ();
428
+ private boolean enableGrpcClientMetrics =
429
+ GrpcStorageDefaults .INSTANCE .isEnableGrpcClientMetrics ();
411
430
private GrpcInterceptorProvider grpcInterceptorProvider =
412
431
GrpcStorageDefaults .INSTANCE .grpcInterceptorProvider ();
413
432
private BlobWriteSessionConfig blobWriteSessionConfig =
414
433
GrpcStorageDefaults .INSTANCE .getDefaultStorageWriterConfig ();
415
434
435
+ private boolean grpcMetricsManuallyEnabled = false ;
436
+
416
437
Builder () {}
417
438
418
439
Builder (StorageOptions options ) {
@@ -421,6 +442,7 @@ public static final class Builder extends StorageOptions.Builder {
421
442
this .storageRetryStrategy = gso .getRetryAlgorithmManager ().retryStrategy ;
422
443
this .terminationAwaitDuration = gso .getTerminationAwaitDuration ();
423
444
this .attemptDirectPath = gso .attemptDirectPath ;
445
+ this .enableGrpcClientMetrics = gso .enableGrpcClientMetrics ;
424
446
this .grpcInterceptorProvider = gso .grpcInterceptorProvider ;
425
447
this .blobWriteSessionConfig = gso .blobWriteSessionConfig ;
426
448
}
@@ -454,6 +476,21 @@ public GrpcStorageOptions.Builder setAttemptDirectPath(boolean attemptDirectPath
454
476
this .attemptDirectPath = attemptDirectPath ;
455
477
return this ;
456
478
}
479
+ /**
480
+ * Option for whether this client should emit internal gRPC client internal metrics to Cloud
481
+ * Monitoring. To disable metric reporting, set this to false. True by default. Emitting metrics
482
+ * is free and requires minimal CPU and memory.
483
+ *
484
+ * @since 2.41.0 This new api is in preview and is subject to breaking changes.
485
+ */
486
+ @ BetaApi
487
+ public GrpcStorageOptions .Builder setEnableGrpcClientMetrics (boolean enableGrpcClientMetrics ) {
488
+ this .enableGrpcClientMetrics = enableGrpcClientMetrics ;
489
+ if (enableGrpcClientMetrics ) {
490
+ grpcMetricsManuallyEnabled = true ;
491
+ }
492
+ return this ;
493
+ }
457
494
458
495
/** @since 2.14.0 This new api is in preview and is subject to breaking changes. */
459
496
@ BetaApi
@@ -660,6 +697,12 @@ public boolean isAttemptDirectPath() {
660
697
return false ;
661
698
}
662
699
700
+ /** @since 2.41.0 This new api is in preview and is subject to breaking changes. */
701
+ @ BetaApi
702
+ public boolean isEnableGrpcClientMetrics () {
703
+ return true ;
704
+ }
705
+
663
706
/** @since 2.22.3 This new api is in preview and is subject to breaking changes. */
664
707
@ BetaApi
665
708
public GrpcInterceptorProvider grpcInterceptorProvider () {
0 commit comments