Skip to content

Commit 67ebc99

Browse files
committed
Modified Shutdown and Flush as per the review comments
1 parent 4d56672 commit 67ebc99

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerCloudMonitoringExporter.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import io.opentelemetry.sdk.metrics.export.MetricExporter;
4444
import java.io.IOException;
4545
import java.util.ArrayList;
46-
import java.util.Arrays;
4746
import java.util.Collection;
4847
import java.util.List;
4948
import java.util.concurrent.atomic.AtomicBoolean;
@@ -78,7 +77,6 @@ class SpannerCloudMonitoringExporter implements MetricExporter {
7877
private CompletableResultCode lastExportCode;
7978
private final MetricServiceClient client;
8079
private final String spannerProjectId;
81-
private final AtomicBoolean isShutdown = new AtomicBoolean(false);
8280

8381
static SpannerCloudMonitoringExporter create(String projectId, @Nullable Credentials credentials)
8482
throws IOException {
@@ -109,7 +107,7 @@ static SpannerCloudMonitoringExporter create(String projectId, @Nullable Credent
109107

110108
@Override
111109
public CompletableResultCode export(Collection<MetricData> collection) {
112-
if (isShutdown.get()) {
110+
if (client.isShutdown()) {
113111
logger.log(Level.WARNING, "Exporter is shut down");
114112
return CompletableResultCode.ofFailure();
115113
}
@@ -207,31 +205,24 @@ private ApiFuture<List<Empty>> exportTimeSeriesInBatch(
207205

208206
@Override
209207
public CompletableResultCode flush() {
210-
if (lastExportCode != null) {
211-
return lastExportCode;
212-
}
213208
return CompletableResultCode.ofSuccess();
214209
}
215210

216211
@Override
217212
public CompletableResultCode shutdown() {
218-
if (!isShutdown.compareAndSet(false, true)) {
213+
if (client.isShutdown()) {
219214
logger.log(Level.WARNING, "shutdown is called multiple times");
220215
return CompletableResultCode.ofSuccess();
221216
}
222-
CompletableResultCode flushResult = flush();
223217
CompletableResultCode shutdownResult = new CompletableResultCode();
224-
flushResult.whenComplete(
225-
() -> {
226-
try {
227-
client.shutdown();
228-
shutdownResult.succeed();
229-
} catch (Throwable e) {
230-
logger.log(Level.WARNING, "failed to shutdown the monitoring client", e);
231-
shutdownResult.fail();
232-
}
233-
});
234-
return CompletableResultCode.ofAll(Arrays.asList(flushResult, shutdownResult));
218+
try {
219+
client.shutdown();
220+
shutdownResult.succeed();
221+
} catch (Throwable e) {
222+
logger.log(Level.WARNING, "failed to shutdown the monitoring client", e);
223+
shutdownResult.fail();
224+
}
225+
return shutdownResult;
235226
}
236227

237228
/**

0 commit comments

Comments
 (0)