1616package com .google .cloud .bigtable .data .v2 .stub .metrics ;
1717
1818import com .google .api .MonitoredResource ;
19+ import com .google .api .core .ApiFuture ;
1920import com .google .api .gax .core .FixedCredentialsProvider ;
2021import com .google .auth .Credentials ;
2122import com .google .cloud .monitoring .v3 .MetricServiceClient ;
2526import com .google .monitoring .v3 .CreateTimeSeriesRequest ;
2627import com .google .monitoring .v3 .ProjectName ;
2728import com .google .monitoring .v3 .TimeSeries ;
29+ import com .google .protobuf .Empty ;
2830import io .opentelemetry .sdk .common .CompletableResultCode ;
2931import io .opentelemetry .sdk .metrics .InstrumentType ;
3032import io .opentelemetry .sdk .metrics .data .AggregationTemporality ;
@@ -47,6 +49,7 @@ final class BigtableCloudMonitoringExporter implements MetricExporter {
4749 private final String projectId ;
4850 private final String taskId ;
4951 private final MonitoredResource monitoredResource ;
52+ private boolean isShutdown = false ;
5053
5154 private static final String RESOURCE_TYPE = "bigtable_client_raw" ;
5255
@@ -78,6 +81,9 @@ static BigtableCloudMonitoringExporter create(String projectId, Credentials cred
7881
7982 @ Override
8083 public CompletableResultCode export (Collection <MetricData > collection ) {
84+ if (isShutdown ) {
85+ return CompletableResultCode .ofFailure ();
86+ }
8187 Preconditions .checkArgument (
8288 collection .stream ()
8389 .flatMap (metricData -> metricData .getData ().getPoints ().stream ())
@@ -102,7 +108,7 @@ public CompletableResultCode export(Collection<MetricData> collection) {
102108 .addAllTimeSeries (timeSeries )
103109 .build ();
104110
105- this .client .createServiceTimeSeries (request );
111+ this .client .createServiceTimeSeriesCallable (). futureCall (request );
106112 }
107113
108114 return CompletableResultCode .ofSuccess ();
@@ -116,6 +122,7 @@ public CompletableResultCode flush() {
116122 @ Override
117123 public CompletableResultCode shutdown () {
118124 client .shutdown ();
125+ isShutdown = true ;
119126 return CompletableResultCode .ofSuccess ();
120127 }
121128
0 commit comments