Skip to content

Commit

Permalink
merged setup and run grpc server groups
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Sharma <[email protected]>
  • Loading branch information
yashrsharma44 committed May 21, 2021
1 parent 4be0b7b commit d55a0aa
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down

0 comments on commit d55a0aa

Please sign in to comment.