diff --git a/cli/cli.go b/cli/cli.go index a5c0cd01f..a5caee41f 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -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 = "-" @@ -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)) diff --git a/components/guns/grpc/core.go b/components/guns/grpc/core.go index c030a7949..08f2ab8ad 100644 --- a/components/guns/grpc/core.go +++ b/components/guns/grpc/core.go @@ -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) { diff --git a/components/guns/grpc/scenario/core.go b/components/guns/grpc/scenario/core.go index 018c31f89..bed051bfe 100644 --- a/components/guns/grpc/scenario/core.go +++ b/components/guns/grpc/scenario/core.go @@ -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 { @@ -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 @@ -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) diff --git a/components/guns/http_scenario/gun.go b/components/guns/http_scenario/gun.go index 9b173a65b..1bdaf2f8a 100644 --- a/components/guns/http_scenario/gun.go +++ b/components/guns/http_scenario/gun.go @@ -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)) } }