Make MetricExporter shutdown method returns CompletableResultCode. (#2321)

This commit is contained in:
dengliming 2020-12-17 01:11:50 +08:00 committed by GitHub
parent 86c763827a
commit 718f512701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 7 deletions

View File

@ -44,8 +44,9 @@ public final class LoggingMetricExporter implements MetricExporter {
}
@Override
public void shutdown() {
public CompletableResultCode shutdown() {
// no-op
this.flush();
return CompletableResultCode.ofSuccess();
}
}

View File

@ -153,11 +153,12 @@ public final class OtlpGrpcMetricExporter implements MetricExporter {
* cancelled. The channel is forcefully closed after a timeout.
*/
@Override
public void shutdown() {
public CompletableResultCode shutdown() {
try {
managedChannel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
logger.log(Level.WARNING, "Failed to shutdown the gRPC channel", e);
}
return CompletableResultCode.ofSuccess();
}
}

View File

@ -76,5 +76,7 @@ class FakeMetricExporter implements MetricExporter {
}
@Override
public void shutdown() {}
public CompletableResultCode shutdown() {
return CompletableResultCode.ofSuccess();
}
}

View File

@ -36,6 +36,10 @@ public interface MetricExporter {
*/
CompletableResultCode flush();
/** Called when the associated IntervalMetricReader is shutdown. */
void shutdown();
/**
* Called when the associated IntervalMetricReader is shutdown.
*
* @return a {@link CompletableResultCode} which is completed when shutdown completes.
*/
CompletableResultCode shutdown();
}

View File

@ -166,8 +166,9 @@ class IntervalMetricReaderTest {
}
@Override
public void shutdown() {
public CompletableResultCode shutdown() {
hasShutdown.set(true);
return CompletableResultCode.ofSuccess();
}
/**

View File

@ -119,8 +119,9 @@ public final class InMemoryMetricExporter implements MetricExporter {
* CompletableResultCode.ofFailure()}
*/
@Override
public void shutdown() {
public CompletableResultCode shutdown() {
isStopped = true;
finishedMetricItems.clear();
return CompletableResultCode.ofSuccess();
}
}