Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Metricbeat] gcp: fix instance machineType reporting (#27363)
Refresh instance metadata for each incoming response by updating the `s.computeMetadata` field in the `metadataCollector` struct. The code was applying a sort of caching to the computeMetadata, but in the wrong place. Most probably it was a leftover, as a proper caching for instance metadata is implemented in the `instance` function on line 146. Due to this check `computeMetadata` were not refreshed for each response. `metadataCollector` is instanciated only once for the entire module. Thus by not overriding `computeMetadata` the metadata of the first response handled was used for all subsequent events. Removing the check make the code update the `s.computeMetadata` property for each new response. With this update the correct metadata based on the instance ID reported in the response are used. Fixes a bug were all metrics were being reported with the same `machineType`. NOTE: the code update the same struct field at each iteration; this is most probably not safe in a parallel execution context; this code is not running multiple times in different threads so for the moment this change should not have negative side effects.
- Loading branch information