Skip to content

Commit

Permalink
Merge pull request #180 from yandex/dev
Browse files Browse the repository at this point in the history
v0.5.19
  • Loading branch information
oke11o authored Jan 25, 2024
2 parents 33abe68 + 6d5317f commit 068b62b
Show file tree
Hide file tree
Showing 33 changed files with 3,306 additions and 1,111 deletions.
24 changes: 24 additions & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"cli/expvar.go":"load/projects/pandora/cli/expvar.go",
"components/grpc/import/import.go":"load/projects/pandora/components/grpc/import/import.go",
"components/guns/grpc/core.go":"load/projects/pandora/components/guns/grpc/core.go",
"components/guns/grpc/scenario/ammo.go":"load/projects/pandora/components/guns/grpc/scenario/ammo.go",
"components/guns/grpc/scenario/core.go":"load/projects/pandora/components/guns/grpc/scenario/core.go",
"components/guns/grpc/scenario/templater.go":"load/projects/pandora/components/guns/grpc/scenario/templater.go",
"components/guns/grpc/scenario/templater_text.go":"load/projects/pandora/components/guns/grpc/scenario/templater_text.go",
"components/guns/grpc/scenario/templater_text_test.go":"load/projects/pandora/components/guns/grpc/scenario/templater_text_test.go",
"components/guns/http/base.go":"load/projects/pandora/components/guns/http/base.go",
"components/guns/http/base_test.go":"load/projects/pandora/components/guns/http/base_test.go",
"components/guns/http/client.go":"load/projects/pandora/components/guns/http/client.go",
Expand Down Expand Up @@ -79,6 +84,15 @@
"components/providers/scenario/config/decode_test.go":"load/projects/pandora/components/providers/scenario/config/decode_test.go",
"components/providers/scenario/config/hcl.go":"load/projects/pandora/components/providers/scenario/config/hcl.go",
"components/providers/scenario/config/hcl_test.go":"load/projects/pandora/components/providers/scenario/config/hcl_test.go",
"components/providers/scenario/grpc/decode.go":"load/projects/pandora/components/providers/scenario/grpc/decode.go",
"components/providers/scenario/grpc/decode_test.go":"load/projects/pandora/components/providers/scenario/grpc/decode_test.go",
"components/providers/scenario/grpc/postprocessor/assert_response.go":"load/projects/pandora/components/providers/scenario/grpc/postprocessor/assert_response.go",
"components/providers/scenario/grpc/postprocessor/assert_response_test.go":"load/projects/pandora/components/providers/scenario/grpc/postprocessor/assert_response_test.go",
"components/providers/scenario/grpc/postprocessor/postprocessor.go":"load/projects/pandora/components/providers/scenario/grpc/postprocessor/postprocessor.go",
"components/providers/scenario/grpc/preprocessor/prepare.go":"load/projects/pandora/components/providers/scenario/grpc/preprocessor/prepare.go",
"components/providers/scenario/grpc/preprocessor/prepare_test.go":"load/projects/pandora/components/providers/scenario/grpc/preprocessor/prepare_test.go",
"components/providers/scenario/grpc/preprocessor/preprocessor.go":"load/projects/pandora/components/providers/scenario/grpc/preprocessor/preprocessor.go",
"components/providers/scenario/grpc/provider.go":"load/projects/pandora/components/providers/scenario/grpc/provider.go",
"components/providers/scenario/http/decode.go":"load/projects/pandora/components/providers/scenario/http/decode.go",
"components/providers/scenario/http/decode_test.go":"load/projects/pandora/components/providers/scenario/http/decode_test.go",
"components/providers/scenario/http/postprocessor/assert_response.go":"load/projects/pandora/components/providers/scenario/http/postprocessor/assert_response.go",
Expand Down Expand Up @@ -252,6 +266,12 @@
"examples/custom_pandora/custom.yaml":"load/projects/pandora/examples/custom_pandora/custom.yaml",
"examples/custom_pandora/custom_main.go":"load/projects/pandora/examples/custom_pandora/custom_main.go",
"examples/debug_and_profiling.yaml":"load/projects/pandora/examples/debug_and_profiling.yaml",
"examples/grpc/server/Makefile":"load/projects/pandora/examples/grpc/server/Makefile",
"examples/grpc/server/proto/target.proto":"load/projects/pandora/examples/grpc/server/proto/target.proto",
"examples/grpc/server/server.go":"load/projects/pandora/examples/grpc/server/server.go",
"examples/grpc/server/stats.go":"load/projects/pandora/examples/grpc/server/stats.go",
"examples/grpc/server/target.pb.go":"load/projects/pandora/examples/grpc/server/target.pb.go",
"examples/grpc/server/target_grpc.pb.go":"load/projects/pandora/examples/grpc/server/target_grpc.pb.go",
"examples/http.jsonline":"load/projects/pandora/examples/http.jsonline",
"examples/http.yaml":"load/projects/pandora/examples/http.yaml",
"examples/http/server/server.go":"load/projects/pandora/examples/http/server/server.go",
Expand Down Expand Up @@ -321,6 +341,10 @@
"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/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",
"tests/grpc_scenario/testdata/users.csv":"load/projects/pandora/tests/grpc_scenario/testdata/users.csv",
"tests/http_scenario/main_test.go":"load/projects/pandora/tests/http_scenario/main_test.go",
"tests/http_scenario/testdata/filter.json":"load/projects/pandora/tests/http_scenario/testdata/filter.json",
"tests/http_scenario/testdata/http_payload.hcl":"load/projects/pandora/tests/http_scenario/testdata/http_payload.hcl",
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.18"
const Version = "0.5.19"
const defaultConfigFile = "load"
const stdinConfigSelector = "-"

