Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x](backport #27363) [Metricbeat] gcp: fix instance machineType reporting #27419

Merged
merged 1 commit into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix cloudwatch metricset collecting duplicate data points. {pull}27327[27327]
- 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*

Expand Down
11 changes: 6 additions & 5 deletions x-pack/metricbeat/module/gcp/metrics/compute/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down