mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #15823 from yeya24/slow-down-ctx-check
Less frequent context check for series API
This commit is contained in:
commit
6a8afa60b5
|
@ -68,6 +68,9 @@ const (
|
||||||
// Non-standard status code (originally introduced by nginx) for the case when a client closes
|
// Non-standard status code (originally introduced by nginx) for the case when a client closes
|
||||||
// the connection while the server is still processing the request.
|
// the connection while the server is still processing the request.
|
||||||
statusClientClosedConnection = 499
|
statusClientClosedConnection = 499
|
||||||
|
|
||||||
|
// checkContextEveryNIterations is used in some tight loops to check if the context is done.
|
||||||
|
checkContextEveryNIterations = 128
|
||||||
)
|
)
|
||||||
|
|
||||||
type errorType string
|
type errorType string
|
||||||
|
@ -962,10 +965,15 @@ func (api *API) series(r *http.Request) (result apiFuncResult) {
|
||||||
|
|
||||||
warnings := set.Warnings()
|
warnings := set.Warnings()
|
||||||
|
|
||||||
|
i := 1
|
||||||
for set.Next() {
|
for set.Next() {
|
||||||
|
if i%checkContextEveryNIterations == 0 {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return apiFuncResult{nil, returnAPIError(err), warnings, closer}
|
return apiFuncResult{nil, returnAPIError(err), warnings, closer}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
|
||||||
metrics = append(metrics, set.At().Labels())
|
metrics = append(metrics, set.At().Labels())
|
||||||
|
|
||||||
if limit > 0 && len(metrics) > limit {
|
if limit > 0 && len(metrics) > limit {
|
||||||
|
|
Loading…
Reference in a new issue