-
Notifications
You must be signed in to change notification settings - Fork 839
Query frontend single binary #2437
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 10 commits
f380324
23235c7
3496276
90c7f79
50769a3
1fad54c
292a97c
1034ff5
be758dc
9747d43
de982b9
6975138
761e0fe
1742749
8a39488
764ff65
6aac536
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 |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ import ( | |
| "github.com/weaveworks/common/middleware" | ||
| "github.com/weaveworks/common/server" | ||
|
|
||
| "github.com/gorilla/mux" | ||
|
|
||
| "github.com/cortexproject/cortex/pkg/alertmanager" | ||
| "github.com/cortexproject/cortex/pkg/chunk/purger" | ||
| "github.com/cortexproject/cortex/pkg/compactor" | ||
|
|
@@ -79,15 +81,19 @@ func New(cfg Config, s *server.Server, logger log.Logger) (*API, error) { | |
| } | ||
|
|
||
| func (a *API) registerRoute(path string, handler http.Handler, auth bool, methods ...string) { | ||
| a.registerRouteWithRouter(a.server.HTTP, path, handler, auth, methods...) | ||
| } | ||
|
|
||
| func (a *API) registerRouteWithRouter(router *mux.Router, path string, handler http.Handler, auth bool, methods ...string) { | ||
| level.Debug(a.logger).Log("msg", "api: registering route", "methods", strings.Join(methods, ","), "path", path, "auth", auth) | ||
| if auth { | ||
| handler = a.authMiddleware.Wrap(handler) | ||
| } | ||
| if len(methods) == 0 { | ||
| a.server.HTTP.Path(path).Handler(handler) | ||
| router.Path(path).Handler(handler) | ||
| return | ||
| } | ||
| a.server.HTTP.Path(path).Methods(methods...).Handler(handler) | ||
| router.Path(path).Methods(methods...).Handler(handler) | ||
| } | ||
|
|
||
| func (a *API) registerRoutesWithPrefix(prefix string, handler http.Handler, auth bool, methods ...string) { | ||
|
|
@@ -236,7 +242,7 @@ func (a *API) RegisterCompactor(c *compactor.Compactor) { | |
| // RegisterQuerier registers the Prometheus routes supported by the | ||
| // Cortex querier service. Currently this can not be registered simultaneously | ||
| // with the QueryFrontend. | ||
| func (a *API) RegisterQuerier(queryable storage.Queryable, engine *promql.Engine, distributor *distributor.Distributor) { | ||
| func (a *API) RegisterQuerier(queryable storage.Queryable, engine *promql.Engine, distributor *distributor.Distributor, registerRoutesExternally bool) http.Handler { | ||
| api := v1.NewAPI( | ||
| engine, | ||
| queryable, | ||
|
|
@@ -255,36 +261,45 @@ func (a *API) RegisterQuerier(queryable storage.Queryable, engine *promql.Engine | |
| &v1.PrometheusVersion{}, | ||
| ) | ||
|
|
||
| promRouter := route.New().WithPrefix(a.cfg.ServerPrefix + a.cfg.PrometheusHTTPPrefix + "/api/v1") | ||
| api.Register(promRouter) | ||
| promHandler := fakeRemoteAddr(promRouter) | ||
|
|
||
| a.registerRoute(a.cfg.PrometheusHTTPPrefix+"/api/v1/read", querier.RemoteReadHandler(queryable), true, "GET") | ||
| a.registerRoute(a.cfg.PrometheusHTTPPrefix+"/api/v1/query", promHandler, true, "GET", "POST") | ||
| a.registerRoute(a.cfg.PrometheusHTTPPrefix+"/api/v1/query_range", promHandler, true, "GET", "POST") | ||
| a.registerRoute(a.cfg.PrometheusHTTPPrefix+"/api/v1/labels", promHandler, true, "GET", "POST") | ||
| a.registerRoute(a.cfg.PrometheusHTTPPrefix+"/api/v1/label/{name}/values", promHandler, true, "GET") | ||
| a.registerRoute(a.cfg.PrometheusHTTPPrefix+"/api/v1/series", promHandler, true, "GET", "POST", "DELETE") | ||
| a.registerRoute(a.cfg.PrometheusHTTPPrefix+"/api/v1/metadata", promHandler, true, "GET") | ||
|
|
||
| // these routes are always registered to the default server | ||
| a.registerRoute("/api/v1/user_stats", http.HandlerFunc(distributor.UserStatsHandler), true) | ||
| a.registerRoute("/api/v1/chunks", querier.ChunksHandler(queryable), true) | ||
|
|
||
| // Legacy Routes | ||
| a.registerRoute(a.cfg.LegacyHTTPPrefix+"/user_stats", http.HandlerFunc(distributor.UserStatsHandler), true) | ||
| a.registerRoute(a.cfg.LegacyHTTPPrefix+"/chunks", querier.ChunksHandler(queryable), true) | ||
|
|
||
| // these routes are either registered the default server OR to an internal mux. The internal mux is | ||
|
Contributor
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. Hrm, does this mean that when using the single binary mode, do we not expose the querier endpoints at all?
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. That is correct. I purposefully chose this route over path prefixing because I found it cleaner. |
||
| // for use in a single binary mode when both the query frontend and the querier would attempt to claim these routes | ||
| router := mux.NewRouter() | ||
| if registerRoutesExternally { | ||
| router = a.server.HTTP | ||
| } | ||
|
|
||
| promRouter := route.New().WithPrefix(a.cfg.ServerPrefix + a.cfg.PrometheusHTTPPrefix + "/api/v1") | ||
| api.Register(promRouter) | ||
| promHandler := fakeRemoteAddr(promRouter) | ||
|
|
||
| a.registerRouteWithRouter(router, a.cfg.PrometheusHTTPPrefix+"/api/v1/read", querier.RemoteReadHandler(queryable), true, "GET") | ||
| a.registerRouteWithRouter(router, a.cfg.PrometheusHTTPPrefix+"/api/v1/query", promHandler, true, "GET", "POST") | ||
| a.registerRouteWithRouter(router, a.cfg.PrometheusHTTPPrefix+"/api/v1/query_range", promHandler, true, "GET", "POST") | ||
| a.registerRouteWithRouter(router, a.cfg.PrometheusHTTPPrefix+"/api/v1/labels", promHandler, true, "GET", "POST") | ||
| a.registerRouteWithRouter(router, a.cfg.PrometheusHTTPPrefix+"/api/v1/label/{name}/values", promHandler, true, "GET") | ||
| a.registerRouteWithRouter(router, a.cfg.PrometheusHTTPPrefix+"/api/v1/series", promHandler, true, "GET", "POST", "DELETE") | ||
| a.registerRouteWithRouter(router, a.cfg.PrometheusHTTPPrefix+"/api/v1/metadata", promHandler, true, "GET") | ||
|
|
||
| legacyPromRouter := route.New().WithPrefix(a.cfg.ServerPrefix + a.cfg.LegacyHTTPPrefix + "/api/v1") | ||
| api.Register(legacyPromRouter) | ||
| legacyPromHandler := fakeRemoteAddr(legacyPromRouter) | ||
|
|
||
| a.registerRoute(a.cfg.LegacyHTTPPrefix+"/api/v1/read", querier.RemoteReadHandler(queryable), true, "GET") | ||
| a.registerRoute(a.cfg.LegacyHTTPPrefix+"/api/v1/query", legacyPromHandler, true, "GET", "POST") | ||
| a.registerRoute(a.cfg.LegacyHTTPPrefix+"/api/v1/query_range", legacyPromHandler, true, "GET", "POST") | ||
| a.registerRoute(a.cfg.LegacyHTTPPrefix+"/api/v1/labels", legacyPromHandler, true, "GET", "POST") | ||
| a.registerRoute(a.cfg.LegacyHTTPPrefix+"/api/v1/label/{name}/values", legacyPromHandler, true, "GET") | ||
| a.registerRoute(a.cfg.LegacyHTTPPrefix+"/api/v1/series", legacyPromHandler, true, "GET", "POST", "DELETE") | ||
| a.registerRoute(a.cfg.LegacyHTTPPrefix+"/api/v1/metadata", legacyPromHandler, true, "GET") | ||
| a.registerRouteWithRouter(router, a.cfg.LegacyHTTPPrefix+"/api/v1/read", querier.RemoteReadHandler(queryable), true, "GET") | ||
| a.registerRouteWithRouter(router, a.cfg.LegacyHTTPPrefix+"/api/v1/query", legacyPromHandler, true, "GET", "POST") | ||
| a.registerRouteWithRouter(router, a.cfg.LegacyHTTPPrefix+"/api/v1/query_range", legacyPromHandler, true, "GET", "POST") | ||
| a.registerRouteWithRouter(router, a.cfg.LegacyHTTPPrefix+"/api/v1/labels", legacyPromHandler, true, "GET", "POST") | ||
| a.registerRouteWithRouter(router, a.cfg.LegacyHTTPPrefix+"/api/v1/label/{name}/values", legacyPromHandler, true, "GET") | ||
| a.registerRouteWithRouter(router, a.cfg.LegacyHTTPPrefix+"/api/v1/series", legacyPromHandler, true, "GET", "POST", "DELETE") | ||
| a.registerRouteWithRouter(router, a.cfg.LegacyHTTPPrefix+"/api/v1/metadata", legacyPromHandler, true, "GET") | ||
|
|
||
| return router | ||
| } | ||
|
|
||
| // RegisterQueryFrontend registers the Prometheus routes supported by the | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.