Skip to content

Commit

Permalink
remove flag which can be set by the user; Use env instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouyihaiDing committed Aug 13, 2018
1 parent 7ff774b commit 61165bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions Spanner/src/Connection/Grpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ class Grpc implements ConnectionInterface
*/
private $longRunningGrpcClients;

private function enableConnectionManagement($conf_path)
private function enableConnectionManagement($hostName, $confPath)
{
// TODO(ddyihai): move this function to GrpcTrait, if we are going
// to enable the grpc-gcp library for other apis.
$conf = new ApiConfig();
$conf->mergeFromJsonString($string = file_get_contents($conf_path));
$config = new Config($conf);
$conf->mergeFromJsonString(file_get_contents($confPath));
$config = new Config($hostName, $conf);
return $config;
}

Expand All @@ -137,6 +137,10 @@ private function enableConnectionManagement($conf_path)
*/
public function __construct(array $config = [])
{
if (getenv("ENABLE_GCP_OPTIMIZER") === false) {
// Enable the GCP optimizer by default.
putenv('ENABLE_GCP_OPTIMIZER=TRUE');
}
$this->serializer = new Serializer([
'commit_timestamp' => function ($v) {
return $this->formatTimestampFromApi($v);
Expand Down Expand Up @@ -165,12 +169,11 @@ public function __construct(array $config = [])
: null
);

if (isset($config['enableGcpOptimizer'])) {
if (getenv('ENABLE_GCP_OPTIMIZER') == 'TRUE') {
$api = 'spanner';
$conf_path = __DIR__. "/../$api.grpc.config";
$grpc_gcp_config = $this->enableConnectionManagement($conf_path);
$grpcConfig['grpc_call_invoker'] = $grpc_gcp_config->callInvoker();
unset($config['enableGcpOptimizer']);
$confPath = __DIR__. "/../$api.grpc.config";
$grpcGcpConfig = $this->enableConnectionManagement('spanner.googleapis.com', $confPath);
$grpcConfig['grpc_call_invoker'] = $grpcGcpConfig->callInvoker();
}

$this->spannerClient = isset($config['gapicSpannerClient'])
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"psr/http-message": "1.0.*",
"ramsey/uuid": "~3",
"google/gax": "^0.36",
"google/grpc-gcp": "^v0.1.0"
"google/grpc-gcp": "v0.1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0",
Expand Down

0 comments on commit 61165bf

Please sign in to comment.