From 967b9a85a9a6a23fe4e7a9ba791b8151c318a9b7 Mon Sep 17 00:00:00 2001 From: sabevzenko Date: Mon, 2 Oct 2023 16:13:18 +0300 Subject: [PATCH] remove fatal logs remove fatal logs --- .mapping.json | 1 - components/guns/grpc/core.go | 22 ++++++++++++-------- components/guns/grpc/core_tests/core_test.go | 12 ----------- core/engine/engine.go | 14 +++++++++---- 4 files changed, 23 insertions(+), 26 deletions(-) delete mode 100644 components/guns/grpc/core_tests/core_test.go diff --git a/.mapping.json b/.mapping.json index bd99a754e..dbcbf74c2 100644 --- a/.mapping.json +++ b/.mapping.json @@ -13,7 +13,6 @@ "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/core_tests/core_test.go":"load/projects/pandora/components/guns/grpc/core_tests/core_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", diff --git a/components/guns/grpc/core.go b/components/guns/grpc/core.go index 61fb13b09..4ba807217 100644 --- a/components/guns/grpc/core.go +++ b/components/guns/grpc/core.go @@ -5,7 +5,6 @@ import ( "crypto/tls" "encoding/json" "fmt" - "log" "time" "github.com/golang/protobuf/proto" @@ -19,6 +18,7 @@ import ( "github.com/yandex/pandora/core/warmup" "github.com/yandex/pandora/lib/answlog" "go.uber.org/zap" + "golang.org/x/exp/maps" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" @@ -89,7 +89,8 @@ func (g *Gun) WarmUp(opts *warmup.Options) (interface{}, error) { refClient := grpcreflect.NewClient(refCtx, reflectpb.NewServerReflectionClient(conn)) listServices, err := refClient.ListServices() if err != nil { - opts.Log.Fatal("Fatal: failed to get services list\n %s\n", zap.Error(err)) + g.GunDeps.Log.Error("failed to get services list", zap.Error(err)) + return nil, fmt.Errorf("refClient.ListServices err: %w", err) } services := make(map[string]desc.MethodDescriptor) for _, s := range listServices { @@ -98,7 +99,8 @@ func (g *Gun) WarmUp(opts *warmup.Options) (interface{}, error) { if grpcreflect.IsElementNotFoundError(err) { continue } - opts.Log.Fatal("FATAL ResolveService: %s", zap.Error(err)) + g.GunDeps.Log.Error("cant resolveService", zap.String("service_name", s), zap.Error(err)) + return nil, fmt.Errorf("cant resolveService %s; err: %w", s, err) } listMethods := service.GetMethods() for _, m := range listMethods { @@ -133,7 +135,7 @@ func (g *Gun) Bind(aggr core.Aggregator, deps core.GunDeps) error { g.stub = grpcdynamic.NewStub(conn) if ent := deps.Log.Check(zap.DebugLevel, "Gun bind"); ent != nil { - log.Printf("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") + 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") g.DebugLog = true } @@ -146,7 +148,6 @@ func (g *Gun) Shoot(am core.Ammo) { } func (g *Gun) shoot(ammo *ammo.Ammo) { - code := 0 sample := netsample.Acquire(ammo.Tag) defer func() { @@ -156,13 +157,14 @@ func (g *Gun) shoot(ammo *ammo.Ammo) { method, ok := g.services[ammo.Call] if !ok { - log.Fatalf("Fatal: No such method %s\n", ammo.Call) + g.GunDeps.Log.Error("invalid ammo.Call", zap.String("method", ammo.Call), + zap.Strings("allowed_methods", maps.Keys(g.services))) return } payloadJSON, err := json.Marshal(ammo.Payload) if err != nil { - log.Fatalf("FATAL: Payload parsing error %s\n", err) + g.GunDeps.Log.Error("invalid payload. Cant unmarshal json", zap.Error(err)) return } md := method.GetInputType() @@ -170,7 +172,7 @@ func (g *Gun) shoot(ammo *ammo.Ammo) { err = message.UnmarshalJSON(payloadJSON) if err != nil { code = 400 - log.Printf("BAD REQUEST: %s\n", err) + g.GunDeps.Log.Error("invalid payload. Cant unmarshal gRPC", zap.Error(err)) return } @@ -186,7 +188,7 @@ func (g *Gun) shoot(ammo *ammo.Ammo) { code = convertGrpcStatus(grpcErr) if grpcErr != nil { - log.Printf("Response error: %s\n", grpcErr) + g.GunDeps.Log.Error("response error", zap.Error(err)) } if g.conf.AnswLog.Enabled { @@ -270,3 +272,5 @@ func convertGrpcStatus(err error) int { return 500 } } + +var _ warmup.WarmedUp = (*Gun)(nil) diff --git a/components/guns/grpc/core_tests/core_test.go b/components/guns/grpc/core_tests/core_test.go deleted file mode 100644 index 07c633fe2..000000000 --- a/components/guns/grpc/core_tests/core_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package core - -import ( - "testing" - - "github.com/yandex/pandora/components/guns/grpc" - "github.com/yandex/pandora/core/warmup" -) - -func TestGrpcGunImplementsWarmedUp(t *testing.T) { - _ = warmup.WarmedUp(&grpc.Gun{}) -} diff --git a/core/engine/engine.go b/core/engine/engine.go index c770ac9de..a7484385e 100644 --- a/core/engine/engine.go +++ b/core/engine/engine.go @@ -76,7 +76,7 @@ func (e *Engine) Run(ctx context.Context) error { go func() { err := pool.Run(ctx) select { - case runRes <- poolRunResult{pool.ID, err}: + case runRes <- poolRunResult{ID: pool.ID, Err: err}: case <-ctx.Done(): pool.log.Info("Pool run result suppressed", zap.String("id", pool.ID), zap.Error(err)) @@ -362,9 +362,15 @@ func (p *instancePool) startInstances( newInstanceSchedule func() (core.Schedule, error), runRes chan<- instanceRunResult) (started int, err error) { deps := instanceDeps{ - newInstanceSchedule, - p.NewGun, - instanceSharedDeps{p.Provider, p.metrics, p.gunWarmUpResult, p.Aggregator, p.DiscardOverflow}, + newSchedule: newInstanceSchedule, + newGun: p.NewGun, + instanceSharedDeps: instanceSharedDeps{ + provider: p.Provider, + metrics: p.metrics, + gunWarmUpResult: p.gunWarmUpResult, + aggregator: p.Aggregator, + discardOverflow: p.DiscardOverflow, + }, } waiter := coreutil.NewWaiter(p.StartupSchedule, startCtx)