Support for time granularity selected in Azure Portal Dashboard (via bin_auto?)
When adding / pinning an Application Insights or Log Analytics chart to the dashboard, you can use the global time selector on the Dashboard to adjust both the the time range (e.g. past 1 hour, past 7 days) and the granularity (e.g. auto, 5 minutes, 1 hour, etc)
However, that works only for the time range, but not for the granularity.
The reason is that whenever you write a query to render a timechart, you have to hardcode the bin size in the query, e.g.:
requests | summarize count() by bin(timestamp, 1m)
Given the query above, I could now choose the time range in the azure portal (e.g. past 30 days), which works as expected, but the chosen time granularity (e.g. 4 hours) would not be considered as it is still hardcoded to 1minute.
Imho this could be implemented via the bin_auto function, so that you don't need to hardcode the bin size in the query anymore, e.g:
requests | summarize count() by bin_auto(timestamp)
However, this currently does not work and produces an error indicating that "querybinauto_size" attribute needs to be set
If Azure Portal would set that "querybinauto_size" under the hood, everything would just work as expected
The following query is how i worked around; this allows you to inject the interval into an existing query easly:
let numberOfBuckets = 25;
let interval = toscalar(requests
| summarize interval = (max(timestamp)-min(timestamp)) / numberOfBuckets
| project max_of(5m,floor(interval, 5m)));
| summarize avg(value) by bin(timestamp,interval)
As a temporary hackish solution, this is what I do:
let timeRange = requests | summarize min = min(timestamp), max = max(timestamp);
let max = toscalar(timeRange | project max);
let min = toscalar(timeRange | project min);
let bin = (max - min)/20;
20 being "how many dots you want in your graph"
then you use `bin` in your aggregation
Please add this feature as it is really useful for user. Thanks in advance.
Torben Knerr commented
See also the related question here:
Official docs for bin_auto() here: