Skip to content

Commit

Permalink
remove fatal logs
Browse files Browse the repository at this point in the history
remove fatal logs
  • Loading branch information
oke11o committed Oct 2, 2023
1 parent d0d396f commit 967b9a8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
1 change: 0 additions & 1 deletion .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 13 additions & 9 deletions components/guns/grpc/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"log"
"time"

"github.com/golang/protobuf/proto"
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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() {
Expand All @@ -156,21 +157,22 @@ 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()
message := dynamic.NewMessage(md)
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
}

Expand All @@ -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 {
Expand Down Expand Up @@ -270,3 +272,5 @@ func convertGrpcStatus(err error) int {
return 500
}
}

var _ warmup.WarmedUp = (*Gun)(nil)
12 changes: 0 additions & 12 deletions components/guns/grpc/core_tests/core_test.go

This file was deleted.

14 changes: 10 additions & 4 deletions core/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 967b9a8

Please sign in to comment.