-
Notifications
You must be signed in to change notification settings - Fork 692
Restore tempo_request_duration_seconds metrics for querier_api_* requests #3403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,8 @@ import ( | |
| ) | ||
|
|
||
| type TempoServer interface { | ||
| HTTP() *mux.Router | ||
| HTTPRouter() *mux.Router | ||
| HTTPHandler() http.Handler | ||
| GRPC() *grpc.Server | ||
| Log() log.Logger | ||
| EnableHTTP2() | ||
|
|
@@ -32,7 +33,8 @@ type TempoServer interface { | |
|
|
||
| // todo: evaluate whether the internal server should be included as part of this | ||
| type tempoServer struct { | ||
| mux *mux.Router // all tempo http routes are added here | ||
| mux *mux.Router // all tempo http routes are added here | ||
| handler http.Handler // the final handler which includes the router and any middleware | ||
|
|
||
| externalServer *server.Server // the standard server that all HTTP/GRPC requests are served on | ||
| enableHTTP2Once sync.Once | ||
|
|
@@ -45,10 +47,14 @@ func newTempoServer() *tempoServer { | |
| } | ||
| } | ||
|
|
||
| func (s *tempoServer) HTTP() *mux.Router { | ||
| func (s *tempoServer) HTTPRouter() *mux.Router { | ||
| return s.mux | ||
| } | ||
|
|
||
| func (s *tempoServer) HTTPHandler() http.Handler { | ||
| return s.handler | ||
| } | ||
|
|
||
| func (s *tempoServer) GRPC() *grpc.Server { | ||
| return s.externalServer.GRPC | ||
| } | ||
|
|
@@ -71,22 +77,28 @@ func (s *tempoServer) StartAndReturnService(cfg server.Config, supportGRPCOnHTTP | |
| var err error | ||
|
|
||
| metrics := server.NewServerMetrics(cfg) | ||
| // use tempo's mux unless we are doing grpc over http, then we will let the library instantiate its own | ||
| // router and piggy back on it to route grpc requests | ||
| cfg.Router = s.mux | ||
| if supportGRPCOnHTTP { | ||
| DisableSignalHandling(&cfg) | ||
|
|
||
| if !supportGRPCOnHTTP { | ||
| // We don't do any GRPC handling, let the library handle all routing for us | ||
| cfg.Router = s.mux | ||
|
|
||
| s.externalServer, err = server.NewWithMetrics(cfg, metrics) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create server: %w", err) | ||
| } | ||
| s.handler = s.externalServer.HTTPServer.Handler | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @joe-elliott we were really close while pairing. We used
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so close! |
||
| } else { | ||
| // We want to route both GRPC and HTTP requests on the same endpoint | ||
| cfg.Router = nil | ||
| cfg.DoNotAddDefaultHTTPMiddleware = true // we don't want instrumentation on the "root" router, we want it on our mux. it will be added below. | ||
| } | ||
|
|
||
| DisableSignalHandling(&cfg) | ||
| s.externalServer, err = server.NewWithMetrics(cfg, metrics) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create server: %w", err) | ||
| } | ||
| s.externalServer, err = server.NewWithMetrics(cfg, metrics) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create server: %w", err) | ||
| } | ||
|
|
||
| // now that we have created the server and service let's setup our grpc/http router if necessary | ||
| if supportGRPCOnHTTP { | ||
| // now that we have created the server and service let's setup our grpc/http router if necessary | ||
| // for grpc to work we must enable h2c on the external server | ||
| s.EnableHTTP2() | ||
|
|
||
|
|
@@ -96,7 +108,8 @@ func (s *tempoServer) StartAndReturnService(cfg server.Config, supportGRPCOnHTTP | |
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create http middleware: %w", err) | ||
| } | ||
| router := middleware.Merge(httpMiddleware...).Wrap(s.mux) | ||
|
|
||
| s.handler = middleware.Merge(httpMiddleware...).Wrap(s.mux) | ||
| s.externalServer.HTTP.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
| // route to GRPC server if it's a GRPC request | ||
| if req.ProtoMajor == 2 && strings.Contains(req.Header.Get("Content-Type"), "application/grpc") { | ||
|
|
@@ -105,7 +118,7 @@ func (s *tempoServer) StartAndReturnService(cfg server.Config, supportGRPCOnHTTP | |
| } | ||
|
|
||
| // default to standard http server | ||
| router.ServeHTTP(w, req) | ||
| s.handler.ServeHTTP(w, req) | ||
| }) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like this rename for clarity