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

Method StartAndReturnService

cmd/tempo/app/server_service.go:82–132  ·  view source on GitHub ↗
(cfg server.Config, supportGRPCOnHTTP bool, servicesToWaitFor func() []services.Service)

Source from the content-addressed store, hash-verified

80}
81
82func (s *tempoServer) StartAndReturnService(cfg server.Config, supportGRPCOnHTTP bool, servicesToWaitFor func() []services.Service) (services.Service, error) {
83 var err error
84
85 metrics := server.NewServerMetrics(cfg)
86 DisableSignalHandling(&cfg)
87
88 if !supportGRPCOnHTTP {
89 // We don't do any GRPC handling, let the library handle all routing for us
90 cfg.Router = s.mux
91
92 s.externalServer, err = server.NewWithMetrics(cfg, metrics)
93 if err != nil {
94 return nil, fmt.Errorf("failed to create server: %w", err)
95 }
96 s.handler = s.externalServer.HTTPServer.Handler
97 } else {
98 // We want to route both GRPC and HTTP requests on the same endpoint
99 cfg.Router = nil
100 cfg.DoNotAddDefaultHTTPMiddleware = true // we don't want instrumentation on the "root" router, we want it on our mux. it will be added below.
101
102 s.externalServer, err = server.NewWithMetrics(cfg, metrics)
103 if err != nil {
104 return nil, fmt.Errorf("failed to create server: %w", err)
105 }
106
107 // now that we have created the server and service let's setup our grpc/http router if necessary
108 // for grpc to work we must enable h2c on the external server
109 s.EnableHTTP2()
110
111 // recreate dskit instrumentation here
112 cfg.DoNotAddDefaultHTTPMiddleware = false
113 httpMiddleware, err := server.BuildHTTPMiddleware(cfg, s.mux, metrics, s.externalServer.Log)
114 if err != nil {
115 return nil, fmt.Errorf("failed to create http middleware: %w", err)
116 }
117
118 s.handler = middleware.Merge(httpMiddleware...).Wrap(s.mux)
119 s.externalServer.HTTP.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
120 // route to GRPC server if it's a GRPC request
121 if req.ProtoMajor == 2 && strings.Contains(req.Header.Get("Content-Type"), "application/grpc") {
122 s.externalServer.GRPC.ServeHTTP(w, req)
123 return
124 }
125
126 // default to standard http server
127 s.handler.ServeHTTP(w, req)
128 })
129 }
130
131 return NewServerService(s.externalServer, servicesToWaitFor), nil
132}
133
134// NewServerService constructs service from Server component.
135// servicesToWaitFor is called when server is stopping, and should return all

Callers

nothing calls this directly

Calls 7

EnableHTTP2Method · 0.95
DisableSignalHandlingFunction · 0.85
NewServerServiceFunction · 0.85
MergeMethod · 0.80
WrapMethod · 0.65
GetMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected