Skip to content

Commit

Permalink
[7.x](backport #26982) [Metricbeat] gcp: log metrics without descript…
Browse files Browse the repository at this point in the history
…ors (#27227)

Metrics listed in the light-weight modules are checked with GCP
Stackdriver APIs to gather further information about them.

In case the metric is not valid, the request to the API returns an empty
response and the metric in question is excluded from collection.
There is no error returned from APIs.

In such a case a log line at error level is produced, notifying the user
of the wrong behaviour.

(cherry picked from commit 452f0fa)

Co-authored-by: endorama <526307+endorama@users.noreply.github.com>
  • Loading branch information
mergify[bot] and endorama authored Aug 4, 2021
1 parent 827d91e commit a9d96dd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion x-pack/metricbeat/module/gcp/metrics/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ func (m *MetricSet) metricDescriptor(ctx context.Context, client *monitoring.Met

for _, sdc := range m.MetricsConfig {
for _, mt := range sdc.MetricTypes {
req.Filter = fmt.Sprintf(`metric.type = starts_with("%s")`, sdc.AddPrefixTo(mt))
id := sdc.AddPrefixTo(mt)
req.Filter = fmt.Sprintf(`metric.type = starts_with("%s")`, id)
it := client.ListMetricDescriptors(ctx, req)

for {
Expand All @@ -263,6 +264,14 @@ func (m *MetricSet) metricDescriptor(ctx context.Context, client *monitoring.Met
if err == iterator.Done {
break
}

}

// NOTE: if a metric is not added to the metricsWithMeta map is not collected subsequently.
// Such a case is an error, as the configuration is explicitly requesting a metric that the beat
// is not able to collect, so we provide a logging statement for this behaviour.
if _, ok := metricsWithMeta[id]; !ok {
m.Logger().Errorf("%s metric descriptor is empty, this metric will not be collected", mt)
}
}
}
Expand Down

0 comments on commit a9d96dd

Please sign in to comment.