Creating a stacked area distribution percentile graph in Google Cloud Monitoring

I found what seems to be the answer on stackoverflow after reading the Monitoring Query Language docs.

union_group_by allows you to chart multiple time series at once which would allow stacked area graph to work correctly. I searched for examples of usage and came across this stack overflow post which had been posted recently.

Essentially, you create a table of percentiles from your latency data and then pass it to union_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 resulting graph is stacked correctly but uses a different interpolation than when using the basic editor's percentile aligner. The values seem roughly correct though.