MCPcopy
hub / github.com/grafana/tempo / NewServerService

Function NewServerService

cmd/tempo/app/server_service.go:139–175  ·  view source on GitHub ↗

NewServerService constructs service from Server component. servicesToWaitFor is called when server is stopping, and should return all services that need to terminate before server actually stops. N.B.: this function is NOT Cortex specific, please let's keep it that way. Passed server should not reac

(serv *server.Server, servicesToWaitFor func() []services.Service)

Source from the content-addressed store, hash-verified

137// N.B.: this function is NOT Cortex specific, please let's keep it that way.
138// Passed server should not react on signals. Early return from Run function is considered to be an error.
139func NewServerService(serv *server.Server, servicesToWaitFor func() []services.Service) services.Service {
140 serverDone := make(chan error, 1)
141
142 runFn := func(ctx context.Context) error {
143 go func() {
144 defer close(serverDone)
145 serverDone <- serv.Run()
146 }()
147
148 select {
149 case <-ctx.Done():
150 return nil
151 case err := <-serverDone:
152 if err != nil {
153 return err
154 }
155 return fmt.Errorf("server stopped unexpectedly")
156 }
157 }
158
159 stoppingFn := func(_ error) error {
160 // wait until all modules are done, and then shutdown server.
161 for _, s := range servicesToWaitFor() {
162 _ = s.AwaitTerminated(context.Background())
163 }
164
165 // shutdown HTTP and gRPC servers (this also unblocks Run)
166 serv.Shutdown()
167
168 // if not closed yet, wait until server stops.
169 <-serverDone
170 level.Info(util_log.Logger).Log("msg", "server stopped")
171 return nil
172 }
173
174 return services.NewBasicService(nil, runFn, stoppingFn)
175}
176
177// DisableSignalHandling puts a dummy signal handler
178func DisableSignalHandling(config *server.Config) {

Callers 2

initInternalServerMethod · 0.85
StartAndReturnServiceMethod · 0.85

Calls 4

DoneMethod · 0.65
ShutdownMethod · 0.65
LogMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected