-
Notifications
You must be signed in to change notification settings - Fork 106
feat(bigtable): populate reasons on why direct access was not accessible #2905
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
Open
sushanb
wants to merge
2
commits into
main
Choose a base branch
from
populate_reason
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/dp/GCECheck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.internal.dp; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Paths; | ||
|
|
||
| @InternalApi | ||
| class GCECheck { | ||
|
|
||
| static boolean isRunningOnGCP() { | ||
| if (!"Linux".equals(System.getProperty("os.name"))) { | ||
| return false; | ||
| } | ||
| return getSystemProductName().contains("Google"); | ||
| } | ||
|
|
||
| private static String getSystemProductName() { | ||
| try { | ||
| return new String( | ||
| Files.readAllBytes(Paths.get("/sys/class/dmi/id/product_name")), StandardCharsets.UTF_8); | ||
| } catch (IOException e) { | ||
| return ""; | ||
| } | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
...gtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/dp/LoopBackInterface.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.internal.dp; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import java.net.InetAddress; | ||
| import java.net.NetworkInterface; | ||
| import java.util.Enumeration; | ||
|
|
||
| /** | ||
| * This class verifies two main things: The OS has a functioning loopback interface (lo) with | ||
| * standard localhost IPs configured. | ||
| */ | ||
| @InternalApi | ||
| class LoopBackInterface { | ||
|
|
||
| static boolean isUp() throws Exception { | ||
| Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); | ||
| while (interfaces.hasMoreElements()) { | ||
| NetworkInterface iface = interfaces.nextElement(); | ||
| if (iface.isLoopback() && iface.isUp()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Verifies that the standard IPv4 localhost address (127.0.0.1) is bound to a loopback interface. | ||
| */ | ||
| static boolean hasLocalIpv4Loopback() throws Exception { | ||
| return checkLocalLoopbackAddress("127.0.0.1"); | ||
| } | ||
|
|
||
| /** Verifies that the standard IPv6 localhost address (::1) is bound to a loopback interface. */ | ||
| static boolean hasLocalIpv6Loopback() throws Exception { | ||
| return checkLocalLoopbackAddress("::1"); | ||
| } | ||
|
|
||
| private static boolean checkLocalLoopbackAddress(String expectedIp) throws Exception { | ||
| InetAddress expected = InetAddress.getByName(expectedIp); | ||
| Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); | ||
| while (interfaces.hasMoreElements()) { | ||
| NetworkInterface iface = interfaces.nextElement(); | ||
| if (iface.isLoopback() && iface.isUp()) { | ||
| Enumeration<InetAddress> addrs = iface.getInetAddresses(); | ||
| while (addrs.hasMoreElements()) { | ||
| if (addrs.nextElement().equals(expected)) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
98 changes: 98 additions & 0 deletions
98
...-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/dp/MetadataServer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.internal.dp; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.InetAddress; | ||
| import java.net.URL; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| /** | ||
| * Verifies that the VM can reach the GCP metadata server and checks whether GCP has successfully | ||
| * assigned DirectPath-eligible IPv4 or IPv6 addresses to the instance's primary network interface | ||
| * (nic0). | ||
| */ | ||
| @InternalApi | ||
| class MetadataServer { | ||
| private static final String METADATA_BASE_URL = | ||
| "http://metadata.google.internal/computeMetadata/v1/"; | ||
| private static final String METADATA_IPV4_URL = | ||
| "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip"; | ||
| private static final String METADATA_IPV6_URL = | ||
| "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ipv6s"; | ||
|
|
||
| private static final int REACHABILITY_TIMEOUT_MS = 2000; | ||
| private static final int FETCH_IP_TIMEOUT_MS = 5000; | ||
|
|
||
| static boolean isReachable() { | ||
| HttpURLConnection conn = null; | ||
| try { | ||
| conn = createConnection(METADATA_BASE_URL, REACHABILITY_TIMEOUT_MS); | ||
| return conn.getResponseCode() == HttpURLConnection.HTTP_OK; | ||
| } catch (Exception e) { | ||
| return false; | ||
| } finally { | ||
| if (conn != null) { | ||
| conn.disconnect(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static InetAddress getIPv4() { | ||
| return fetchIP(METADATA_IPV4_URL); | ||
| } | ||
|
|
||
| static InetAddress getIPv6() { | ||
| return fetchIP(METADATA_IPV6_URL); | ||
| } | ||
|
|
||
| private static InetAddress fetchIP(String urlStr) { | ||
| HttpURLConnection conn = null; | ||
| try { | ||
| conn = createConnection(urlStr, FETCH_IP_TIMEOUT_MS); | ||
| if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { | ||
| try (BufferedReader br = | ||
| new BufferedReader( | ||
| new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { | ||
| String ipStr = br.readLine(); | ||
| if (ipStr != null && !ipStr.isEmpty()) { | ||
| return InetAddress.getByName(ipStr.trim()); | ||
| } | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| // investigator handles the exception | ||
| } finally { | ||
| if (conn != null) { | ||
| conn.disconnect(); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** Helper to consistently configure the HttpURLConnection for the GCE Metadata Server. */ | ||
| private static HttpURLConnection createConnection(String urlStr, int readTimeout) | ||
| throws Exception { | ||
| HttpURLConnection conn = (HttpURLConnection) new URL(urlStr).openConnection(); | ||
| conn.setConnectTimeout(MetadataServer.REACHABILITY_TIMEOUT_MS); | ||
| conn.setReadTimeout(readTimeout); | ||
| conn.setRequestProperty("Metadata-Flavor", "Google"); | ||
| return conn; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.