percentile - Calculate percentiles of numerical values
The percentile
function will calculate the approximate n-th percentile from a data of numbers that are passed into it.
Syntax
Arguments
Name | Type | Required | Description |
---|---|---|---|
percentile | number | true | The percentile value we wish to find, between 0 and 1 |
expression | number | true | The expression whose percentile we seek |
error_threshold | number | false | The accuracy we should use. Lower numbers are more accurate. Defaults to 0.01 |
Controlling accuracy
Since the percentile calculation is approximate, the accuracy may be controlled with the error_threshold
parameter which ranges from 0
to 1
(defaults to 0.01
). A lower value will result in better accuracy at the cost of longer query times.
For example, the following query will be very fast but possibly inaccurate:
Whereas the following query will be much more accurate, but may slow down your query time:
It's important to draw a balance between performance and precision, depending on your use case.
Example - Calculating 99th percentile from trace data
Let's say we're interested in the 99th percentile of a lambda function. We have trace data, and the lambda function's operation name is Lambda.Invoke
. We can then run the following query to compute its 99th percentile:
source spans
| filter $l.operationName == 'Lambda.Invoke'
| groupby $l.operationName agg percentile(0.99, $m.duration)