mirror of
https://github.com/prometheus/prometheus.git
synced 2026-02-19 02:29:16 -05:00
Merge pull request #17647 from roidelapluie/roidelapluie/resource-limit-fix
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
web/api: Add maximum limit validation to TSDB status endpoint
This commit is contained in:
commit
e77dd5bec2
3 changed files with 17 additions and 1 deletions
|
|
@ -1346,7 +1346,7 @@ GET /api/v1/status/tsdb
|
|||
```
|
||||
URL query parameters:
|
||||
|
||||
- `limit=<number>`: Limit the number of returned items to a given number for each set of statistics. By default, 10 items are returned.
|
||||
- `limit=<number>`: Limit the number of returned items to a given number for each set of statistics. By default, 10 items are returned. The maximum allowed limit is 10000.
|
||||
|
||||
The `data` section of the query result consists of:
|
||||
|
||||
|
|
|
|||
|
|
@ -1837,12 +1837,16 @@ func (api *API) serveTSDBBlocks(*http.Request) apiFuncResult {
|
|||
}
|
||||
|
||||
func (api *API) serveTSDBStatus(r *http.Request) apiFuncResult {
|
||||
const maxTSDBLimit = 10000
|
||||
limit := 10
|
||||
if s := r.FormValue("limit"); s != "" {
|
||||
var err error
|
||||
if limit, err = strconv.Atoi(s); err != nil || limit < 1 {
|
||||
return apiFuncResult{nil, &apiError{errorBadData, errors.New("limit must be a positive number")}, nil, nil}
|
||||
}
|
||||
if limit > maxTSDBLimit {
|
||||
return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("limit must not exceed %d", maxTSDBLimit)}, nil, nil}
|
||||
}
|
||||
}
|
||||
s, err := api.db.Stats(labels.MetricName, limit)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -4465,6 +4465,18 @@ func TestTSDBStatus(t *testing.T) {
|
|||
values: map[string][]string{"limit": {"0"}},
|
||||
errType: errorBadData,
|
||||
},
|
||||
{
|
||||
db: tsdb,
|
||||
endpoint: tsdbStatusAPI,
|
||||
values: map[string][]string{"limit": {"10000"}},
|
||||
errType: errorNone,
|
||||
},
|
||||
{
|
||||
db: tsdb,
|
||||
endpoint: tsdbStatusAPI,
|
||||
values: map[string][]string{"limit": {"10001"}},
|
||||
errType: errorBadData,
|
||||
},
|
||||
} {
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
api := &API{db: tc.db, gatherer: prometheus.DefaultGatherer}
|
||||
|
|
|
|||
Loading…
Reference in a new issue