mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
api: Added v1/status/flags endpoint. (#3864)
Endpoint URL: /api/v1/status/flags Example Output: ```json { "status": "success", "data": { "alertmanager.notification-queue-capacity": "10000", "alertmanager.timeout": "10s", "completion-bash": "false", "completion-script-bash": "false", "completion-script-zsh": "false", "config.file": "my_cool_prometheus.yaml", "help": "false", "help-long": "false", "help-man": "false", "log.level": "info", "query.lookback-delta": "5m", "query.max-concurrency": "20", "query.timeout": "2m", "storage.tsdb.max-block-duration": "36h", "storage.tsdb.min-block-duration": "2h", "storage.tsdb.no-lockfile": "false", "storage.tsdb.path": "data/", "storage.tsdb.retention": "15d", "version": "false", "web.console.libraries": "console_libraries", "web.console.templates": "consoles", "web.enable-admin-api": "false", "web.enable-lifecycle": "false", "web.external-url": "", "web.listen-address": "0.0.0.0:9090", "web.max-connections": "512", "web.read-timeout": "5m", "web.route-prefix": "/", "web.user-assets": "" } } ``` Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
This commit is contained in:
parent
675ce533c9
commit
93a63ac5fd
|
@ -278,7 +278,14 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.web.Flags = map[string]string{}
|
cfg.web.Flags = map[string]string{}
|
||||||
|
|
||||||
|
// Exclude kingpin default flags to expose only Prometheus ones.
|
||||||
|
boilerplateFlags := kingpin.New("", "").Version("")
|
||||||
for _, f := range a.Model().Flags {
|
for _, f := range a.Model().Flags {
|
||||||
|
if boilerplateFlags.GetFlag(f.Name) != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
cfg.web.Flags[f.Name] = f.Value.String()
|
cfg.web.Flags[f.Name] = f.Value.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -382,6 +382,57 @@ $ curl http://localhost:9090/api/v1/alertmanagers
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
Following status endpoints expose current Prometheus configuration.
|
||||||
|
|
||||||
|
### Config
|
||||||
|
|
||||||
|
The following endpoint returns currently loaded configuration file:
|
||||||
|
|
||||||
|
```
|
||||||
|
GET /api/v1/status/config
|
||||||
|
```
|
||||||
|
|
||||||
|
The config is returned as dumped YAML file. Due to limitation of the YAML
|
||||||
|
library, YAML comments are not included.
|
||||||
|
|
||||||
|
```json
|
||||||
|
$ curl http://localhost:9090/api/v1/status/config
|
||||||
|
{
|
||||||
|
"status": "success",
|
||||||
|
"data": {
|
||||||
|
"yaml": "<content of the loaded config file in YAML>",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Flags
|
||||||
|
|
||||||
|
The following endpoint returns flag values that Prometheus was configured with:
|
||||||
|
|
||||||
|
```
|
||||||
|
GET /api/v1/status/flags
|
||||||
|
```
|
||||||
|
|
||||||
|
All values are in a form of "string".
|
||||||
|
|
||||||
|
```json
|
||||||
|
$ curl http://localhost:9090/api/v1/status/flags
|
||||||
|
{
|
||||||
|
"status": "success",
|
||||||
|
"data": {
|
||||||
|
"alertmanager.notification-queue-capacity": "10000",
|
||||||
|
"alertmanager.timeout": "10s",
|
||||||
|
"log.level": "info",
|
||||||
|
"query.lookback-delta": "5m",
|
||||||
|
"query.max-concurrency": "20",
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*New in v2.2*
|
||||||
|
|
||||||
## TSDB Admin APIs
|
## TSDB Admin APIs
|
||||||
These are APIs that expose database functionalities for the advanced user. These APIs are not enabled unless the `--web.enable-admin-api` is set.
|
These are APIs that expose database functionalities for the advanced user. These APIs are not enabled unless the `--web.enable-admin-api` is set.
|
||||||
|
|
|
@ -114,9 +114,10 @@ type API struct {
|
||||||
targetRetriever targetRetriever
|
targetRetriever targetRetriever
|
||||||
alertmanagerRetriever alertmanagerRetriever
|
alertmanagerRetriever alertmanagerRetriever
|
||||||
|
|
||||||
now func() time.Time
|
now func() time.Time
|
||||||
config func() config.Config
|
config func() config.Config
|
||||||
ready func(http.HandlerFunc) http.HandlerFunc
|
flagsMap map[string]string
|
||||||
|
ready func(http.HandlerFunc) http.HandlerFunc
|
||||||
|
|
||||||
db func() *tsdb.DB
|
db func() *tsdb.DB
|
||||||
enableAdmin bool
|
enableAdmin bool
|
||||||
|
@ -129,6 +130,7 @@ func NewAPI(
|
||||||
tr targetRetriever,
|
tr targetRetriever,
|
||||||
ar alertmanagerRetriever,
|
ar alertmanagerRetriever,
|
||||||
configFunc func() config.Config,
|
configFunc func() config.Config,
|
||||||
|
flagsMap map[string]string,
|
||||||
readyFunc func(http.HandlerFunc) http.HandlerFunc,
|
readyFunc func(http.HandlerFunc) http.HandlerFunc,
|
||||||
db func() *tsdb.DB,
|
db func() *tsdb.DB,
|
||||||
enableAdmin bool,
|
enableAdmin bool,
|
||||||
|
@ -140,6 +142,7 @@ func NewAPI(
|
||||||
alertmanagerRetriever: ar,
|
alertmanagerRetriever: ar,
|
||||||
now: time.Now,
|
now: time.Now,
|
||||||
config: configFunc,
|
config: configFunc,
|
||||||
|
flagsMap: flagsMap,
|
||||||
ready: readyFunc,
|
ready: readyFunc,
|
||||||
db: db,
|
db: db,
|
||||||
enableAdmin: enableAdmin,
|
enableAdmin: enableAdmin,
|
||||||
|
@ -180,6 +183,7 @@ func (api *API) Register(r *route.Router) {
|
||||||
r.Get("/alertmanagers", instr("alertmanagers", api.alertmanagers))
|
r.Get("/alertmanagers", instr("alertmanagers", api.alertmanagers))
|
||||||
|
|
||||||
r.Get("/status/config", instr("config", api.serveConfig))
|
r.Get("/status/config", instr("config", api.serveConfig))
|
||||||
|
r.Get("/status/flags", instr("flags", api.serveFlags))
|
||||||
r.Post("/read", api.ready(prometheus.InstrumentHandler("read", http.HandlerFunc(api.remoteRead))))
|
r.Post("/read", api.ready(prometheus.InstrumentHandler("read", http.HandlerFunc(api.remoteRead))))
|
||||||
|
|
||||||
// Admin APIs
|
// Admin APIs
|
||||||
|
@ -494,6 +498,10 @@ func (api *API) serveConfig(r *http.Request) (interface{}, *apiError) {
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) serveFlags(r *http.Request) (interface{}, *apiError) {
|
||||||
|
return api.flagsMap, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) remoteRead(w http.ResponseWriter, r *http.Request) {
|
func (api *API) remoteRead(w http.ResponseWriter, r *http.Request) {
|
||||||
req, err := remote.DecodeReadRequest(r)
|
req, err := remote.DecodeReadRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -63,6 +63,11 @@ var samplePrometheusCfg = config.Config{
|
||||||
RemoteReadConfigs: []*config.RemoteReadConfig{},
|
RemoteReadConfigs: []*config.RemoteReadConfig{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sampleFlagMap = map[string]string{
|
||||||
|
"flag1": "value1",
|
||||||
|
"flag2": "value2",
|
||||||
|
}
|
||||||
|
|
||||||
func TestEndpoints(t *testing.T) {
|
func TestEndpoints(t *testing.T) {
|
||||||
suite, err := promql.NewTest(t, `
|
suite, err := promql.NewTest(t, `
|
||||||
load 1m
|
load 1m
|
||||||
|
@ -108,9 +113,10 @@ func TestEndpoints(t *testing.T) {
|
||||||
QueryEngine: suite.QueryEngine(),
|
QueryEngine: suite.QueryEngine(),
|
||||||
targetRetriever: tr,
|
targetRetriever: tr,
|
||||||
alertmanagerRetriever: ar,
|
alertmanagerRetriever: ar,
|
||||||
now: func() time.Time { return now },
|
now: func() time.Time { return now },
|
||||||
config: func() config.Config { return samplePrometheusCfg },
|
config: func() config.Config { return samplePrometheusCfg },
|
||||||
ready: func(f http.HandlerFunc) http.HandlerFunc { return f },
|
flagsMap: sampleFlagMap,
|
||||||
|
ready: func(f http.HandlerFunc) http.HandlerFunc { return f },
|
||||||
}
|
}
|
||||||
|
|
||||||
start := time.Unix(0, 0)
|
start := time.Unix(0, 0)
|
||||||
|
@ -449,6 +455,10 @@ func TestEndpoints(t *testing.T) {
|
||||||
YAML: samplePrometheusCfg.String(),
|
YAML: samplePrometheusCfg.String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
endpoint: api.serveFlags,
|
||||||
|
response: sampleFlagMap,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
methods := func(f apiFunc) []string {
|
methods := func(f apiFunc) []string {
|
||||||
|
|
|
@ -187,6 +187,7 @@ func New(logger log.Logger, o *Options) *Handler {
|
||||||
defer h.mtx.RUnlock()
|
defer h.mtx.RUnlock()
|
||||||
return *h.config
|
return *h.config
|
||||||
},
|
},
|
||||||
|
o.Flags,
|
||||||
h.testReady,
|
h.testReady,
|
||||||
h.options.TSDB,
|
h.options.TSDB,
|
||||||
h.options.EnableAdminAPI,
|
h.options.EnableAdminAPI,
|
||||||
|
|
Loading…
Reference in a new issue