add context cancellation check at get series result iteration (#13766)

* add context cancellation check at get series iteration
* add warnings and closer on error
* add test

---------

Signed-off-by: Erlan Zholdubai uulu <erlanz@amazon.com>
This commit is contained in:
Erlan Zholdubai uulu 2024-03-19 10:37:43 -07:00 committed by GitHub
parent 16164226e5
commit 742196b6c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View File

@ -882,6 +882,9 @@ func (api *API) series(r *http.Request) (result apiFuncResult) {
warnings := set.Warnings()
for set.Next() {
if err := ctx.Err(); err != nil {
return apiFuncResult{nil, returnAPIError(err), warnings, closer}
}
metrics = append(metrics, set.At().Labels())
if len(metrics) >= limit {

View File

@ -3568,6 +3568,9 @@ func TestReturnAPIError(t *testing.T) {
}, {
err: errors.New("exec error"),
expected: errorExec,
}, {
err: context.Canceled,
expected: errorCanceled,
},
}