grafana / iot-sitewise-datasource

IoT Sitewise
Apache License 2.0
19 stars 9 forks source link

perf(api): batch APIs queries to request for maximum number of datapo… #310

Closed chejimmy closed 2 months ago

chejimmy commented 2 months ago

…ints

What this PR does / why we need it:

Grafana has a default behavior to set query's maxDataPoints to a somewhat low number (compares to the SiteWise APIs maximum), and causes unnecessary pagination for queries with high response data points. It creates unnecessary latency and request (TPS) load to the server.

For example, for 6 hour time range - the maxDataPoints is auto set to ~500, and requires ~50 request for 6 hours of 1 second data points = 6hr60min/hr60sec/min / 432maxDataPoints/request.

This PR updates the batch APIs queries to request for maximum number of datapoints the SiteWise APIs can support for a better UX.

Before this PR - GetPropertyValueHistory for 6 hr took ~10 seconds:

https://github.com/grafana/iot-sitewise-datasource/assets/50635800/134cd459-e7d3-451c-b3a6-b331360f802b

After this PR - GetPropertyValueHistory for 6 hr took ~1.5 seconds:

https://github.com/grafana/iot-sitewise-datasource/assets/50635800/e74a527e-6b5a-4ec2-8d98-079cc8b1a7b7

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

chejimmy commented 2 months ago

Hi @chejimmy ! Overall looks good and makes sense to me, but I think you need to add "datapoints" to the words section in cspell.config.json to pass the spell check (and the ci). You can double check it locally by running yarn spellcheck

I see; updated to data points instead to conform to the existing spelling 👍