google-cloud-platformpercentilegoogle-cloud-metricsmonitoring-query-language

Chart multiple percentiles from distributions using Google MQL


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.


Solution

  • 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