From d55a0aa738034ad1b80b2654e7fd02fe4c6fbe98 Mon Sep 17 00:00:00 2001 From: Yash Sharma Date: Fri, 21 May 2021 12:14:46 +0530 Subject: [PATCH] merged setup and run grpc server groups Signed-off-by: Yash Sharma --- cmd/thanos/receive.go | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/cmd/thanos/receive.go b/cmd/thanos/receive.go index f8feaca7011..7a107d5ad08 100644 --- a/cmd/thanos/receive.go +++ b/cmd/thanos/receive.go @@ -255,12 +255,9 @@ func runReceive( // startGRPCListening re-starts the gRPC server once it receives a signal. startGRPCListening := make(chan struct{}) - if err := setupGRPCServer(g, logger, reg, tracer, conf, s, startGRPCListening, reloadGRPCServer, comp, dbs, webHandler, grpcLogOpts, tagOpts, grpcProbe); err != nil { + if err := setupAndRunGRPCServer(g, logger, reg, tracer, conf, s, startGRPCListening, reloadGRPCServer, comp, dbs, webHandler, grpcLogOpts, tagOpts, grpcProbe); err != nil { return err } - // if err := runGRPCServer(g, logger, s, startGRPCListening, conf); err != nil { - // return err - // } } level.Debug(logger).Log("msg", "setting up receive http handler") @@ -279,32 +276,9 @@ func runReceive( return nil } -// runGRPCServer starts the grpc server, once it receives a signal from the startGRPCListening channel. -func runGRPCServer(g *run.Group, - logger log.Logger, - s *grpcserver.Server, - startGRPCListening chan struct{}, - conf *receiveConfig, - -) error { - // We need to be able to start and stop the gRPC server - // whenever the DB changes, thus it needs its own run group. - g.Add(func() error { - for range startGRPCListening { - level.Info(logger).Log("msg", "listening for StoreAPI and WritableStoreAPI gRPC", "address", *conf.grpcBindAddr) - if err := s.ListenAndServe(); err != nil { - return errors.Wrap(err, "serve gRPC") - } - } - return nil - }, func(error) {}) - - return nil -} - -// setupGRPCServer sets up the configuration for the gRPC server. +// setupAndRunGRPCServer sets up the configuration for the gRPC server. // It also sets up a handler for reloading the server if tsdb reloads. -func setupGRPCServer(g *run.Group, +func setupAndRunGRPCServer(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer,