From 3f3e57d06747e8349c3cf44fca85222fe2d91510 Mon Sep 17 00:00:00 2001 From: Gabriel Pop <94497545+gpop63@users.noreply.github.com> Date: Tue, 3 Sep 2024 20:01:58 +0300 Subject: [PATCH] [GCP] Log `ListTimeSeries` and `AggregatedList` requests duration (#40661) * log total time taken for ListTimeSeries requests * add changelog entry * fix PR id * log total time taken for AggregatedList request * update changelog entry * remove log * Update x-pack/metricbeat/module/gcp/metrics/compute/metadata.go Co-authored-by: subham sarkar * Update x-pack/metricbeat/module/gcp/metrics/metrics_requester.go Co-authored-by: subham sarkar * Update x-pack/metricbeat/module/gcp/metrics/compute/metadata.go Co-authored-by: Harnish Chavda <118714680+harnish-elastic@users.noreply.github.com> * Update x-pack/metricbeat/module/gcp/metrics/metrics_requester.go Co-authored-by: Harnish Chavda <118714680+harnish-elastic@users.noreply.github.com> --------- Co-authored-by: subham sarkar Co-authored-by: Harnish Chavda <118714680+harnish-elastic@users.noreply.github.com> --- CHANGELOG.next.asciidoc | 1 + x-pack/metricbeat/module/gcp/metrics/compute/metadata.go | 6 ++++++ x-pack/metricbeat/module/gcp/metrics/metrics_requester.go | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 832d3f6a99e..471b87d03af 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -324,6 +324,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Add SSL support for aerospike module {pull}38126[38126] - Add new metricset network for the vSphere module. {pull}40559[40559] - Add new metricset resourcepool for the vSphere module. {pull}40456[40456] +- Log the total time taken for GCP `ListTimeSeries` and `AggregatedList` requests {pull}40661[40661] *Metricbeat* diff --git a/x-pack/metricbeat/module/gcp/metrics/compute/metadata.go b/x-pack/metricbeat/module/gcp/metrics/compute/metadata.go index c215e471b45..eb9f5971303 100644 --- a/x-pack/metricbeat/module/gcp/metrics/compute/metadata.go +++ b/x-pack/metricbeat/module/gcp/metrics/compute/metadata.go @@ -10,6 +10,7 @@ import ( "fmt" "strconv" "strings" + "time" compute "cloud.google.com/go/compute/apiv1" "cloud.google.com/go/compute/apiv1/computepb" @@ -188,6 +189,11 @@ func (s *metadataCollector) getComputeInstances(ctx context.Context) { defer instancesClient.Close() + start := time.Now() + defer func() { + s.logger.Debugf("Total time taken for compute AggregatedList request: %s", time.Since(start)) + }() + it := instancesClient.AggregatedList(ctx, &computepb.AggregatedListInstancesRequest{ Project: s.projectID, }) diff --git a/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go b/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go index e7e7f081e52..d33d710f77a 100644 --- a/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go +++ b/x-pack/metricbeat/module/gcp/metrics/metrics_requester.go @@ -124,6 +124,11 @@ func (r *metricsRequester) Metrics(ctx context.Context, serviceName string, alig } } + start := time.Now() + defer func() { + r.logger.Debugf("Total time taken for all ListTimeSeries requests: %s and config period: %s", time.Since(start), r.config.period.AsDuration()) + }() + for mt, meta := range metricsToCollect { wg.Add(1)