Skip to content

Commit

Permalink
grpc scenario docs
Browse files Browse the repository at this point in the history
grpc scenario docs
  • Loading branch information
oke11o committed Jan 26, 2024
1 parent 6d5317f commit 745ec08
Show file tree
Hide file tree
Showing 11 changed files with 910 additions and 230 deletions.
6 changes: 6 additions & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,15 @@
"docs/eng/architecture.md":"load/projects/pandora/docs/eng/architecture.md",
"docs/eng/config.md":"load/projects/pandora/docs/eng/config.md",
"docs/eng/custom.md":"load/projects/pandora/docs/eng/custom.md",
"docs/eng/grpc-generator.md":"load/projects/pandora/docs/eng/grpc-generator.md",
"docs/eng/http-generator.md":"load/projects/pandora/docs/eng/http-generator.md",
"docs/eng/install.md":"load/projects/pandora/docs/eng/install.md",
"docs/eng/load-profile.md":"load/projects/pandora/docs/eng/load-profile.md",
"docs/eng/performance.md":"load/projects/pandora/docs/eng/performance.md",
"docs/eng/providers.md":"load/projects/pandora/docs/eng/providers.md",
"docs/eng/scenario-grpc-generator.md":"load/projects/pandora/docs/eng/scenario-grpc-generator.md",
"docs/eng/scenario-http-generator.md":"load/projects/pandora/docs/eng/scenario-http-generator.md",
"docs/eng/scenario/variable_source.md":"load/projects/pandora/docs/eng/scenario/variable_source.md",
"docs/eng/tuturial.md":"load/projects/pandora/docs/eng/tuturial.md",
"docs/images/architecture.graphml":"load/projects/pandora/docs/images/architecture.graphml",
"docs/images/architecture.png":"load/projects/pandora/docs/images/architecture.png",
Expand All @@ -254,13 +257,16 @@
"docs/rus/architecture.md":"load/projects/pandora/docs/rus/architecture.md",
"docs/rus/config.md":"load/projects/pandora/docs/rus/config.md",
"docs/rus/custom.md":"load/projects/pandora/docs/rus/custom.md",
"docs/rus/grpc-generator.md":"load/projects/pandora/docs/rus/grpc-generator.md",
"docs/rus/http-generator.md":"load/projects/pandora/docs/rus/http-generator.md",
"docs/rus/index.md":"load/projects/pandora/docs/rus/index.md",
"docs/rus/install.md":"load/projects/pandora/docs/rus/install.md",
"docs/rus/load-profile.md":"load/projects/pandora/docs/rus/load-profile.md",
"docs/rus/performance.md":"load/projects/pandora/docs/rus/performance.md",
"docs/rus/providers.md":"load/projects/pandora/docs/rus/providers.md",
"docs/rus/scenario-grpc-generator.md":"load/projects/pandora/docs/rus/scenario-grpc-generator.md",
"docs/rus/scenario-http-generator.md":"load/projects/pandora/docs/rus/scenario-http-generator.md",
"docs/rus/scenario/variable_source.md":"load/projects/pandora/docs/rus/scenario/variable_source.md",
"docs/rus/tuturial.md":"load/projects/pandora/docs/rus/tuturial.md",
"examples/connect.yaml":"load/projects/pandora/examples/connect.yaml",
"examples/custom_pandora/custom.yaml":"load/projects/pandora/examples/custom_pandora/custom.yaml",
Expand Down
26 changes: 26 additions & 0 deletions docs/eng/grpc-generator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[Home](index.md)

---

# gRPC generator

Full gRPC generator config

```yaml
gun:
type: http
target: '[hostname]:443'
timeout: 15s
tls: true
dial_options:
timeout: 1s
authority: string
answlog:
enabled: true
path: ./answ.log
filter: all # all - all http codes, warning - log 4xx and 5xx, error - log only 5xx. Default: error
```
---
[Home](index.md)
289 changes: 289 additions & 0 deletions docs/eng/scenario-grpc-generator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
[Home](../index.md)

---

# Scenario generator / gRPC

