diff --git a/providers/aws/aws.go b/providers/aws/aws.go index dfb0931ff..889fc4644 100644 --- a/providers/aws/aws.go +++ b/providers/aws/aws.go @@ -3,6 +3,7 @@ package aws import ( "context" "strings" + "sync" log "github.com/sirupsen/logrus" @@ -100,28 +101,34 @@ func FetchResources(ctx context.Context, client providers.ProviderClient, region log.Infof("Komiser will fetch resources from the following regions: %s", strings.Join(regions, ",")) listOfSupportedRegions = regions } - + var sncResource sync.WaitGroup for _, region := range listOfSupportedRegions { client.AWSClient.Region = region + for _, fetchResources := range listOfSupportedServices() { - resources, err := fetchResources(ctx, client) - if err != nil { - log.Warnf("[%s][AWS] %s", client.Name, err) - } else { - for _, resource := range resources { - _, err = db.NewInsert().Model(&resource).On("CONFLICT (resource_id) DO UPDATE").Set("cost = EXCLUDED.cost").Exec(context.Background()) - if err != nil { - log.WithError(err).Errorf("db trigger failed") + sncResource.Add(1) + go func(fetchResources providers.FetchDataFunction) { + resources, err := fetchResources(ctx, client) + if err != nil { + log.Warnf("[%s][AWS] %s", client.Name, err) + } else { + for _, resource := range resources { + _, err = db.NewInsert().Model(&resource).On("CONFLICT (resource_id) DO UPDATE").Set("cost = EXCLUDED.cost").Exec(context.Background()) + if err != nil { + log.WithError(err).Errorf("db trigger failed") + } + } + if telemetry { + analytics.TrackEvent("discovered_resources", map[string]interface{}{ + "provider": "AWS", + "resources": len(resources), + }) } } - if telemetry { - analytics.TrackEvent("discovered_resources", map[string]interface{}{ - "provider": "AWS", - "resources": len(resources), - }) - } - } + sncResource.Done() + }(fetchResources) } + sncResource.Wait() } }