From 67bbc702d4bbfcca167a7c30444f38631d12ab32 Mon Sep 17 00:00:00 2001 From: Edoardo Tenani Date: Wed, 14 Jul 2021 17:03:38 +0200 Subject: [PATCH] gcp: log metrics without descriptors 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. --- 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) } } }