Skip to content

Commit cb973dc

Browse files
committed
Document GPRC Connection's TLS option
1 parent f32b958 commit cb973dc

File tree

2 files changed

+160
-4
lines changed

2 files changed

+160
-4
lines changed

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 grpc/20 Client/20-Client-connect-connect-address-params.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,20 @@ See [Client.close()](/javascript-api/k6-experimental/grpc/client/client-close) t
2020
| `ConnectParams.plaintext` | bool | If `true` will connect to the gRPC server using plaintext i.e. insecure. Defaults to `false` i.e. secure via TLS. |
2121
| `ConnectParams.reflect` | boolean | Whether to use the [gRPC server reflection protocol](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md) when connecting. |
2222
| `ConnectParams.timeout` | string / number | Connection timeout to use. Default timeout is `"60s"`. <br/> The type can also be a number, in which case k6 interprets it as milliseconds, e.g., `60000` is equivalent to `"60s"`. |
23-
| `ConnectParams.maxReceiveSize` | number | Sets the maximum message size in bytes the client can receive.Defaults to 0. |
24-
| `ConnectParams.maxSendSize` | number | Sets the maximum message size in bytes the client can send.Defaults to 0. |
23+
| `ConnectParams.maxReceiveSize` | number | Sets the maximum message size in bytes the client can receive. Defaults to 0. |
24+
| `ConnectParams.maxSendSize` | number | Sets the maximum message size in bytes the client can send. Defaults to 0. |
25+
| `ConnectParams.tls` (optional) | object | [TLS](#tls) | TLS settings of the connection. Defaults not defined. |
26+
27+
## TLS
28+
29+
TLS settings of the connection, if not defined, the main TLS config from options will be used.
30+
31+
| Name | Type | Description |
32+
|------|------|-------------|
33+
| `tls.cert` | string | PEM formatted client certificate. |
34+
| `tls.key` | string | PEM formatted client private key. |
35+
| `tls.password` | string | Password for decrypting the client's private key. |
36+
| `tls.cacerts` | string / array | PEM formatted strings of the certificate authorities. |
2537

2638
### Examples
2739

@@ -50,3 +62,69 @@ export default () => {
5062
};
5163
```
5264
</div>
65+
66+
<div class="code-group" data-props='{"labels": ["Different TLS settings"], "lineNumbers": [true]}'>
67+
68+
```javascript
69+
import grpc from 'k6/experimental/grpc';
70+
import { check } from 'k6';
71+
72+
// note: there are no such services
73+
const params = {
74+
'foo1.grpcbin.test.k6.io:9001': {
75+
plaintext: false,
76+
tls: {
77+
cacerts: [open('cacerts0.pem')],
78+
cert: open('cert0.pem'),
79+
key: open('key0.pem'),
80+
},
81+
},
82+
'foo2.grpcbin.test.k6.io:9002': {
83+
plaintext: false,
84+
tls: {
85+
cacerts: open('cacerts1.pem'),
86+
cert: open('cert1.pem'),
87+
key: open('key1.pem'),
88+
password: 'cert1-passphrase',
89+
},
90+
},
91+
};
92+
const clients = {
93+
'foo1.grpcbin.test.k6.io:9001': new grpc.Client(),
94+
'foo2.grpcbin.test.k6.io:9002': new grpc.Client(),
95+
};
96+
97+
export default () => {
98+
if (__ITER === 0) {
99+
clients['foo1.grpcbin.test.k6.io:9001'].connect(
100+
'foo1.grpcbin.test.k6.io:9001',
101+
params['foo1.grpcbin.test.k6.io:9001']
102+
);
103+
clients['foo2.grpcbin.test.k6.io:9002'].connect(
104+
'foo2.grpcbin.test.k6.io:9002',
105+
params['foo2.grpcbin.test.k6.io:9002']
106+
);
107+
}
108+
109+
const response1 = clients['foo1.grpcbin.test.k6.io:9001'].invoke('hello.HelloService/SayHello', {
110+
greeting: 'Bert',
111+
});
112+
113+
check(response1, {
114+
'status is OK': (r) => r && r.status === grpc.StatusOK,
115+
});
116+
117+
console.log(JSON.stringify(response1.message));
118+
119+
const response2 = clients['foo2.grpcbin.test.k6.io:9002'].invoke('hello.HelloService/SayHello', {
120+
greeting: 'Ernie',
121+
});
122+
123+
check(response2, {
124+
'status is OK': (r) => r && r.status === grpc.StatusOK,
125+
});
126+
127+
console.log(JSON.stringify(response2.message));
128+
};
129+
```
130+
</div>

src/data/markdown/docs/02 javascript api/11 k6-net-grpc/20 Client/20-Client-connect-connect-address-params.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,20 @@ See [Client.close()](/javascript-api/k6-net-grpc/client/client-close) to close t
2020
| `ConnectParams.plaintext` | bool | If `true` will connect to the gRPC server using plaintext i.e. insecure. Defaults to `false` i.e. secure via TLS. |
2121
| `ConnectParams.reflect` | boolean | Whether to use the [gRPC server reflection protocol](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md) when connecting. |
2222
| `ConnectParams.timeout` | string / number | Connection timeout to use. Default timeout is `"60s"`. <br/> The type can also be a number, in which case k6 interprets it as milliseconds, e.g., `60000` is equivalent to `"60s"`. |
23-
| `ConnectParams.maxReceiveSize` | number | Sets the maximum message size in bytes the client can receive.Defaults to 0. |
24-
| `ConnectParams.maxSendSize` | number | Sets the maximum message size in bytes the client can send.Defaults to 0. |
23+
| `ConnectParams.maxReceiveSize` | number | Sets the maximum message size in bytes the client can receive. Defaults to 0. |
24+
| `ConnectParams.maxSendSize` | number | Sets the maximum message size in bytes the client can send. Defaults to 0. |
25+
| `ConnectParams.tls` (optional) | object | [TLS](#tls) | TLS settings of the connection. Defaults not defined. |
26+
27+
## TLS
28+
29+
TLS settings of the connection, if not defined, the main TLS config from options will be used.
30+
31+
| Name | Type | Description |
32+
|------|------|-------------|
33+
| `tls.cert` | string | PEM formatted client certificate. |
34+
| `tls.key` | string | PEM formatted client private key. |
35+
| `tls.password` | string | Password for decrypting the client's private key. |
36+
| `tls.cacerts` | string / array | PEM formatted strings of the certificate authorities. |
2537

2638
### Examples
2739

@@ -50,3 +62,69 @@ export default () => {
5062
};
5163
```
5264
</div>
65+
66+
<div class="code-group" data-props='{"labels": ["Different TLS settings"], "lineNumbers": [true]}'>
67+
68+
```javascript
69+
import grpc from 'k6/net/grpc';
70+
import { check } from 'k6';
71+
72+
// note: there are no such services
73+
const params = {
74+
'foo1.grpcbin.test.k6.io:9001': {
75+
plaintext: false,
76+
tls: {
77+
cacerts: [open('cacerts0.pem')],
78+
cert: open('cert0.pem'),
79+
key: open('key0.pem'),
80+
},
81+
},
82+
'foo2.grpcbin.test.k6.io:9002': {
83+
plaintext: false,
84+
tls: {
85+
cacerts: open('cacerts1.pem'),
86+
cert: open('cert1.pem'),
87+
key: open('key1.pem'),
88+
password: 'cert1-passphrase',
89+
},
90+
},
91+
};
92+
const clients = {
93+
'foo1.grpcbin.test.k6.io:9001': new grpc.Client(),
94+
'foo2.grpcbin.test.k6.io:9002': new grpc.Client(),
95+
};
96+
97+
export default () => {
98+
if (__ITER === 0) {
99+
clients['foo1.grpcbin.test.k6.io:9001'].connect(
100+
'foo1.grpcbin.test.k6.io:9001',
101+
params['foo1.grpcbin.test.k6.io:9001']
102+
);
103+
clients['foo2.grpcbin.test.k6.io:9002'].connect(
104+
'foo2.grpcbin.test.k6.io:9002',
105+
params['foo2.grpcbin.test.k6.io:9002']
106+
);
107+
}
108+
109+
const response1 = clients['foo1.grpcbin.test.k6.io:9001'].invoke('hello.HelloService/SayHello', {
110+
greeting: 'Bert',
111+
});
112+
113+
check(response1, {
114+
'status is OK': (r) => r && r.status === grpc.StatusOK,
115+
});
116+
117+
console.log(JSON.stringify(response1.message));
118+
119+
const response2 = clients['foo2.grpcbin.test.k6.io:9002'].invoke('hello.HelloService/SayHello', {
120+
greeting: 'Ernie',
121+
});
122+
123+
check(response2, {
124+
'status is OK': (r) => r && r.status === grpc.StatusOK,
125+
});
126+
127+
console.log(JSON.stringify(response2.message));
128+
};
129+
```
130+
</div>

0 commit comments

Comments
 (0)