Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

fix: Shutdown Stackdriver MetricServiceClient properly #2091

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
## Unreleased

- fix: Shutdown `MetricServiceClient` properly on `StackdriverStatsExporter.unregister()` (#2007)

## 0.28.3 - 2021-01-12

- fix: Return public access to unsafe `ContextUtils` api. Remove bincompat issue from 0.27.1. (#2072)
Expand Down
Expand Up @@ -77,6 +77,10 @@ public final class StackdriverStatsExporter {
@Nullable
private static StackdriverStatsExporter instance = null;

@GuardedBy("monitor")
@Nullable
private static MetricServiceClient metricServiceClient = null;

private static final String EXPORTER_SPAN_NAME = "ExportMetricsToStackdriver";

// See io.grpc.internal.GrpcUtil.USER_AGENT_KEY
Expand Down Expand Up @@ -392,10 +396,13 @@ private static void createInternal(
throws IOException {
synchronized (monitor) {
checkState(instance == null, "Stackdriver stats exporter is already created.");
MetricServiceClient client =
stub == null
? createMetricServiceClient(credentials, deadline)
: MetricServiceClient.create(stub);
final MetricServiceClient client;
punya marked this conversation as resolved.
Show resolved Hide resolved
if (stub == null) {
metricServiceClient = createMetricServiceClient(credentials, deadline);
client = metricServiceClient;
} else {
client = MetricServiceClient.create(stub);
}
instance =
new StackdriverStatsExporter(
projectId,
Expand Down Expand Up @@ -445,6 +452,10 @@ public static void unregister() {
instance.intervalMetricReader.stop();
}
instance = null;
if (metricServiceClient != null) {
metricServiceClient.close();
metricServiceClient = null;
}
}
}
}