Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 27663a7

Browse files
gaplykrghetia
authored andcommitted
Fix an issue with multiple calls of Autodetec func (#117)
1 parent 81dc1cd commit 27663a7

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

monitoredresource/monitored_resources.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ func (aws *AWSEC2Instance) MonitoredResource() (resType string, labels map[strin
143143
// For resource definition go to https://cloud.google.com/monitoring/api/resources
144144
func Autodetect() Interface {
145145
return func() Interface {
146-
var autoDetected Interface
147-
var awsIdentityDoc *awsIdentityDocument
148-
var gcpMetadata *gcpMetadata
149146
detectOnce.Do(func() {
147+
var awsIdentityDoc *awsIdentityDocument
148+
var gcpMetadata *gcpMetadata
150149

151150
// First attempts to retrieve AWS Identity Doc and GCP metadata.
152151
// It then determines the resource type
@@ -214,6 +213,9 @@ func createGKEContainerMonitoredResource(gcpMetadata *gcpMetadata) *GKEContainer
214213
// detectOnce is used to make sure GCP and AWS metadata detect function executes only once.
215214
var detectOnce sync.Once
216215

216+
// autoDetected is the metadata detected after the first execution of Autodetect function.
217+
var autoDetected Interface
218+
217219
// detectResourceType determines the resource type.
218220
// awsIdentityDoc contains AWS EC2 attributes. nil if it is not AWS EC2 environment
219221
// gcpMetadata contains GCP (GKE or GCE) specific attributes.

0 commit comments

Comments
 (0)