diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 132c7878a25..9842043a064 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -407,6 +407,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Fix cloudwatch metricset collecting duplicate data points. {pull}27248[27248] - Fix flaky test TestAddCounterInvalidArgWhenQueryClosed. {issue}27312[27312] {pull}27313[27313] - Add percent formatters to system/process {pull}27374[27374] +- Fix instance machineType reporting in compute metricset of GCP module {pull}27363[27363] *Packetbeat* diff --git a/x-pack/metricbeat/module/gcp/metrics/compute/metadata.go b/x-pack/metricbeat/module/gcp/metrics/compute/metadata.go index d7bc006c77e..fbf0a2cc2f5 100644 --- a/x-pack/metricbeat/module/gcp/metrics/compute/metadata.go +++ b/x-pack/metricbeat/module/gcp/metrics/compute/metadata.go @@ -61,11 +61,11 @@ type metadataCollector struct { // Metadata implements googlecloud.MetadataCollector to the known set of labels from a Compute TimeSeries single point of data. func (s *metadataCollector) Metadata(ctx context.Context, resp *monitoringpb.TimeSeries) (gcp.MetadataCollectorData, error) { - if s.computeMetadata == nil { - _, err := s.instanceMetadata(ctx, s.instanceID(resp), s.instanceZone(resp)) - if err != nil { - return gcp.MetadataCollectorData{}, err - } + // NOTE: ignoring the return value because instanceMetadata changes s.computeMetadata in place. + // This is probably not thread safe. + _, err := s.instanceMetadata(ctx, s.instanceID(resp), s.instanceZone(resp)) + if err != nil { + return gcp.MetadataCollectorData{}, err } stackdriverLabels := gcp.NewStackdriverMetadataServiceForTimeSeries(resp) @@ -107,6 +107,7 @@ func (s *metadataCollector) Metadata(ctx context.Context, resp *monitoringpb.Tim // instanceMetadata returns the labels of an instance func (s *metadataCollector) instanceMetadata(ctx context.Context, instanceID, zone string) (*computeMetadata, error) { + // FIXME: remove side effect on metadataCollector instance and use return value instead i, err := s.instance(ctx, instanceID, zone) if err != nil { return nil, errors.Wrapf(err, "error trying to get data from instance '%s' in zone '%s'", instanceID, zone)