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

Minor gRPC docs updates #1491

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error will be thrown.
| Parameter | Type | Description |
| ----------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| url | string | The gRPC method url to invoke, in the form `/package.Service/Method`, e.g. `/google.cloud.language.v1.LanguageService/AnalyzeSentiment`. The leading slash `/` is optional. |
| request | object | The canonical request object, as-per the [Protobuf JSON Mapping](https://developers.google.com/protocol-buffers/docs/proto3#json). |
| request | object | The canonical request object, as-per the [Protobuf JSON Mapping](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/protocols/grpc/#protocol-buffers-json-mapping). |
| params (optional) | object | [Params](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-net-grpc/params) object containing additional request parameters. |

### Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 40

# Stream.write()

Writes a message to the stream.
Writes a message to the stream. The message is a canonical request object, as-per the [Protobuf JSON Mapping](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/protocols/grpc/#protocol-buffers-json-mapping).

### Example

Expand Down
14 changes: 9 additions & 5 deletions docs/sources/next/using-k6/protocols/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default () => {

In server streaming mode, the client sends a single request to the server, and the server replies with multiple responses.

The example below demonstrates client streaming.
The example below demonstrates server streaming.

{{< code >}}

Expand Down Expand Up @@ -256,11 +256,15 @@ stream.on('error', function (e) {

{{< /code >}}

### Handle special cases in message Marshaling/Unmarshaling
### Protocol Buffers JSON Mapping

It's important to note how k6 handles requests and messages. First, it tries to marshal the request/message in JSON format. Then, k6 uses the [protojson](https://pkg.go.dev/google.golang.org/protobuf/encoding/protojson) package to encode or decode to a Protobuf message.

A limitation during this process is that the object you pass as a request/message must be serializable. That means structs like `Map` don't work.

k6 uses the [protojson](https://pkg.go.dev/google.golang.org/protobuf/encoding/protojson) package for encoding and decoding of messages.
The benefit of using `protojson` is the canonical JSON encoding support. The [Protocol Buffers documentation](https://protobuf.dev/programming-guides/proto3/#json) describes this mapping.

Certain gRPC well-known types or wrappers have specific marshaling/unmarshaling rules.
#### Examples

For instance, if you import `"google/protobuf/wrappers.proto"` and your proto-definitions look like this:

Expand Down Expand Up @@ -301,7 +305,7 @@ if (respInt.message !== '6') {

{{< /code >}}

Another special case could be usage of `oneof`. Let's say you have a proto-definition like this:
Another example could be usage of `oneof`. Let's say you have a proto-definition like this:

```proto
syntax = "proto3";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error will be thrown.
| Parameter | Type | Description |
| ----------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| url | string | The gRPC method url to invoke, in the form `/package.Service/Method`, e.g. `/google.cloud.language.v1.LanguageService/AnalyzeSentiment`. The leading slash `/` is optional. |
| request | object | The canonical request object, as-per the [Protobuf JSON Mapping](https://developers.google.com/protocol-buffers/docs/proto3#json). |
| request | object | The canonical request object, as-per the [Protobuf JSON Mapping](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/protocols/grpc/#protocol-buffers-json-mapping). |
| params (optional) | object | [Params](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-net-grpc/params) object containing additional request parameters. |

### Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 40

# Stream.write()

Writes a message to the stream.
Writes a message to the stream. The message is a canonical request object, as-per the [Protobuf JSON Mapping](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/protocols/grpc/#protocol-buffers-json-mapping).

### Example

Expand Down
14 changes: 9 additions & 5 deletions docs/sources/v0.49.x/using-k6/protocols/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default () => {

In server streaming mode, the client sends a single request to the server, and the server replies with multiple responses.

The example below demonstrates client streaming.
The example below demonstrates server streaming.

{{< code >}}

Expand Down Expand Up @@ -256,11 +256,15 @@ stream.on('error', function (e) {

{{< /code >}}

### Handle special cases in message Marshaling/Unmarshaling
### Protocol Buffers JSON Mapping

It's important to note how k6 handles requests and messages. First, it tries to marshal the request/message in JSON format. Then, k6 uses the [protojson](https://pkg.go.dev/google.golang.org/protobuf/encoding/protojson) package to encode or decode to a Protobuf message.

A limitation during this process is that the object you pass as a request/message must be serializable. That means structs like `Map` don't work.

k6 uses the [protojson](https://pkg.go.dev/google.golang.org/protobuf/encoding/protojson) package for encoding and decoding of messages.
The benefit of using `protojson` is the canonical JSON encoding support. The [Protocol Buffers documentation](https://protobuf.dev/programming-guides/proto3/#json) describes this mapping.

Certain gRPC well-known types or wrappers have specific marshaling/unmarshaling rules.
#### Examples

For instance, if you import `"google/protobuf/wrappers.proto"` and your proto-definitions look like this:

Expand Down Expand Up @@ -301,7 +305,7 @@ if (respInt.message !== '6') {

{{< /code >}}

Another special case could be usage of `oneof`. Let's say you have a proto-definition like this:
Another example could be usage of `oneof`. Let's say you have a proto-definition like this:

```proto
syntax = "proto3";
Expand Down
Loading