Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
Merged
Changes from all 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 @@ -20,6 +20,7 @@
import com.google.cloud.monitoring.v3.UptimeCheckServiceClient;
import com.google.cloud.monitoring.v3.UptimeCheckServiceClient.ListUptimeCheckConfigsPagedResponse;
import com.google.cloud.monitoring.v3.UptimeCheckServiceClient.ListUptimeCheckIpsPagedResponse;
import com.google.cloud.monitoring.v3.UptimeCheckServiceSettings;
import com.google.common.base.Strings;
import com.google.monitoring.v3.CreateUptimeCheckConfigRequest;
import com.google.monitoring.v3.ListUptimeCheckConfigsRequest;
Expand Down Expand Up @@ -82,8 +83,9 @@ public class UptimeSample {
.addOption(DISPLAY_NAME_OPTION)
.addOption(HOST_NAME_OPTION)
.addOption(PATH_NAME_OPTION);

private static final CommandLineParser PARSER = new DefaultParser();
private static final org.threeten.bp.Duration MAX_RECONNECT_BACKOFF_TIME =
org.threeten.bp.Duration.ofSeconds(60);

public static void main(String... args) throws IOException {
CommandLine cl;
Expand Down Expand Up @@ -126,7 +128,7 @@ public static void main(String... args) throws IOException {
listUptimeChecks(projectId);
break;
case "listips":
listUptimeCheckIPs();
listUptimeCheckIps();
break;
case "get":
getUptimeCheckConfig(
Expand Down Expand Up @@ -214,7 +216,7 @@ private static void listUptimeChecks(String projectId) throws IOException {
// [END monitoring_uptime_check_list_configs]]

// [START monitoring_uptime_check_list_ips]]
private static void listUptimeCheckIPs() throws IOException {
private static void listUptimeCheckIps() throws IOException {
try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
ListUptimeCheckIpsPagedResponse response =
client.listUptimeCheckIps(ListUptimeCheckIpsRequest.newBuilder().build());
Expand All @@ -230,7 +232,31 @@ private static void listUptimeCheckIPs() throws IOException {

// [START monitoring_uptime_check_get]]
private static void getUptimeCheckConfig(String projectId, String checkName) throws IOException {
try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
// Create UptimeCheckServiceSettings instance for add retry mechanism
UptimeCheckServiceSettings.Builder uptimeCheckServiceSettingsBuilder =
UptimeCheckServiceSettings.newBuilder();
uptimeCheckServiceSettingsBuilder
.getUptimeCheckConfigSettings()
.setRetrySettings(
uptimeCheckServiceSettingsBuilder
.getUptimeCheckConfigSettings()
.getRetrySettings()
.toBuilder()
.setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(100L))
.setRetryDelayMultiplier(1.3)
.setMaxRetryDelay(MAX_RECONNECT_BACKOFF_TIME)
.setInitialRpcTimeout(MAX_RECONNECT_BACKOFF_TIME)
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(MAX_RECONNECT_BACKOFF_TIME)
.setTotalTimeout(MAX_RECONNECT_BACKOFF_TIME)
.setMaxAttempts(6)
.build());
UptimeCheckServiceSettings uptimeCheckServiceSettings =
uptimeCheckServiceSettingsBuilder.build();

// create UptimeCheckServiceClient with retry setting
try (UptimeCheckServiceClient client =
UptimeCheckServiceClient.create(uptimeCheckServiceSettings)) {
String fullCheckName = UptimeCheckConfigName.format(projectId, checkName);
UptimeCheckConfig config = client.getUptimeCheckConfig(fullCheckName);
if (config != null) {
Expand Down