diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aa2b897b4..7378a00e65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ * [CHANGE] Store Gateway: Remove `idle_timeout`, `max_conn_age`, `pool_size`, `min_idle_conns` fields for Redis index cache and caching bucket. #5448 * [CHANGE] Store Gateway: Add flag `-store-gateway.sharding-ring.zone-stable-shuffle-sharding` to enable store gateway to use zone stable shuffle sharding. #5489 * [CHANGE] Bucket Index: Add `series_max_size` and `chunk_max_size` to bucket index. #5489 +* [CHANGE] Query Frontend/Querier: Make build info API disabled by default and add feature flag `api.build-info-enabled` to enable it. #5533 * [FEATURE] Store Gateway: Add `max_downloaded_bytes_per_request` to limit max bytes to download per store gateway request. * [FEATURE] Added 2 flags `-alertmanager.alertmanager-client.grpc-max-send-msg-size` and ` -alertmanager.alertmanager-client.grpc-max-recv-msg-size` to configure alert manager grpc client message size limits. #5338 * [FEATURE] Query Frontend: Add `cortex_rejected_queries_total` metric for throttled queries. #5356 diff --git a/docs/configuration/config-file-reference.md b/docs/configuration/config-file-reference.md index 076267f92b..3a4932f5a0 100644 --- a/docs/configuration/config-file-reference.md +++ b/docs/configuration/config-file-reference.md @@ -91,6 +91,10 @@ api: # CLI flag: -server.cors-origin [cors_origin: | default = ".*"] + # If enabled, build Info API will be served by query frontend or querier. + # CLI flag: -api.build-info-enabled + [build_info_enabled: | default = false] + # The server_config configures the HTTP and gRPC server of the launched # service(s). [server: ] diff --git a/pkg/api/api.go b/pkg/api/api.go index fb4efdcb04..6171150ae8 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -71,12 +71,15 @@ type Config struct { // This sets the Origin header value corsRegexString string `yaml:"cors_origin"` + + buildInfoEnabled bool `yaml:"build_info_enabled"` } // RegisterFlags adds the flags required to config this to the given FlagSet. func (cfg *Config) RegisterFlags(f *flag.FlagSet) { f.BoolVar(&cfg.ResponseCompression, "api.response-compression-enabled", false, "Use GZIP compression for API responses. Some endpoints serve large YAML or JSON blobs which can benefit from compression.") f.Var(&cfg.HTTPRequestHeadersToLog, "api.http-request-headers-to-log", "Which HTTP Request headers to add to logs") + f.BoolVar(&cfg.buildInfoEnabled, "api.build-info-enabled", false, "If enabled, build Info API will be served by query frontend or querier.") cfg.RegisterFlagsWithPrefix("", f) } @@ -389,8 +392,6 @@ func (a *API) RegisterQueryable( // RegisterQueryAPI registers the Prometheus API routes with the provided handler. func (a *API) RegisterQueryAPI(handler http.Handler) { - infoHandler := &buildInfoHandler{logger: a.logger} - hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { httputil.SetCORS(w, a.corsOrigin, r) handler.ServeHTTP(w, r) @@ -404,7 +405,6 @@ func (a *API) RegisterQueryAPI(handler http.Handler) { a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/label/{name}/values"), hf, true, "GET") a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/series"), hf, true, "GET", "POST", "DELETE") a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/metadata"), hf, true, "GET") - a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/status/buildinfo"), infoHandler, true, "GET") // Register Legacy Routers a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/read"), hf, true, "POST") @@ -415,11 +415,16 @@ func (a *API) RegisterQueryAPI(handler http.Handler) { a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/label/{name}/values"), hf, true, "GET") a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/series"), hf, true, "GET", "POST", "DELETE") a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/metadata"), hf, true, "GET") - a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/status/buildinfo"), infoHandler, true, "GET") + + if a.cfg.buildInfoEnabled { + infoHandler := &buildInfoHandler{logger: a.logger} + a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/status/buildinfo"), infoHandler, true, "GET") + a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/status/buildinfo"), infoHandler, true, "GET") + } } -// RegisterQueryFrontend registers the Prometheus routes supported by the -// Cortex querier service. Currently this can not be registered simultaneously +// RegisterQueryFrontendHandler registers the Prometheus routes supported by the +// Cortex querier service. Currently, this can not be registered simultaneously // with the Querier. func (a *API) RegisterQueryFrontendHandler(h http.Handler) { a.RegisterQueryAPI(h) diff --git a/pkg/api/handlers.go b/pkg/api/handlers.go index caa5367039..a1aa3daed8 100644 --- a/pkg/api/handlers.go +++ b/pkg/api/handlers.go @@ -268,7 +268,6 @@ func NewQuerierHandler( router.Path(path.Join(prefix, "/api/v1/label/{name}/values")).Methods("GET").Handler(promRouter) router.Path(path.Join(prefix, "/api/v1/series")).Methods("GET", "POST", "DELETE").Handler(promRouter) router.Path(path.Join(prefix, "/api/v1/metadata")).Methods("GET").Handler(promRouter) - router.Path(path.Join(prefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(promRouter) // TODO(gotjosh): This custom handler is temporary until we're able to vendor the changes in: // https://github.com/prometheus/prometheus/pull/7125/files @@ -282,7 +281,11 @@ func NewQuerierHandler( router.Path(path.Join(legacyPrefix, "/api/v1/label/{name}/values")).Methods("GET").Handler(legacyPromRouter) router.Path(path.Join(legacyPrefix, "/api/v1/series")).Methods("GET", "POST", "DELETE").Handler(legacyPromRouter) router.Path(path.Join(legacyPrefix, "/api/v1/metadata")).Methods("GET").Handler(legacyPromRouter) - router.Path(path.Join(legacyPrefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(legacyPromRouter) + + if cfg.buildInfoEnabled { + router.Path(path.Join(prefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(promRouter) + router.Path(path.Join(legacyPrefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(legacyPromRouter) + } // Track execution time. return stats.NewWallTimeMiddleware().Wrap(router) diff --git a/pkg/api/handlers_test.go b/pkg/api/handlers_test.go index a641f3e242..8a3b614aeb 100644 --- a/pkg/api/handlers_test.go +++ b/pkg/api/handlers_test.go @@ -230,7 +230,7 @@ func TestBuildInfoAPI(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - cfg := Config{} + cfg := Config{buildInfoEnabled: true} version.Version = tc.version version.Branch = tc.branch version.Revision = tc.revision