From da3ae202f07d2148f57074d777bbc51111a97754 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 25 May 2022 19:18:36 +0300 Subject: [PATCH] [#1436] node: Log service initialization/boot up Signed-off-by: Pavel Karpy --- cmd/neofs-node/control.go | 4 ++- cmd/neofs-node/main.go | 51 ++++++++++++++++++++++++++------------- cmd/neofs-node/metrics.go | 4 ++- cmd/neofs-node/morph.go | 4 ++- cmd/neofs-node/pprof.go | 4 ++- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/cmd/neofs-node/control.go b/cmd/neofs-node/control.go index ea6c7ced0..33e184277 100644 --- a/cmd/neofs-node/control.go +++ b/cmd/neofs-node/control.go @@ -55,7 +55,9 @@ func initControlService(c *cfg) { control.RegisterControlServiceServer(c.cfgControlService.server, ctlSvc) c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) { - fatalOnErr(c.cfgControlService.server.Serve(lis)) + runAndLog(c, "control", false, func(c *cfg) { + fatalOnErr(c.cfgControlService.server.Serve(lis)) + }) })) } diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index 6cc5ebad5..a38eec6b2 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -66,32 +66,49 @@ func main() { shutdown(c) } +func initAndLog(c *cfg, name string, initializer func(*cfg)) { + c.log.Info(fmt.Sprintf("initializing %s service...", name)) + initializer(c) + c.log.Info(fmt.Sprintf("%s service has been successfully initialized", name)) +} + func initApp(c *cfg) { c.ctx, c.ctxCancel = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) - initGRPC(c) + initAndLog(c, "gRPC", initGRPC) + initAndLog(c, "netmap", initNetmapService) + initAndLog(c, "accounting", initAccountingService) + initAndLog(c, "container", initContainerService) + initAndLog(c, "session", initSessionService) + initAndLog(c, "reputation", initReputationService) + initAndLog(c, "notification", initNotifications) + initAndLog(c, "object", initObjectService) + initAndLog(c, "profiler", initProfiler) + initAndLog(c, "metrics", initMetrics) + initAndLog(c, "control", initControlService) - initNetmapService(c) - initAccountingService(c) - initContainerService(c) - initSessionService(c) - initReputationService(c) - initNotifications(c) - initObjectService(c) - initProfiler(c) - initMetrics(c) - initControlService(c) + initAndLog(c, "storage engine", func(c *cfg) { + fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open()) + fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Init()) + }) - fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open()) - fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Init()) + initAndLog(c, "morph notifications", listenMorphNotifications) +} - listenMorphNotifications(c) +func runAndLog(c *cfg, name string, logSuccess bool, starter func(*cfg)) { + c.log.Info(fmt.Sprintf("starting %s service...", name)) + starter(c) + + if logSuccess { + c.log.Info(fmt.Sprintf("%s service started successfully", name)) + } } func bootUp(c *cfg) { - connectNats(c) - serveGRPC(c) - makeAndWaitNotaryDeposit(c) + runAndLog(c, "NATS", true, connectNats) + runAndLog(c, "gRPC", false, serveGRPC) + runAndLog(c, "notary", true, makeAndWaitNotaryDeposit) + bootstrapNode(c) startWorkers(c) } diff --git a/cmd/neofs-node/metrics.go b/cmd/neofs-node/metrics.go index d837dc9c7..04275d626 100644 --- a/cmd/neofs-node/metrics.go +++ b/cmd/neofs-node/metrics.go @@ -27,7 +27,9 @@ func initMetrics(c *cfg) { ) c.workers = append(c.workers, newWorkerFromFunc(func(context.Context) { - fatalOnErr(srv.Serve()) + runAndLog(c, "metrics", false, func(c *cfg) { + fatalOnErr(srv.Serve()) + }) })) c.closers = append(c.closers, func() { diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index 6f0f023e7..befd3a006 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -207,7 +207,9 @@ func listenMorphNotifications(c *cfg) { fatalOnErr(err) c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) { - lis.ListenWithError(ctx, c.internalErr) + runAndLog(c, "morph notification", false, func(c *cfg) { + lis.ListenWithError(ctx, c.internalErr) + }) })) setNetmapNotificationParser(c, newEpochNotification, netmapEvent.ParseNewEpoch) diff --git a/cmd/neofs-node/pprof.go b/cmd/neofs-node/pprof.go index 5332fafbe..727de5489 100644 --- a/cmd/neofs-node/pprof.go +++ b/cmd/neofs-node/pprof.go @@ -26,7 +26,9 @@ func initProfiler(c *cfg) { ) c.workers = append(c.workers, newWorkerFromFunc(func(context.Context) { - fatalOnErr(srv.Serve()) + runAndLog(c, "profiler", false, func(c *cfg) { + fatalOnErr(srv.Serve()) + }) })) c.closers = append(c.closers, func() {