From d05538521fe521a3993bb5b65646f5e27d9dbb49 Mon Sep 17 00:00:00 2001 From: endorama <526307+endorama@users.noreply.github.com> Date: Wed, 4 Aug 2021 09:51:07 +0200 Subject: [PATCH] [Metricbeat] gcp: log metrics without descriptors (#26982) 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 452f0fafe2a5ee5b682e7d5a0db6ddb77ba7c73e) --- x-pack/metricbeat/module/gcp/metrics/metricset.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x-pack/metricbeat/module/gcp/metrics/metricset.go b/x-pack/metricbeat/module/gcp/metrics/metricset.go index 7a59434c09b..95e4d0ed9f1 100644 --- a/x-pack/metricbeat/module/gcp/metrics/metricset.go +++ b/x-pack/metricbeat/module/gcp/metrics/metricset.go @@ -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 { @@ -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) } } }