Skip to content

Commit

Permalink
grpc scenario err
Browse files Browse the repository at this point in the history
61bcfb6f21a0647117de24e3b6230d5f14ec118a
  • Loading branch information
oke11o committed Apr 27, 2024
1 parent 32f96c6 commit 40815db
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
3 changes: 2 additions & 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.23"
const Version = "0.5.24.alpha1"
const defaultConfigFile = "load"
const stdinConfigSelector = "-"

Expand Down Expand Up @@ -218,6 +218,7 @@ func readConfig(args []string) *CliConfig {
}
}

log.Info("Pandora version", zap.String("version", Version))
if useStdinConfig {
v.SetConfigType("yaml")
configBuffer, err := ioutil.ReadAll(bufio.NewReader(os.Stdin))
Expand Down
20 changes: 14 additions & 6 deletions components/guns/grpc/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,35 @@ func (g *Gun) shoot(ammo *ammo.Ammo) {
g.GunDeps.Log.Error("response error", zap.Error(err))
}

g.Answ(&method, message, ammo.Metadata, out, grpcErr, code)
}

func (g *Gun) Answ(method *desc.MethodDescriptor, message *dynamic.Message, metadata map[string]string, out proto.Message, grpcErr error, code int) {
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, metadata, out, grpcErr)

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

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

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 (g *Gun) AnswLogging(logger *zap.Logger, method *desc.MethodDescriptor, request proto.Message, metadata map[string]string, response proto.Message, grpcErr error) {
logger.Debug("Request:", zap.Stringer("method", method), zap.Stringer("message", request), zap.Any("metadata", metadata))
if response != nil {
logger.Debug("Response:", zap.Stringer("resp", response), zap.Error(grpcErr))
} else {
logger.Debug("Response:", zap.String("resp", "empty"), zap.Error(grpcErr))
}
}

func (g *Gun) makeConnect() (conn *grpc.ClientConn, err error) {
Expand Down
22 changes: 5 additions & 17 deletions components/guns/grpc/scenario/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func (g *Gun) shoot(ammo *Scenario, templateVars map[string]any) error {

requestVars := map[string]any{}
templateVars["request"] = requestVars
if g.gun.DebugLog {
g.gun.GunDeps.Log.Debug("Source variables", zap.Any("variables", templateVars))
}

startAt := time.Now()
for _, call := range ammo.Calls {
Expand Down Expand Up @@ -156,7 +159,7 @@ func (g *Gun) shootStep(step *Call, sample *netsample.Sample, ammoName string, t
}
preprocVars = mergeMaps(preprocVars, pp)
if g.gun.DebugLog {
g.gun.GunDeps.Log.Debug("PreparePreprocessor variables", zap.Any(fmt.Sprintf(".resuest.%s.preprocessor", step.Name), pp))
g.gun.GunDeps.Log.Debug("PreparePreprocessor variables", zap.Any(fmt.Sprintf(".request.%s.preprocessor", step.Name), pp))
}
}
stepVars["preprocessor"] = preprocVars
Expand Down Expand Up @@ -200,22 +203,7 @@ func (g *Gun) shootStep(step *Call, sample *netsample.Sample, ammoName string, t
g.gun.GunDeps.Log.Error("response error", zap.Error(err))
}

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

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

case "error":
if code >= 500 {
g.gun.AnswLogging(g.gun.AnswLog, &method, message, out, grpcErr)
}
}
}
g.gun.Answ(&method, message, step.Metadata, out, grpcErr, code)

for _, postProcessor := range step.Postprocessors {
pp, err := postProcessor.Process(out, code)
Expand Down
2 changes: 1 addition & 1 deletion components/guns/http_scenario/gun.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (g *ScenarioGun) shootStep(step Request, sample *netsample.Sample, ammoName
var dumpErr error
reqBytes, dumpErr = httputil.DumpRequestOut(req, true)
if dumpErr != nil {
g.base.Log.Error("Error dumping request: %s", zap.Error(dumpErr))
g.base.Log.Error("Error dumping request:", zap.Error(dumpErr))
}
}

Expand Down

0 comments on commit 40815db

Please sign in to comment.