Skip to content

Commit 08b97b2

Browse files
committed
support Prometheus /api/v1/status/buildinfo API
Signed-off-by: Ben Ye <[email protected]>
1 parent bb8c097 commit 08b97b2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pkg/api/api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ type Distributor interface {
352352
UserStatsHandler(w http.ResponseWriter, r *http.Request)
353353
}
354354

355-
// RegisterQueryable registers the the default routes associated with the querier
355+
// RegisterQueryable registers the default routes associated with the querier
356356
// module.
357357
func (a *API) RegisterQueryable(
358358
queryable storage.SampleAndChunkQueryable,
@@ -374,6 +374,7 @@ func (a *API) RegisterQueryAPI(handler http.Handler) {
374374
a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/label/{name}/values"), handler, true, "GET")
375375
a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/series"), handler, true, "GET", "POST", "DELETE")
376376
a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/metadata"), handler, true, "GET")
377+
a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/status/buildinfo"), handler, true, "GET")
377378

378379
// Register Legacy Routers
379380
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/read"), handler, true, "POST")
@@ -384,6 +385,7 @@ func (a *API) RegisterQueryAPI(handler http.Handler) {
384385
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/label/{name}/values"), handler, true, "GET")
385386
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/series"), handler, true, "GET", "POST", "DELETE")
386387
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/metadata"), handler, true, "GET")
388+
a.RegisterRoute(path.Join(a.cfg.LegacyHTTPPrefix, "/api/v1/status/buildinfo"), handler, true, "GET")
387389
}
388390

389391
// RegisterQueryFrontend registers the Prometheus routes supported by the

pkg/api/handlers.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/prometheus/client_golang/prometheus/promauto"
1616
dto "github.com/prometheus/client_model/go"
1717
"github.com/prometheus/common/route"
18+
"github.com/prometheus/common/version"
1819
"github.com/prometheus/prometheus/config"
1920
"github.com/prometheus/prometheus/storage"
2021
v1 "github.com/prometheus/prometheus/web/api/v1"
@@ -194,7 +195,7 @@ func NewQuerierHandler(
194195
api := v1.NewAPI(
195196
engine,
196197
querier.NewErrorTranslateSampleAndChunkQueryable(queryable), // Translate errors to errors expected by API.
197-
nil, // No remote write support.
198+
nil, // No remote write support.
198199
exemplarQueryable,
199200
func(context.Context) v1.TargetRetriever { return &querier.DummyTargetRetriever{} },
200201
func(context.Context) v1.AlertmanagerRetriever { return &querier.DummyAlertmanagerRetriever{} },
@@ -211,7 +212,11 @@ func NewQuerierHandler(
211212
false,
212213
regexp.MustCompile(".*"),
213214
func() (v1.RuntimeInfo, error) { return v1.RuntimeInfo{}, errors.New("not implemented") },
214-
&v1.PrometheusVersion{},
215+
&v1.PrometheusVersion{
216+
Version: version.Version,
217+
Branch: version.Branch,
218+
Revision: version.Revision,
219+
},
215220
// This is used for the stats API which we should not support. Or find other ways to.
216221
prometheus.GathererFunc(func() ([]*dto.MetricFamily, error) { return nil, nil }),
217222
reg,
@@ -255,6 +260,7 @@ func NewQuerierHandler(
255260
router.Path(path.Join(prefix, "/api/v1/label/{name}/values")).Methods("GET").Handler(promRouter)
256261
router.Path(path.Join(prefix, "/api/v1/series")).Methods("GET", "POST", "DELETE").Handler(promRouter)
257262
router.Path(path.Join(prefix, "/api/v1/metadata")).Methods("GET").Handler(promRouter)
263+
router.Path(path.Join(prefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(promRouter)
258264

259265
// TODO(gotjosh): This custom handler is temporary until we're able to vendor the changes in:
260266
// https://github.com/prometheus/prometheus/pull/7125/files
@@ -268,6 +274,7 @@ func NewQuerierHandler(
268274
router.Path(path.Join(legacyPrefix, "/api/v1/label/{name}/values")).Methods("GET").Handler(legacyPromRouter)
269275
router.Path(path.Join(legacyPrefix, "/api/v1/series")).Methods("GET", "POST", "DELETE").Handler(legacyPromRouter)
270276
router.Path(path.Join(legacyPrefix, "/api/v1/metadata")).Methods("GET").Handler(legacyPromRouter)
277+
router.Path(path.Join(legacyPrefix, "/api/v1/status/buildinfo")).Methods("GET").Handler(legacyPromRouter)
271278

272279
// Track execution time.
273280
return stats.NewWallTimeMiddleware().Wrap(router)

0 commit comments

Comments
 (0)