Skip to content
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

Added $opts array for customize gRPC client options #137

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* added `$opts` array for customize gRPC client options

## 1.14.0
* added `ScanQueryMode` for `Table::scanQuery`

Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,19 @@ $config = [
$ydb = new \YdbPlatform\Ydb\Ydb($config);
```

## gRPC options

You can customize the gRPC client's behavior by setting options in config array

Example of using:
```php
$config = [
// ...
'opts' => [
rekby marked this conversation as resolved.
Show resolved Hide resolved
'grpc.max_receive_message_length' => 8*1024*1024,
'grpc.default_compression_algorithm' => 2,
'grpc.default_compression_level' => 2,
],
]
$ydb = new \YdbPlatform\Ydb\Ydb($config);
```
4 changes: 1 addition & 3 deletions src/AuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public function __construct(Ydb $ydb, $logger)
{
$this->ydb = $ydb;
$this->logger = $logger;
$this->client = new ServiceClient($ydb->endpoint(), [
'credentials' => $ydb->iam()->getCredentials(),
]);
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());
$this->credentials = $ydb->iam();
$this->meta = [
'x-ydb-database' => [$ydb->database()],
Expand Down
4 changes: 1 addition & 3 deletions src/Discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
{
$this->ydb = $ydb;

$this->client = new ServiceClient($ydb->endpoint(), [
'credentials' => $ydb->iam()->getCredentials(),
]);
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());

$this->meta = $ydb->meta();

Expand Down
4 changes: 1 addition & 3 deletions src/Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
{
$this->ydb = $ydb;

$this->client = new ServiceClient($ydb->endpoint(), [
'credentials' => $ydb->iam()->getCredentials(),
]);
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());

$this->meta = $ydb->meta();

Expand Down
4 changes: 1 addition & 3 deletions src/Scheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
{
$this->ydb = $ydb;

$this->client = new ServiceClient($ydb->endpoint(), [
'credentials' => $ydb->iam()->getCredentials(),
]);
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());

$this->meta = $ydb->meta();

Expand Down
4 changes: 1 addition & 3 deletions src/Scripting.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
{
$this->ydb = $ydb;

$this->client = new ServiceClient($ydb->endpoint(), [
'credentials' => $ydb->iam()->getCredentials(),
]);
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());

$this->meta = $ydb->meta();

Expand Down
4 changes: 1 addition & 3 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null, Retry &$re
{
$this->ydb = $ydb;

$this->client = new ServiceClient($ydb->endpoint(), [
'credentials' => $ydb->iam()->getCredentials(),
]);
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());

$this->meta = $ydb->meta();

Expand Down
4 changes: 1 addition & 3 deletions src/Traits/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ protected function handleGrpcStatus($service, $method, $status)
if ($this->ydb->needDiscovery() && count($this->ydb->cluster()->all()) > 0){
$endpoint = $this->ydb->cluster()->all()[array_rand($this->ydb->cluster()->all())]->endpoint();
}
$this->client = new $this->client($endpoint,[
'credentials' => $this->ydb->iam()->getCredentials()
]);
$this->client = new $this->client($endpoint, $this->ydb->opts());
if (isset(self::$grpcExceptions[$status->code])) {
throw new self::$grpcExceptions[$status->code]($message);
} else {
Expand Down
14 changes: 14 additions & 0 deletions src/Ydb.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class Ydb
*/
protected $iam_config;

/**
* @var array
*/
protected $opts;

/**
* @var Iam
*/
Expand Down Expand Up @@ -106,6 +111,7 @@ public function __construct($config = [], LoggerInterface $logger = null)
$this->endpoint = $config['endpoint'] ?? null;
$this->database = $config['database'] ?? null;
$this->iam_config = $config['iam_config'] ?? [];
$this->opts = $config['opts'] ?? [];
rekby marked this conversation as resolved.
Show resolved Hide resolved

if (!is_null($logger) && isset($config['logger'])){
throw new \Exception('Logger set in 2 places');
Expand Down Expand Up @@ -173,6 +179,14 @@ public function meta(): array
return $meta;
}

public function opts(): array
{
$opts = $this->opts;
$opts['credentials'] = $this->iam()->getCredentials();
rekby marked this conversation as resolved.
Show resolved Hide resolved

return $opts;
}

/**
* Discover available endpoints to connect to.
*
Expand Down
Loading