CloudMonitoring: Ignore min and max aggregation in MQL queries (#41302)

* ignore min and max aggregations in mql queries

* refine comment

* moving continuation check to the top of the loop

* remove empty line

* lint issue
This commit is contained in:
Erik Sundell
2021-11-05 13:09:22 +01:00
committed by GitHub
parent 07754351b7
commit a852ddc10d
5 changed files with 618 additions and 376 deletions

View File

@@ -59,8 +59,6 @@ func (timeSeriesQuery cloudMonitoringTimeSeriesQuery) run(ctx context.Context, r
span.SetTag("query", timeSeriesQuery.Query)
span.SetTag("from", req.Queries[0].TimeRange.From)
span.SetTag("until", req.Queries[0].TimeRange.To)
span.SetTag("datasource_id", dsInfo.id)
span.SetTag("org_id", req.PluginContext.OrgID)
defer span.Finish()
@@ -125,6 +123,14 @@ func (timeSeriesQuery cloudMonitoringTimeSeriesQuery) parseResponse(queryRes *ba
}
for n, d := range response.TimeSeriesDescriptor.PointDescriptors {
// If more than 1 pointdescriptor was returned, three aggregations are returned per time series - min, mean and max.
// This is a because the period for the given table is less than half the duration which is used in the graph_period MQL function.
// See https://cloud.google.com/monitoring/mql/reference#graph_period-tabop
// When this is the case, we'll just ignore the min and max and use the mean value in the frame
if len(response.TimeSeriesDescriptor.PointDescriptors) > 1 && !strings.HasSuffix(d.Key, ".mean") {
continue
}
if _, ok := labels["metric.name"]; !ok {
labels["metric.name"] = map[string]bool{}
}