- [Configuration](#configuration)
- [Generator](#generator)
- [Provider](#provider)
- [Description of the scenario format](#description-of-the-scenario-format)
- [General principle](#general-principle)
- [HCL example](#hcl-example)
- [YAML example](#yaml-example)
- [Features](#features)
- [Calls](#calls)
- [Templater](#templater)
- [Variable names in templates](#variable-names-in-templates)
- [Preprocessors](#preprocessors)
- [prepare](#prepare)
- [Postprocessors](#postprocessors)
- [assert/response](#assertresponse)
- [Scenarios](#scenarios)
- [Sources](#sources)

## Configuration

You need to use a generator and a provider of type `grpc/scenario`

```yaml
pools:
- id: Pool name
gun:
type: grpc/scenario
target: localhost:8888
ammo:
type: grpc/scenario
file: payload.hcl
```
### Generator
The minimum generator configuration is as follows
```yaml
gun:
type: http/scenario
target: localhost:80
```
For a scenario gRPC generator, all settings of a regular gRPC generator are supported [gRPC generator](grpc-generator.md)
### Provider
The provider accepts only one parameter - the path to the file with the scenario description
```yaml
ammo:
type: http/scenario
file: payload.hcl
```
Supports file extensions
- hcl
- yaml
- json
## Description of the scenario format
Supports formats
- hcl
- yaml
- json
### General principle
Several scenarios can be described in a single file. A script has a name by which one scenario differs from another.
A script is a sequence of rpc calls. That is, you will need to describe in the script which calls
should be executed in what order.
The Call is a gRPC call. It has standard gRPC call fields plus additional ones. See [Calls](#calls).
### HCL example
```terraform
variable_source "users" "file/csv" {
file = "users.csv"
fields = ["user_id", "login", "pass"]
ignore_first_line = true
delimiter = ","
}
variable_source "filter_src" "file/json" {
file = "filter.json"
}
variable_source "variables" "variables" {
variables = {
header = "yandex"
b = "s"
}
}

call "auth_req" {
call = "target.TargetService.Auth"
tag = "auth"
metadata = {
"metadata" = "server.proto"
}
preprocessor "prepare" {
mapping = {
user = "source.users[next]"
}
}
payload = <<EOF
{"login": "{{.request.auth_req.preprocessor.user.login}}", "pass": "{{.request.auth_req.preprocessor.user.pass}}"}
EOF
postprocessor "assert/response" {
payload = ["token"]
status_code = 200
}
}}
}

scenario "scenario_name" {
weight = 1
min_waiting_time = 1000
requests = [
"auth_req",
]
}
```

You can also see an example in the tests https://github.com/yandex/pandora/blob/dev/tests/grpc_scenario/testdata/grpc_payload.hcl


### YAML example

```yaml
variable_sources:
- type: "file/csv"
name: "users"
ignore_first_line: true
delimiter: ","
file: "file.csv"
fields: ["user_id", "login", "pass"]
- type: "file/json"
name: "filter_src"

calls:
- name: "auth_req"
call: 'target.TargetService.Auth'
tag: auth
method: POST
metadata:
metadata: "server.proto"
preprocessors:
- type: prepare
mapping:
new_var: source.var_name[next].0
payload: '{"login": "{{.request.auth_req.preprocessor.user.login}}", "pass": "{{.request.auth_req.preprocessor.user.pass}}"}'
postprocessors:
- type: assert/response
payload: ["token"]
status_code: 200

scenarios:
- name: scenario_name
weight: 1
min_waiting_time: 1000
requests: [
auth_req
]
```

## Features

### Calls

Fields

- call
- tag
- metadata
- preprocessors
- payload
- postprocessors

### Templater

The fields `metadata', `payload` are templated.

The standard go template is used.

#### Variable names in templates

Variable names have the full path of their definition.

For example

Variable `users` from source `user_file` - `{% raw %}{{{.source.user_file.users}}{% endraw %}`

Variable `item` from the `list_req` call preprocessor - `{% raw %}{{{.request.list_req.preprocessor.item}}{% endraw %}`

> Note
> To maintain similarity with http scripts, the response section from the grpc call is saved to the `postprocessor` section
Variable `token` from the `list_req` call is `{% raw %}{{{.request.list_req.postprocessor.token}}{% endraw %}`

#### Preprocessors

Preprocessor - actions are performed before templating

##### prepare

It is used for creating new variable mapping

The preprocessor has the ability to work with arrays using modifiers

- next
- last
- rand

##### yaml

```yaml
calls:
- name: req_name
...
preprocessors:
- type: prepare
mapping:
user_id: source.users[next].id
```
##### hcl
```terraform
call "req_name" {
preprocessor "prepare" {
mapping = {
user_id = "source.users[next].id"
}
}
}
```

#### Postprocessors

##### assert/response

Checks header and body content

Upon assertion, further scenario execution is dropped

```terraform
postprocessor "assert/response" {
payload = ["token"]
status_code = 200
}
```

### Scenarios

This section repeats the same [scenario in HTTP generator](./scenario-http-generator.md#scenarios)

The minimum fields for the script are name and list of requests

```terraform
scenario "scenario_name" {
requests = [
"list_call",
"order_call",
"order_call",
"order_call"
]
}
```

More - [scenario in HTTP generator](./scenario-http-generator.md#scenarios)


### Sources

Follow - [Variable sources](scenario/variable_source.md)

---

[Home](../index.md)
Loading

0 comments on commit 745ec08

Please sign in to comment.