Fix query builder generation of aggregates

Updated the query builder generation of the appropriate JSON for the
aggregates required for a metric. This is the bare minimum change to
support the new format, it does not allow for multiple aggregates per
metric.