Skip to content

Commit

Permalink
reflect metadata simpler format and docs
Browse files Browse the repository at this point in the history
e32c147aa6e274c81a60a9bd344a947d3c907c2b
  • Loading branch information
oke11o committed May 22, 2024
1 parent 7df17c5 commit 8740306
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 35 deletions.
3 changes: 0 additions & 3 deletions .changes/unreleased/Added-20240517-144818.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions .changes/unreleased/Added-20240517-144851.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions .mapping.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
".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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).


## v0.5.26 - 2024-05-21
### Added
* scenario config local block in yaml
* scenario config local block documentation
### Changed
* reflect metadata simpler format and docs

## v0.5.25 - 2024-05-16
### Fixed
* randInt function without args in preprocessor
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.25"
const Version = "0.5.26"
const defaultConfigFile = "load"
const stdinConfigSelector = "-"

Expand Down
16 changes: 8 additions & 8 deletions components/guns/grpc/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ type GrpcDialOptions struct {
}

type GunConfig struct {
Target string `validate:"required"`
ReflectPort int64 `config:"reflect_port"`
ReflectMetadata metadata.MD `config:"reflect_metadata"`
Timeout time.Duration `config:"timeout"` // grpc request timeout
TLS bool `config:"tls"`
DialOptions GrpcDialOptions `config:"dial_options"`
AnswLog AnswLogConfig `config:"answlog"`
Target string `validate:"required"`
ReflectPort int64 `config:"reflect_port"`
ReflectMetadata map[string]string `config:"reflect_metadata"`
Timeout time.Duration `config:"timeout"` // grpc request timeout
TLS bool `config:"tls"`
DialOptions GrpcDialOptions `config:"dial_options"`
AnswLog AnswLogConfig `config:"answlog"`
SharedClient struct {
ClientNumber int `config:"client-number,omitempty"`
Enabled bool `config:"enabled"`
Expand Down Expand Up @@ -111,7 +111,7 @@ func (g *Gun) prepareMethodList(opts *warmup.Options) (map[string]desc.MethodDes
}
defer conn.Close()

refCtx := metadata.NewOutgoingContext(context.Background(), g.Conf.ReflectMetadata)
refCtx := metadata.NewOutgoingContext(context.Background(), metadata.New(g.Conf.ReflectMetadata))
refClient := grpcreflect.NewClientAuto(refCtx, conn)
listServices, err := refClient.ListServices()
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions components/guns/grpc/scenario/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
const defaultTimeout = time.Second * 15

type GunConfig struct {
Target string `validate:"required"`
ReflectPort int64 `config:"reflect_port"`
ReflectMetadata metadata.MD `config:"reflect_metadata"`
Timeout time.Duration `config:"timeout"` // grpc request timeout
TLS bool `config:"tls"`
DialOptions GrpcDialOptions `config:"dial_options"`
AnswLog AnswLogConfig `config:"answlog"`
Target string `validate:"required"`
ReflectPort int64 `config:"reflect_port"`
ReflectMetadata map[string]string `config:"reflect_metadata"`
Timeout time.Duration `config:"timeout"` // grpc request timeout
TLS bool `config:"tls"`
DialOptions GrpcDialOptions `config:"dial_options"`
AnswLog AnswLogConfig `config:"answlog"`
}

type GrpcDialOptions struct {
Expand Down
4 changes: 4 additions & 0 deletions docs/eng/grpc-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ gun:
target: '[hostname]:443'
timeout: 15s # Grpc request timeout. Default: 15s
tls: false # If true, Pandora accepts any certificate presented by the server and any host name in that certificate. Default: false
reflect_port: 8000 # If your reflection service is located on a port other than the main server
reflect_metadata: # Separate metadata data for reflection service
auth: Token
shared-client:
enabled: false # If TRUE, the generator will use a common transport client for all instances
client-number: 1 # The number of shared clients can be increased. The default is 1
Expand Down Expand Up @@ -53,6 +56,7 @@ But to unify reports it converts them into HTTP codes.
# References
- [Scenario generator / gRPC](scenario-grpc-generator.md)
- Best practices
- [RPS per instance](best_practices/rps-per-instance.md)
- [Shared client](best_practices/shared-client.md)
Expand Down
4 changes: 4 additions & 0 deletions docs/rus/grpc-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ gun:
target: '[hostname]:443'
timeout: 15s # Таймаут для запросов gRPC. По умолчанию: 15s
tls: false # Если true, Pandora принимает любой сертификат, представленный сервером, и любое имя хоста в этом сертификате. По умолчанию: false
reflect_port: 8000 # Если ваш рефлекшн сервис находится на отличном от основного сервера порту
reflect_metadata: # Отдельные metadata данные для рефлекшн сервис
auth: Token
shared-client:
enabled: true # Если TRUE, генератор будет использовать общий транспортный клиент для всех инстансов
client-number: 1 # Количество общих клиентов можно увеличить. По умолчанию 1
Expand Down Expand Up @@ -53,6 +56,7 @@ gun:
# Смотри так же
- [Сценарный генератор / gRPC](scenario-grpc-generator.md)
- Практики использования
- [RPS на инстанс](best_practices/rps-per-instance.md)
- [Общий транспорт](best_practices/shared-client.md)
Expand Down
12 changes: 5 additions & 7 deletions tests/acceptance/config_model.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package acceptance

import "google.golang.org/grpc/metadata"

type PandoraConfigLog struct {
Level string `yaml:"level"`
}
Expand All @@ -13,11 +11,11 @@ type PandoraConfigMonitoring struct {
ExpVar PandoraConfigMonitoringExpVar `yaml:"expvar"`
}
type PandoraConfigGRPCGun struct {
Type string `yaml:"type"`
Target string `yaml:"target"`
TLS bool `yaml:"tls"`
ReflectPort *int64 `yaml:"reflect_port,omitempty"`
ReflectMetadata *metadata.MD `yaml:"reflect_metadata,omitempty"`
Type string `yaml:"type"`
Target string `yaml:"target"`
TLS bool `yaml:"tls"`
ReflectPort *int64 `yaml:"reflect_port,omitempty"`
ReflectMetadata map[string]string `yaml:"reflect_metadata,omitempty"`
SharedClient struct {
ClientNumber int `yaml:"client-number,omitempty"`
Enabled bool `yaml:"enabled"`
Expand Down
6 changes: 2 additions & 4 deletions tests/acceptance/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ func TestCheckGRPCReflectServer(t *testing.T) {
{
name: "success",
conf: parseFileContentToCliConfig(t, baseFile, func(c *PandoraConfigGRPC) {
md := metadata.New(map[string]string{metadataKey: metadataValue})
c.Pools[0].Gun.ReflectMetadata = &md
c.Pools[0].Gun.ReflectMetadata = map[string]string{metadataKey: metadataValue}
}),
},
{
Expand All @@ -177,8 +176,7 @@ func TestCheckGRPCReflectServer(t *testing.T) {
{
name: "wrong metadata value",
conf: parseFileContentToCliConfig(t, baseFile, func(c *PandoraConfigGRPC) {
md := metadata.New(map[string]string{metadataKey: "wrong-value"})
c.Pools[0].Gun.ReflectMetadata = &md
c.Pools[0].Gun.ReflectMetadata = map[string]string{metadataKey: "wrong-value"}
}),
err: wrongMDValueError,
},
Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance/testdata/grpc/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pools:
target: localhost:18888
tls: false
use-shared-client: false
reflect_metadata:
auth: Token
ammo:
type: grpc/json
file: testdata/grpc/grpc.payload
Expand Down

0 comments on commit 8740306

Please sign in to comment.