Expand Down
2 changes: 2 additions & 0 deletions components/grpc/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package example
import (
"github.com/spf13/afero"
"github.com/yandex/pandora/components/guns/grpc"
"github.com/yandex/pandora/components/guns/grpc/scenario"
"github.com/yandex/pandora/components/providers/grpc/grpcjson"
"github.com/yandex/pandora/core"
"github.com/yandex/pandora/core/register"
Expand All @@ -20,4 +21,5 @@ func Import(fs afero.Fs) {
})

register.Gun("grpc", grpc.NewGun, grpc.DefaultGunConfig)
register.Gun("grpc/scenario", scenario.NewGun, scenario.DefaultGunConfig)
}
60 changes: 30 additions & 30 deletions components/guns/grpc/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Sample struct {
ShootTimeSeconds float64
}

type grpcDialOptions struct {
type GrpcDialOptions struct {
Authority string `config:"authority"`
Timeout time.Duration `config:"timeout"`
}
Expand All @@ -42,7 +42,7 @@ type GunConfig struct {
Target string `validate:"required"`
Timeout time.Duration `config:"timeout"` // grpc request timeout
TLS bool `config:"tls"`
DialOptions grpcDialOptions `config:"dial_options"`
DialOptions GrpcDialOptions `config:"dial_options"`
AnswLog AnswLogConfig `config:"answlog"`
}

Expand All @@ -54,15 +54,15 @@ type AnswLogConfig struct {

type Gun struct {
DebugLog bool
client *grpc.ClientConn
conf GunConfig
aggr core.Aggregator
Client *grpc.ClientConn
Conf GunConfig
Aggr core.Aggregator
core.GunDeps

stub grpcdynamic.Stub
services map[string]desc.MethodDescriptor
Stub grpcdynamic.Stub
Services map[string]desc.MethodDescriptor

answLog *zap.Logger
AnswLog *zap.Logger
}

func DefaultGunConfig() GunConfig {
Expand All @@ -77,7 +77,7 @@ func DefaultGunConfig() GunConfig {
}

func (g *Gun) WarmUp(opts *warmup.Options) (interface{}, error) {
conn, err := makeGRPCConnect(g.conf.Target, g.conf.TLS, g.conf.DialOptions)
conn, err := MakeGRPCConnect(g.Conf.Target, g.Conf.TLS, g.Conf.DialOptions)
if err != nil {
return nil, fmt.Errorf("failed to connect to target: %w", err)
}
Expand Down Expand Up @@ -114,24 +114,24 @@ func (g *Gun) AcceptWarmUpResult(i interface{}) error {
if !ok {
return fmt.Errorf("grpc WarmUp result should be services: map[string]desc.MethodDescriptor")
}
g.services = services
g.Services = services
return nil
}

func NewGun(conf GunConfig) *Gun {
answLog := answlog.Init(conf.AnswLog.Path, conf.AnswLog.Enabled)
return &Gun{conf: conf, answLog: answLog}
return &Gun{Conf: conf, AnswLog: answLog}
}

func (g *Gun) Bind(aggr core.Aggregator, deps core.GunDeps) error {
conn, err := makeGRPCConnect(g.conf.Target, g.conf.TLS, g.conf.DialOptions)
conn, err := MakeGRPCConnect(g.Conf.Target, g.Conf.TLS, g.Conf.DialOptions)
if err != nil {
return fmt.Errorf("makeGRPCConnect fail %w", err)
}
g.client = conn
g.aggr = aggr
g.Client = conn
g.Aggr = aggr
g.GunDeps = deps
g.stub = grpcdynamic.NewStub(conn)
g.Stub = grpcdynamic.NewStub(conn)

if ent := deps.Log.Check(zap.DebugLevel, "Gun bind"); ent != nil {
deps.Log.Warn("Deprecation Warning: log level: debug doesn't produce request/response logs anymore. Please use AnswLog option instead:\nanswlog:\n enabled: true\n filter: all|warning|error\n path: answ.log")
Expand All @@ -151,13 +151,13 @@ func (g *Gun) shoot(ammo *ammo.Ammo) {
sample := netsample.Acquire(ammo.Tag)
defer func() {
sample.SetProtoCode(code)
g.aggr.Report(sample)
g.Aggr.Report(sample)
}()

method, ok := g.services[ammo.Call]
method, ok := g.Services[ammo.Call]
if !ok {
g.GunDeps.Log.Error("invalid ammo.Call", zap.String("method", ammo.Call),
zap.Strings("allowed_methods", maps.Keys(g.services)))
zap.Strings("allowed_methods", maps.Keys(g.Services)))
return
}

Expand All @@ -176,44 +176,44 @@ func (g *Gun) shoot(ammo *ammo.Ammo) {
}

timeout := defaultTimeout
if g.conf.Timeout != 0 {
timeout = g.conf.Timeout
if g.Conf.Timeout != 0 {
timeout = g.Conf.Timeout
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
ctx = metadata.NewOutgoingContext(ctx, metadata.New(ammo.Metadata))
out, grpcErr := g.stub.InvokeRpc(ctx, &method, message)
code = convertGrpcStatus(grpcErr)
out, grpcErr := g.Stub.InvokeRpc(ctx, &method, message)
code = ConvertGrpcStatus(grpcErr)

if grpcErr != nil {
g.GunDeps.Log.Error("response error", zap.Error(err))
}

if g.conf.AnswLog.Enabled {
switch g.conf.AnswLog.Filter {
if g.Conf.AnswLog.Enabled {
switch g.Conf.AnswLog.Filter {
case "all":
g.answLogging(g.answLog, &method, message, out, grpcErr)
g.AnswLogging(g.AnswLog, &method, message, out, grpcErr)

case "warning":
if code >= 400 {
g.answLogging(g.answLog, &method, message, out, grpcErr)
g.AnswLogging(g.AnswLog, &method, message, out, grpcErr)
}

case "error":
if code >= 500 {
g.answLogging(g.answLog, &method, message, out, grpcErr)
g.AnswLogging(g.AnswLog, &method, message, out, grpcErr)
}
}
}
}

func (g *Gun) answLogging(logger *zap.Logger, method *desc.MethodDescriptor, request proto.Message, response proto.Message, grpcErr error) {
func (g *Gun) AnswLogging(logger *zap.Logger, method *desc.MethodDescriptor, request proto.Message, response proto.Message, grpcErr error) {
logger.Debug("Request:", zap.Stringer("method", method), zap.Stringer("message", request))
logger.Debug("Response:", zap.Stringer("resp", response), zap.Error(grpcErr))
}

func makeGRPCConnect(target string, isTLS bool, dialOptions grpcDialOptions) (conn *grpc.ClientConn, err error) {
func MakeGRPCConnect(target string, isTLS bool, dialOptions GrpcDialOptions) (conn *grpc.ClientConn, err error) {
opts := []grpc.DialOption{}
if isTLS {
opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true})))
Expand All @@ -235,7 +235,7 @@ func makeGRPCConnect(target string, isTLS bool, dialOptions grpcDialOptions) (co
return grpc.DialContext(ctx, target, opts...)
}

func convertGrpcStatus(err error) int {
func ConvertGrpcStatus(err error) int {
s := status.Convert(err)

switch s.Code() {
Expand Down
44 changes: 44 additions & 0 deletions components/guns/grpc/scenario/ammo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package scenario

import (
"time"

"github.com/golang/protobuf/proto"
)

type SourceStorage interface {
Variables() map[string]any
}

type Scenario struct {
id uint64
Calls []Call
Name string
MinWaitingTime time.Duration
VariableStorage SourceStorage
}

func (a *Scenario) SetID(id uint64) {
a.id = id
}

type Call struct {
Name string
Preprocessors []Preprocessor
Postprocessors []Postprocessor

Tag string `json:"tag"`
Call string `json:"call"`
Metadata map[string]string `json:"metadata"`
Payload []byte `json:"payload"`

Sleep time.Duration `json:"sleep"`
}

type Postprocessor interface {
Process(out proto.Message, code int) (map[string]any, error)
}

type Preprocessor interface {
Process(call *Call, templateVars map[string]any) (newVars map[string]any, err error)
}
Loading

0 comments on commit 068b62b

Please sign in to comment.