Skip to content

Commit 29c40f7

Browse files
authored
Add feature flag to enable build info API (#5533)
* put buildinfo behind a feature flag to unblock grafana usage Signed-off-by: Ben Ye <[email protected]> * update doc Signed-off-by: Ben Ye <[email protected]> * changelog Signed-off-by: Ben Ye <[email protected]> * fix test Signed-off-by: Ben Ye <[email protected]> --------- Signed-off-by: Ben Ye <[email protected]>
1 parent f240583 commit 29c40f7

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* [CHANGE] Store Gateway: Remove `idle_timeout`, `max_conn_age`, `pool_size`, `min_idle_conns` fields for Redis index cache and caching bucket. #5448
2020
* [CHANGE] Store Gateway: Add flag `-store-gateway.sharding-ring.zone-stable-shuffle-sharding` to enable store gateway to use zone stable shuffle sharding. #5489
2121
* [CHANGE] Bucket Index: Add `series_max_size` and `chunk_max_size` to bucket index. #5489
22+
* [CHANGE] Query Frontend/Querier: Make build info API disabled by default and add feature flag `api.build-info-enabled` to enable it. #5533
2223
* [FEATURE] Store Gateway: Add `max_downloaded_bytes_per_request` to limit max bytes to download per store gateway request.
2324
* [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
2425
* [FEATURE] Query Frontend: Add `cortex_rejected_queries_total` metric for throttled queries. #5356

docs/configuration/config-file-reference.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ api:
9191
# CLI flag: -server.cors-origin
9292
[cors_origin: <string> | default = ".*"]
9393

94+
# If enabled, build Info API will be served by query frontend or querier.
95+
# CLI flag: -api.build-info-enabled
96+
[build_info_enabled: <boolean> | default = false]
97+
9498
# The server_config configures the HTTP and gRPC server of the launched
9599
# service(s).
96100
[server: <server_config>]

pkg/api/api.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,15 @@ type Config struct {
7171

7272
// This sets the Origin header value
7373
corsRegexString string `yaml:"cors_origin"`
74+
75+
buildInfoEnabled bool `yaml:"build_info_enabled"`
7476
}
7577

7678
// RegisterFlags adds the flags required to config this to the given FlagSet.
7779
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
7880
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.")
7981
f.Var(&cfg.HTTPRequestHeadersToLog, "api.http-request-headers-to-log", "Which HTTP Request headers to add to logs")
82+
f.BoolVar(&cfg.buildInfoEnabled, "api.build-info-enabled", false, "If enabled, build Info API will be served by query frontend or querier.")
8083
cfg.RegisterFlagsWithPrefix("", f)
8184
}
8285

@@ -389,8 +392,6 @@ func (a *API) RegisterQueryable(
389392

390393
// RegisterQueryAPI registers the Prometheus API routes with the provided handler.
391394
func (a *API) RegisterQueryAPI(handler http.Handler) {
392-
infoHandler := &buildInfoHandler{logger: a.logger}
393-
394395
hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
395396
httputil.SetCORS(w, a.corsOrigin, r)
396397
handler.ServeHTTP(w, r)
@@ -404,7 +405,6 @@ func (a *API) RegisterQueryAPI(handler http.Handler) {
404405
a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/label/{name}/values"), hf, true, "GET")
405406
a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/series"), hf, true, "GET", "POST", "DELETE")
406407
a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/metadata"), hf, true, "GET")
407-
a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/status/buildinfo"), infoHandler, true, "GET")
408408

409409
// Register Legacy Routers
410410
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/read"), hf, true, "POST")
@@ -415,11 +415,16 @@ func (a *API) RegisterQueryAPI(handler http.Handler) {
415415
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/label/{name}/values"), hf, true, "GET")
416416
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/series"), hf, true, "GET", "POST", "DELETE")
417417
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/metadata"), hf, true, "GET")
418-
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/status/buildinfo"), infoHandler, true, "GET")
418+
419+
if a.cfg.buildInfoEnabled {
420+
infoHandler := &buildInfoHandler{logger: a.logger}
421+
a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/status/buildinfo"), infoHandler, true, "GET")
422+
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/status/buildinfo"), infoHandler, true, "GET")
423+
}
419424
}
420425

421-
// RegisterQueryFrontend registers the Prometheus routes supported by the
422-
// Cortex querier service. Currently this can not be registered simultaneously
426+
// RegisterQueryFrontendHandler registers the Prometheus routes supported by the
427+
// Cortex querier service. Currently, this can not be registered simultaneously
423428
// with the Querier.
424429
func (a *API) RegisterQueryFrontendHandler(h http.Handler) {
425430
a.RegisterQueryAPI(h)

pkg/api/handlers.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ func NewQuerierHandler(
268268
router.Path(path.Join(prefix, "/api/v1/label/{name}/values")).Methods("GET").Handler(promRouter)
269269
router.Path(path.Join(prefix, "/api/v1/series")).Methods("GET", "POST", "DELETE").Handler(promRouter)
270270
router.Path(path.Join(prefix, "/api/v1/metadata")).Methods("GET").Handler(promRouter)
271-
router.Path(path.Join(prefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(promRouter)
272271

273272
// TODO(gotjosh): This custom handler is temporary until we're able to vendor the changes in:
274273
// https://github.com/prometheus/prometheus/pull/7125/files
@@ -282,7 +281,11 @@ func NewQuerierHandler(
282281
router.Path(path.Join(legacyPrefix, "/api/v1/label/{name}/values")).Methods("GET").Handler(legacyPromRouter)
283282
router.Path(path.Join(legacyPrefix, "/api/v1/series")).Methods("GET", "POST", "DELETE").Handler(legacyPromRouter)
284283
router.Path(path.Join(legacyPrefix, "/api/v1/metadata")).Methods("GET").Handler(legacyPromRouter)
285-
router.Path(path.Join(legacyPrefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(legacyPromRouter)
284+
285+
if cfg.buildInfoEnabled {
286+
router.Path(path.Join(prefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(promRouter)
287+
router.Path(path.Join(legacyPrefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(legacyPromRouter)
288+
}
286289

287290
// Track execution time.
288291
return stats.NewWallTimeMiddleware().Wrap(router)

pkg/api/handlers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func TestBuildInfoAPI(t *testing.T) {
230230
},
231231
} {
232232
t.Run(tc.name, func(t *testing.T) {
233-
cfg := Config{}
233+
cfg := Config{buildInfoEnabled: true}
234234
version.Version = tc.version
235235
version.Branch = tc.branch
236236
version.Revision = tc.revision

0 commit comments

Comments
 (0)