Chart multiple percentiles from distributions using Google MQL

1.1k Views Asked by At

How does one plot multiple lines, such as different percentiles, in a single chart based on a single distribution metric using MQL in Google Cloud Platform?

The following query will draw a graph with the 50th percentile from a distribution metric:

fetch global::logging.googleapis.com/user/my_metrics.response_time |
percentile_from 50

The my_metrics.response_time is a logs-based distribution metric with the unit ms, the chart looks like this:

p50 chart

I'd like to plot the 50th, 90th, and 95th percentiles in the same chart as well. My best attempt so far is:

fetch global::logging.googleapis.com/user/my_metrics.response_time |
{
    percentile_from 50
    ;
    percentile_from 90
    ;
    percentile_from 95
} |
union

This only plots a single line again, however (it seems to be the 90th percentile):

fail

The attempt above is based on this example which plots multiple lines from a single metric.

I've tried various alignment functions etc, but I think the problem is just that I don't have a good understanding of the data model. There's probably a group_by [] or outer_join 0 missing somewhere, but I can't wrap my head around it.

2

There are 2 best solutions below

0
On BEST ANSWER

One solution that seems to work is to use union_group_by to do a group by operation with multiple tables as input, in combination with add to create a label to group by:

fetch global::logging.googleapis.com/user/my_metrics.response_time |
{
    percentile_from 50 | add [p: "50th percentile"]
    ;
    percentile_from 90 | add [p: "90th percentile"]
    ;
    percentile_from 95 | add [p: "95th percentile"]
} |
union_group_by [p]

The following chart is produced:

Chart with three lines

0
On

The other answer is clever (and the only way to use a stacked area chart type with percentile lines) but it does complicate configuration compared to the basic editor.

If the goal is to just have multiple percentiles on the same chart there are some other possibilities:

  1. Use heatmap chart type with percentile lines. If your data is of type DISTRIBUTION then choosing Heatmap chart type will immediately give you the option to see all 3 percentile lines on your chart. I usually hide the actual heatmap since I find it distracting.

  2. After you've added your initial percentile line via the basic editor, you can add another almost identical metric to the chart to see both metrics at the same time. These metrics don't work together with respect to area chart types but otherwise look identical to the other answer.