|
43 | 43 | import io.opentelemetry.sdk.metrics.export.MetricExporter; |
44 | 44 | import java.io.IOException; |
45 | 45 | import java.util.ArrayList; |
46 | | -import java.util.Arrays; |
47 | 46 | import java.util.Collection; |
48 | 47 | import java.util.List; |
49 | 48 | import java.util.concurrent.atomic.AtomicBoolean; |
@@ -78,7 +77,6 @@ class SpannerCloudMonitoringExporter implements MetricExporter { |
78 | 77 | private CompletableResultCode lastExportCode; |
79 | 78 | private final MetricServiceClient client; |
80 | 79 | private final String spannerProjectId; |
81 | | - private final AtomicBoolean isShutdown = new AtomicBoolean(false); |
82 | 80 |
|
83 | 81 | static SpannerCloudMonitoringExporter create(String projectId, @Nullable Credentials credentials) |
84 | 82 | throws IOException { |
@@ -109,7 +107,7 @@ static SpannerCloudMonitoringExporter create(String projectId, @Nullable Credent |
109 | 107 |
|
110 | 108 | @Override |
111 | 109 | public CompletableResultCode export(Collection<MetricData> collection) { |
112 | | - if (isShutdown.get()) { |
| 110 | + if (client.isShutdown()) { |
113 | 111 | logger.log(Level.WARNING, "Exporter is shut down"); |
114 | 112 | return CompletableResultCode.ofFailure(); |
115 | 113 | } |
@@ -207,31 +205,24 @@ private ApiFuture<List<Empty>> exportTimeSeriesInBatch( |
207 | 205 |
|
208 | 206 | @Override |
209 | 207 | public CompletableResultCode flush() { |
210 | | - if (lastExportCode != null) { |
211 | | - return lastExportCode; |
212 | | - } |
213 | 208 | return CompletableResultCode.ofSuccess(); |
214 | 209 | } |
215 | 210 |
|
216 | 211 | @Override |
217 | 212 | public CompletableResultCode shutdown() { |
218 | | - if (!isShutdown.compareAndSet(false, true)) { |
| 213 | + if (client.isShutdown()) { |
219 | 214 | logger.log(Level.WARNING, "shutdown is called multiple times"); |
220 | 215 | return CompletableResultCode.ofSuccess(); |
221 | 216 | } |
222 | | - CompletableResultCode flushResult = flush(); |
223 | 217 | 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; |
235 | 226 | } |
236 | 227 |
|
237 | 228 | /** |
|
0 commit comments