Skip to content

Commit

Permalink
pandora scenario: local block docs
Browse files Browse the repository at this point in the history
7eb87e73be643c6cd89eacda49777b507ce609d4
  • Loading branch information
oke11o committed May 20, 2024
1 parent 6a7b878 commit 7df17c5
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20240517-144818.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: scenario config local block in yaml
time: 2024-05-17T14:48:18.485698+02:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20240517-144851.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: scenario config local block documentation
time: 2024-05-17T14:48:51.970879+02:00
4 changes: 4 additions & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
".changes/header.tpl.md":"load/projects/pandora/.changes/header.tpl.md",
".changes/unreleased/.gitkeep":"load/projects/pandora/.changes/unreleased/.gitkeep",
".changes/unreleased/Added-20240517-144818.yaml":"load/projects/pandora/.changes/unreleased/Added-20240517-144818.yaml",
".changes/unreleased/Added-20240517-144851.yaml":"load/projects/pandora/.changes/unreleased/Added-20240517-144851.yaml",
".changes/v0.5.04.md":"load/projects/pandora/.changes/v0.5.04.md",
".changes/v0.5.05.md":"load/projects/pandora/.changes/v0.5.05.md",
".changes/v0.5.06.md":"load/projects/pandora/.changes/v0.5.06.md",
Expand Down Expand Up @@ -273,6 +275,7 @@
"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/functions.md":"load/projects/pandora/docs/eng/scenario/functions.md",
"docs/eng/scenario/locals.md":"load/projects/pandora/docs/eng/scenario/locals.md",
"docs/eng/scenario/variable_source.md":"load/projects/pandora/docs/eng/scenario/variable_source.md",
"docs/eng/startup.md":"load/projects/pandora/docs/eng/startup.md",
"docs/eng/tutorial.md":"load/projects/pandora/docs/eng/tutorial.md",
Expand Down Expand Up @@ -304,6 +307,7 @@
"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/functions.md":"load/projects/pandora/docs/rus/scenario/functions.md",
"docs/rus/scenario/locals.md":"load/projects/pandora/docs/rus/scenario/locals.md",
"docs/rus/scenario/variable_source.md":"load/projects/pandora/docs/rus/scenario/variable_source.md",
"docs/rus/startup.md":"load/projects/pandora/docs/rus/startup.md",
"docs/rus/tutorial.md":"load/projects/pandora/docs/rus/tutorial.md",
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

Pandora is a high-performance load generator in Go language. It has built-in HTTP(S) and HTTP/2 support and you can write your own load scenarios in Go, compiling them just before your test.

