Skip to content

Commit 78b5db4

Browse files
authored
Merge pull request #137 from aneterial/grpc_opts_feature add grpc options
2 parents 5fdd2e4 + 499e8b9 commit 78b5db4

File tree

10 files changed

+42
-21
lines changed

10 files changed

+42
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* added `$grpc_config` array for customize gRPC behavior
2+
13
## 1.14.0
24
* added `ScanQueryMode` for `Table::scanQuery`
35

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,22 @@ $config = [
562562
$ydb = new \YdbPlatform\Ydb\Ydb($config);
563563
```
564564

565+
## gRPC
566+
567+
### gRPC client's options
568+
You can customize the gRPC client's behavior by setting options in config array
569+
570+
Example of using:
571+
```php
572+
$config = [
573+
// ...
574+
'grpc' => [
575+
'opts' => [
576+
'grpc.max_receive_message_length' => 8*1024*1024,
577+
'grpc.default_compression_algorithm' => 2,
578+
'grpc.default_compression_level' => 2,
579+
],
580+
],
581+
];
582+
$ydb = new \YdbPlatform\Ydb\Ydb($config);
583+
```

src/AuthService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public function __construct(Ydb $ydb, $logger)
2828
{
2929
$this->ydb = $ydb;
3030
$this->logger = $logger;
31-
$this->client = new ServiceClient($ydb->endpoint(), [
32-
'credentials' => $ydb->iam()->getCredentials(),
33-
]);
31+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
3432
$this->credentials = $ydb->iam();
3533
$this->meta = [
3634
'x-ydb-database' => [$ydb->database()],

src/Discovery.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
4343
{
4444
$this->ydb = $ydb;
4545

46-
$this->client = new ServiceClient($ydb->endpoint(), [
47-
'credentials' => $ydb->iam()->getCredentials(),
48-
]);
46+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
4947

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

src/Operations.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
3838
{
3939
$this->ydb = $ydb;
4040

41-
$this->client = new ServiceClient($ydb->endpoint(), [
42-
'credentials' => $ydb->iam()->getCredentials(),
43-
]);
41+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
4442

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

src/Scheme.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
4141
{
4242
$this->ydb = $ydb;
4343

44-
$this->client = new ServiceClient($ydb->endpoint(), [
45-
'credentials' => $ydb->iam()->getCredentials(),
46-
]);
44+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
4745

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

src/Scripting.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
3838
{
3939
$this->ydb = $ydb;
4040

41-
$this->client = new ServiceClient($ydb->endpoint(), [
42-
'credentials' => $ydb->iam()->getCredentials(),
43-
]);
41+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
4442

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

src/Table.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null, Retry &$re
7575
{
7676
$this->ydb = $ydb;
7777

78-
$this->client = new ServiceClient($ydb->endpoint(), [
79-
'credentials' => $ydb->iam()->getCredentials(),
80-
]);
78+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
8179

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

src/Traits/RequestTrait.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ protected function handleGrpcStatus($service, $method, $status)
193193
if ($this->ydb->needDiscovery() && count($this->ydb->cluster()->all()) > 0){
194194
$endpoint = $this->ydb->cluster()->all()[array_rand($this->ydb->cluster()->all())]->endpoint();
195195
}
196-
$this->client = new $this->client($endpoint,[
197-
'credentials' => $this->ydb->iam()->getCredentials()
198-
]);
196+
$this->client = new $this->client($endpoint, $this->ydb->grpcOpts());
199197
if (isset(self::$grpcExceptions[$status->code])) {
200198
throw new self::$grpcExceptions[$status->code]($message);
201199
} else {

src/Ydb.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class Ydb
3737
*/
3838
protected $iam_config;
3939

40+
/**
41+
* @var array
42+
*/
43+
protected $grpc_config;
44+
4045
/**
4146
* @var Iam
4247
*/
@@ -106,6 +111,7 @@ public function __construct($config = [], LoggerInterface $logger = null)
106111
$this->endpoint = $config['endpoint'] ?? null;
107112
$this->database = $config['database'] ?? null;
108113
$this->iam_config = $config['iam_config'] ?? [];
114+
$this->grpc_config = (array) ($config['grpc'] ?? []);
109115

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

182+
public function grpcOpts(): array
183+
{
184+
$grpcOpts = (array) ($this->grpc_config['opts'] ?? []);
185+
$grpcOpts['credentials'] = $this->iam()->getCredentials();
186+
187+
return $grpcOpts;
188+
}
189+
176190
/**
177191
* Discover available endpoints to connect to.
178192
*

0 commit comments

Comments
 (0)