Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcp-o11y: add sleep in Observability close() #9972

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/** The main class for gRPC Google Cloud Platform Observability features. */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8869")
public final class GcpObservability implements AutoCloseable {

private static final Logger logger = Logger.getLogger(GcpObservability.class.getName());
private static final int METRICS_EXPORT_INTERVAL = 30;
@VisibleForTesting
static final ImmutableSet<String> SERVICES_TO_EXCLUDE = ImmutableSet.of(
Expand Down Expand Up @@ -117,6 +122,15 @@ public void close() {
throw new IllegalStateException("GcpObservability already closed!");
}
sink.close();
if (config.isEnableCloudMonitoring() || config.isEnableCloudTracing()) {
try {
// Sleeping before shutdown to ensure all metrics and traces are flushed
Thread.sleep(
TimeUnit.MILLISECONDS.convert(2 * METRICS_EXPORT_INTERVAL, TimeUnit.SECONDS));
} catch (InterruptedException e) {
logger.log(Level.SEVERE, "Caught exception during sleep", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Thread.currentThread().interrupt()

}
}
instance = null;
}
}
Expand Down