## Documentation
[Documentation](https://yandex.github.io/pandora/)

## How to start

### Binary releases
Expand Down Expand Up @@ -71,9 +74,3 @@ Create changelog release file - `changie batch v0.5.21`
Same for next version - `changie batch $(changie next patch)`

Merge to main CHANGELOG.md file - `changie merge`

## Documentation
[Documentation](https://yandex.github.io/pandora/)

## Old Documentation
[ReadTheDocs](https://yandexpandora.readthedocs.io/)
1 change: 1 addition & 0 deletions components/providers/scenario/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// AmmoConfig is a config for dynamic converting from map[string]interface{}
type AmmoConfig struct {
Locals map[string]any
VariableSources []vs.VariableSource `config:"variable_sources"`
Requests []RequestConfig
Calls []CallConfig
Expand Down
2 changes: 1 addition & 1 deletion components/providers/scenario/grpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ core.Provider = (*scenario.Provider[*gun.Scenario])(nil)
const defaultSinkSize = 100

func NewProvider(fs afero.Fs, conf scenario.ProviderConfig) (core.Provider, error) {
const op = "config.NewProvider"
const op = "scenario_grpc.NewProvider"
ammoCfg, err := config.ReadAmmoConfig(fs, conf.File)
if err != nil {
return nil, fmt.Errorf("%s ReadAmmoConfig %w", op, err)
Expand Down
2 changes: 1 addition & 1 deletion components/providers/scenario/http/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ core.Provider = (*scenario.Provider[*gun.Scenario])(nil)
const defaultSinkSize = 100

func NewProvider(fs afero.Fs, conf scenario.ProviderConfig) (core.Provider, error) {
const op = "scenario.NewProvider"
const op = "scenario_http.NewProvider"
ammoCfg, err := config.ReadAmmoConfig(fs, conf.File)
if err != nil {
return nil, fmt.Errorf("%s ReadAmmoConfig %w", op, err)
Expand Down
9 changes: 6 additions & 3 deletions components/providers/scenario/test/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/yandex/pandora/components/providers/scenario/config"
_import "github.com/yandex/pandora/components/providers/scenario/import"
"github.com/yandex/pandora/core/plugin/pluginconfig"
Expand All @@ -22,12 +23,14 @@ func Test_ReadConfig_YamlAndHclSameResult(t *testing.T) {

t.Run("http", func(t *testing.T) {
fromHCL, err := config.ReadAmmoConfig(testFS, "../testdata/http_payload.hcl")
assert.NoError(t, err)
require.NoError(t, err)
fromHCL.Locals = nil

fromYaml, err := config.ReadAmmoConfig(testFS, "../testdata/http_payload.yaml")
assert.NoError(t, err)
require.NoError(t, err)
fromYaml.Locals = nil

assert.Equal(t, fromHCL, fromYaml)
require.Equal(t, fromHCL, fromYaml)
})
}

Expand Down
9 changes: 6 additions & 3 deletions components/providers/scenario/testdata/http_payload.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
locals:
global-headers: &global-headers
Content-Type: application/json
Useragent: Yandex
variable_sources:
- name: users
type: file/csv
Expand All @@ -20,9 +24,8 @@ requests:
- name: auth_req
method: POST
uri: /auth
headers: &global-headers
Content-Type: application/json
Useragent: Yandex
headers:
<<: *global-headers
tag: auth
body: |
{"user_id": {{.request.auth_req.preprocessor.user_id}}}
Expand Down
27 changes: 22 additions & 5 deletions docs/eng/scenario-grpc-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [General principle](#general-principle)
- [HCL example](#hcl-example)
- [YAML example](#yaml-example)
- [Locals](#locals)
- [Features](#features)
- [Calls](#calls)
- [Templater](#templater)
Expand Down Expand Up @@ -87,6 +88,18 @@ The Call is a gRPC call. It has standard gRPC call fields plus additional ones.
### HCL example
```terraform
locals {
common_meta = {
"metadata" = "server.proto"
}
next = "next"
}
locals {
auth_meta = merge(local.common_meta, {
authorization = "{{.request.auth_req.postprocessor.token}}"
})
next = "next"
}
variable_source "users" "file/csv" {
file = "users.csv"
fields = ["user_id", "login", "pass"]
Expand All @@ -106,9 +119,7 @@ variable_source "variables" "variables" {
call "auth_req" {
call = "target.TargetService.Auth"
tag = "auth"
metadata = {
"metadata" = "server.proto"
}
metadata = local.auth_meta
preprocessor "prepare" {
mapping = {
user = "source.users[next]"
Expand All @@ -121,7 +132,6 @@ EOF
payload = ["token"]
status_code = 200
}
}}
}

scenario "scenario_name" {
Expand All @@ -139,6 +149,9 @@ You can also see an example in the tests https://github.com/yandex/pandora/blob/
### YAML example

```yaml
locals:
my-meta: &global-meta
metadata: "server.proto"
variable_sources:
- type: "file/csv"
name: "users"
Expand All @@ -155,7 +168,7 @@ calls:
tag: auth
method: POST
metadata:
metadata: "server.proto"
<<: *global-meta
preprocessors:
- type: prepare
mapping:
Expand All @@ -175,6 +188,10 @@ scenarios:
]
```

### Locals

Про блок locals смотрите в отдельной [статье Locals](scenario/locals.md)

## Features

### Calls
Expand Down
30 changes: 26 additions & 4 deletions docs/eng/scenario-http-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [General principle](#general-principle)
- [HCL example](#hcl-example)
- [YAML example](#yaml-example)
- [Locals](#locals)
- [Features](#features)
- [Requests](#requests)
- [Templater](#templater)
Expand Down Expand Up @@ -97,6 +98,19 @@ Request - HTTP request. Has the standard HTTP request fields plus additional fie
### HCL example

```terraform
locals {
common_headers = {
Content-Type = "application/json"
Useragent = "Yandex"
}
next = "next"
}
locals {
auth_headers = merge(local.common_headers, {
Authorization = "Bearer {{.request.auth_req.postprocessor.token}}"
})
next = "next"
}
variable_source "source_name" "file/csv" {
file = "file.csv"
fields = ["id", "name"]
Expand All @@ -107,9 +121,9 @@ variable_source "source_name" "file/csv" {
request "request_name" {
method = "POST"
uri = "/uri"
headers = {
HeaderName = "header value"
}
headers = merge(local.common_headers, {
Authorization = "Bearer {{.request.auth_req.postprocessor.token}}"
})
tag = "tag"
body = <<EOF
<body/>
Expand Down Expand Up @@ -144,6 +158,10 @@ scenario "scenario_name" {
### YAML example

```yaml
locals:
my-headers: &global-headers
Content-Type: application/json
Useragent: Yandex
variable_sources:
- type: "file/csv"
name: "source_name"
Expand All @@ -157,7 +175,7 @@ requests:
uri: '/uri'
method: POST
headers:
Header-Name: "header value"
<<: *global-headers
tag: tag
body: '<body/>'
preprocessor:
Expand All @@ -179,6 +197,10 @@ scenarios:
]
```

### Locals

See [Locals article](scenario/locals.md)

## Features

### Requests
Expand Down
22 changes: 22 additions & 0 deletions docs/eng/scenario/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,28 @@ preprocessor {
}
```

# HCL functions

You can use follow function

- [coalesce](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/coalesce)
- [coalescelist](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/coalescelist)
- [compact](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/compact)
- [concat](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/concat)
- [distinct](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/distinct)
- [element](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/element)
- [flatten](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/flatten)
- [index](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/index-fn)
- [keys](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/keys)
- [lookup](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/lookup)
- [merge](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/merge)
- [reverse](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/reverse)
- [slice](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/slice)
- [sort](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/sort)
- [split](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/string/split)
- [values](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/values)
- [zipmap](https://developer.hashicorp.com/packer/docs/templates/hcl_templates/functions/collection/zipmap)


---

Expand Down
Loading

0 comments on commit 7df17c5

Please sign in to comment.