[ https://issues.apache.org/jira/browse/BEAM-8472?focusedWorklogId=338410&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-338410 ]
ASF GitHub Bot logged work on BEAM-8472: ---------------------------------------- Author: ASF GitHub Bot Created on: 04/Nov/19 23:42 Start Date: 04/Nov/19 23:42 Worklog Time Spent: 10m Work Description: ibzib commented on pull request #9974: [BEAM-8472] Get default GCP region from gcloud (Java) URL: https://github.com/apache/beam/pull/9974#discussion_r342324597 ########## File path: runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java ########## @@ -357,6 +357,50 @@ public static DataflowRunner fromOptions(PipelineOptions options) { return new DataflowRunner(dataflowOptions); } + /** + * Get a default value for Google Cloud region according to + * https://cloud.google.com/compute/docs/gcloud-compute/#default-properties. If no other default + * can be found, returns "us-central1". + */ + static String getDefaultGcpRegion() { + String environmentRegion = System.getenv("CLOUDSDK_COMPUTE_REGION"); + if (environmentRegion != null && !environmentRegion.isEmpty()) { + LOG.info("Using default GCP region {} from $CLOUDSDK_COMPUTE_REGION", environmentRegion); + return environmentRegion; + } + try { + ProcessBuilder pb = + new ProcessBuilder(Arrays.asList("gcloud", "config", "get-value", "compute/region")); + Process process = pb.start(); + BufferedReader reader = + new BufferedReader( + new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)); + BufferedReader errorReader = + new BufferedReader( + new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8)); + process.waitFor(1, TimeUnit.SECONDS); Review comment: > Is 1 second enough? Tests on my machine (in debug mode) indicated it took on average around 0.25 seconds, including reading the output stream after. I have bumped the timeout to 2s just to make double sure. > Should we check the return value of this call? Not sure it matters, since I think it should interrupt the process after the time limit has passed, but it couldn't hurt to check anyway. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 338410) Time Spent: 2h (was: 1h 50m) > Get default GCP region from gcloud > ---------------------------------- > > Key: BEAM-8472 > URL: https://issues.apache.org/jira/browse/BEAM-8472 > Project: Beam > Issue Type: Improvement > Components: runner-dataflow > Reporter: Kyle Weaver > Assignee: Kyle Weaver > Priority: Major > Time Spent: 2h > Remaining Estimate: 0h > > Currently, we default to us-central1 if --region flag is not set. The Google > Cloud SDK generally tries to get a default value in this case for > convenience, which we should follow. > [https://cloud.google.com/compute/docs/gcloud-compute/#order_of_precedence_for_default_properties] -- This message was sent by Atlassian Jira (v8.3.4#803005)