-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow DirectPath by default + update integration tests
* DirectPath is now opt-out by setting google.bigtable.direct.path.allowed to false * Integration tests can now verify that they are running over the desired mode by specifying "bigtable.connection-mode" system property * Integration tests update their user agent to signal membership in allow/deny lists * DirectPathFallbackIT now supports IPv4
- Loading branch information
1 parent
a25357f
commit c935655
Showing
11 changed files
with
372 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
65 changes: 65 additions & 0 deletions
65
...ent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/util/DirectPathUtil.java
This file contains 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,65 @@ | ||
/* | ||
* Copyright 2021 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 | ||
* | ||
* http://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.util; | ||
|
||
import com.google.api.core.InternalApi; | ||
import com.google.cloud.bigtable.config.BigtableOptions; | ||
import com.google.cloud.bigtable.config.CredentialOptions; | ||
import com.google.common.base.Supplier; | ||
import com.google.common.base.Suppliers; | ||
import com.google.common.io.CharStreams; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
@InternalApi("For internal use only") | ||
public class DirectPathUtil { | ||
private static final String GCE_PRODUCTION_NAME_PRIOR_2016 = "Google"; | ||
private static final String GCE_PRODUCTION_NAME_AFTER_2016 = "Google Compute Engine"; | ||
|
||
private static final Supplier<Boolean> isOnComputeEngine = | ||
Suppliers.memoize( | ||
new Supplier<Boolean>() { | ||
@Override | ||
public Boolean get() { | ||
String osName = System.getProperty("os.name"); | ||
if ("Linux".equals(osName)) { | ||
String cmd = "cat /sys/class/dmi/id/product_name"; | ||
try { | ||
Process process = Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", cmd}); | ||
process.waitFor(); | ||
String result = | ||
CharStreams.toString( | ||
new InputStreamReader(process.getInputStream(), "UTF-8")); | ||
return result.contains(GCE_PRODUCTION_NAME_PRIOR_2016) | ||
|| result.contains(GCE_PRODUCTION_NAME_AFTER_2016); | ||
} catch (IOException | InterruptedException e) { | ||
return false; | ||
} | ||
} | ||
return false; | ||
} | ||
}); | ||
|
||
private DirectPathUtil() {} | ||
|
||
public static boolean shouldAttemptDirectPath( | ||
String endpoint, int port, CredentialOptions creds) { | ||
return BigtableOptions.BIGTABLE_DATA_HOST_DEFAULT.equals(endpoint) | ||
&& BigtableOptions.BIGTABLE_PORT_DEFAULT == port | ||
&& CredentialOptions.defaultCredentials() == creds | ||
&& isOnComputeEngine.get(); | ||
} | ||
} |
This file contains 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.