grafana/contribute/architecture/frontend-data-requests.md
Joseph Perez f09f21b5bb
Docs: Edit of data requests and breaking changes docs (part 4 of Contribute doc quality project) (#88858)
* Docs: data requests and breaking changes edit

* Update contribute/architecture/frontend-data-requests.md

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

* Fixes from review

* Update contribute/architecture/frontend-data-requests.md

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

* Update contribute/architecture/frontend-data-requests.md

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

* Update contribute/breaking-changes-guide/breaking-changes-guide.md

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

* Fix from review

* Update contribute/breaking-changes-guide/breaking-changes-guide.md

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

* Update contribute/breaking-changes-guide/breaking-changes-guide.md

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

* Fix from review

* Update contribute/breaking-changes-guide/breaking-changes-guide.md

Co-authored-by: Beverly Buchanan <131809838+BeverlyJaneJ@users.noreply.github.com>

* Fixes from review

* Update contribute/breaking-changes-guide/breaking-changes-guide.md

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

* Fix from review

* Fix from review

* Fix alt text

* Remove 1st person

* Fix from review

* Eliminate 'in case'

---------

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: Beverly Buchanan <131809838+BeverlyJaneJ@users.noreply.github.com>
2024-06-11 14:57:22 -07:00

3.2 KiB

Frontend data requests

BackendSrv handles all outgoing HTTP requests from Grafana. This document explains the high-level concepts used by BackendSrv.

Cancel requests

While data sources can implement their own cancellation concept, we recommend that you use the method described in this section.

A data request can take a long time to finish. During the time between when a request starts and finishes, the user can change context. For example, the user may navigate away or issue the same request again.

If we wait for canceled requests to complete, they might create unnecessary load on the data sources.

Request cancellation by Grafana version

Grafana uses a concept called request cancellation to cancel any ongoing request that Grafana doesn't need. The process for canceling requests in this manner varies by Grafana version.

Before Grafana 7.2

Before Grafana can cancel any data request, it has to identify that request. Grafana identifies a request using the property requestId passed as options when you use BackendSrv.

The cancellation logic is as follows:

  • When an ongoing request discovers that an additional request with the same requestId has started, then Grafana will cancel the ongoing request.
  • When an ongoing request discovers that the special "cancel all requests" requestId was sent, then Grafana will cancel the ongoing request.

After Grafana 7.2

Grafana 7.2 introduced an additional way of canceling requests using RxJs. To support the new cancellation functionality, the data source needs to use the new fetch function in BackendSrv.

Migrating the core data sources to the new fetch function is an ongoing process. To learn more, refer to this issue.

Request queue

If Grafana isn't configured to support HTTP/2, browsers connecting with HTTP 1.1 enforce a limit of 4 to 8 parallel requests (the specific limit varies). Because of this limit, if some requests take a long time, they will block later requests and make interacting with Grafana very slow.

Enabling HTTP/2 support in Grafana allows far more parallel requests.

Before Grafana 7.2

Not supported.

After Grafana 7.2

Grafana uses a request queue to process all incoming data requests in order while reserving a free "spot" for any requests to the Grafana API.

Since the first implementation of the request queue doesn't take into account what browser the user uses, the request queue's limit for parallel data source requests is hard-coded to 5.

Note: Grafana instances configured with HTTP/2 have a hard-coded limit of 1000.