Skip to content

Commit

Permalink
Merge pull request #181 from yandex/dev
Browse files Browse the repository at this point in the history
v0.5.20
  • Loading branch information
oke11o authored Jan 29, 2024
2 parents 068b62b + 916fd46 commit 3840354
Show file tree
Hide file tree
Showing 18 changed files with 1,088 additions and 337 deletions.
9 changes: 9 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 Expand Up @@ -337,10 +343,13 @@
"script/checkfmt.sh":"load/projects/pandora/script/checkfmt.sh",
"script/coverage.sh":"load/projects/pandora/script/coverage.sh",
"tests/acceptance/http_test.go":"load/projects/pandora/tests/acceptance/http_test.go",
"tests/acceptance/testdata/http/http-check-limit.yaml":"load/projects/pandora/tests/acceptance/testdata/http/http-check-limit.yaml",
"tests/acceptance/testdata/http/http-check-passes.yaml":"load/projects/pandora/tests/acceptance/testdata/http/http-check-passes.yaml",
"tests/acceptance/testdata/http/http.yaml":"load/projects/pandora/tests/acceptance/testdata/http/http.yaml",
"tests/acceptance/testdata/http/http2.yaml":"load/projects/pandora/tests/acceptance/testdata/http/http2.yaml",
"tests/acceptance/testdata/http/https.yaml":"load/projects/pandora/tests/acceptance/testdata/http/https.yaml",
"tests/acceptance/testdata/http/payload.uri":"load/projects/pandora/tests/acceptance/testdata/http/payload.uri",
"tests/acceptance/testdata/http/payload5.uri":"load/projects/pandora/tests/acceptance/testdata/http/payload5.uri",
"tests/grpc_scenario/main_test.go":"load/projects/pandora/tests/grpc_scenario/main_test.go",
"tests/grpc_scenario/testdata/filter.json":"load/projects/pandora/tests/grpc_scenario/testdata/filter.json",
"tests/grpc_scenario/testdata/grpc_payload.hcl":"load/projects/pandora/tests/grpc_scenario/testdata/grpc_payload.hcl",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ prepare: fmt test vet

test:
@echo "$(OK_COLOR)Test packages$(NO_COLOR)"
@go test -v ./...
go test -race -v ./...

coverage:
@echo "$(OK_COLOR)Make coverage report$(NO_COLOR)"
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"go.uber.org/zap/zapcore"
)

const Version = "0.5.19"
const Version = "0.5.20"
const defaultConfigFile = "load"
const stdinConfigSelector = "-"

Expand Down
1 change: 1 addition & 0 deletions components/providers/http/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (p *Provider) Release(a core.Ammo) {
func (p *Provider) Run(ctx context.Context, deps core.ProviderDeps) (err error) {
p.Deps = deps
defer func() {
close(p.Sink)
// TODO: wrap in go 1.20
// err = errors.Join(err, p.Close())
if p.Close == nil {
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 3840354

Please sign in to comment.