diff --git a/providers/aws/aws.go b/providers/aws/aws.go index 71b82d20a..585f19c16 100644 --- a/providers/aws/aws.go +++ b/providers/aws/aws.go @@ -119,6 +119,7 @@ func FetchResources(ctx context.Context, client providers.ProviderClient, region Name: client.Name, } for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources wp.SubmitTask(func() { resources, err := fetchResources(ctx, client) if err != nil { diff --git a/providers/azure/azure.go b/providers/azure/azure.go index ee014ae78..144faa566 100644 --- a/providers/azure/azure.go +++ b/providers/azure/azure.go @@ -32,6 +32,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources wp.SubmitTask(func() { resources, err := fetchResources(ctx, client) if err != nil { diff --git a/providers/civo/civo.go b/providers/civo/civo.go index 80f050f33..663f730d3 100644 --- a/providers/civo/civo.go +++ b/providers/civo/civo.go @@ -30,6 +30,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources regions, err := client.CivoClient.ListRegions() if err != nil { log.Printf("[%s][Civo] %s", client.Name, err) diff --git a/providers/digitalocean/digitalocean.go b/providers/digitalocean/digitalocean.go index 1e9013f56..60fb91308 100644 --- a/providers/digitalocean/digitalocean.go +++ b/providers/digitalocean/digitalocean.go @@ -32,6 +32,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources wp.SubmitTask(func() { resources, err := fetchResources(ctx, client) if err != nil { diff --git a/providers/gcp/gcp.go b/providers/gcp/gcp.go index 4d4c14ba1..794288def 100644 --- a/providers/gcp/gcp.go +++ b/providers/gcp/gcp.go @@ -41,6 +41,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources wp.SubmitTask(func() { resources, err := fetchResources(ctx, client) if err != nil { diff --git a/providers/k8s/k8s.go b/providers/k8s/k8s.go index d162e4cd1..b8c792d91 100644 --- a/providers/k8s/k8s.go +++ b/providers/k8s/k8s.go @@ -30,6 +30,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources wp.SubmitTask(func() { resources, err := fetchResources(ctx, client) if err != nil { diff --git a/providers/linode/linode.go b/providers/linode/linode.go index 50a1b243d..bed1d7430 100644 --- a/providers/linode/linode.go +++ b/providers/linode/linode.go @@ -34,6 +34,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources wp.SubmitTask(func() { resources, err := fetchResources(ctx, client) if err != nil { diff --git a/providers/mongodbatlas/mongodbatlas.go b/providers/mongodbatlas/mongodbatlas.go index 7f5b846f8..ffca9b32e 100644 --- a/providers/mongodbatlas/mongodbatlas.go +++ b/providers/mongodbatlas/mongodbatlas.go @@ -19,6 +19,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources wp.SubmitTask(func() { resources, err := fetchResources(ctx, client) if err != nil { diff --git a/providers/oci/oci.go b/providers/oci/oci.go index 44dbdd272..601932cfb 100644 --- a/providers/oci/oci.go +++ b/providers/oci/oci.go @@ -29,6 +29,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources wp.SubmitTask(func() { resources, err := fetchResources(ctx, client) if err != nil { diff --git a/providers/ovh/ovh.go b/providers/ovh/ovh.go index 11c264741..ddbd6d1d1 100644 --- a/providers/ovh/ovh.go +++ b/providers/ovh/ovh.go @@ -45,6 +45,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { wp.SubmitTask(func() { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources resources, err := fetchResources(ctx, client) if err != nil { log.Printf("[%s][OVH] %s", client.Name, err) diff --git a/providers/providers.go b/providers/providers.go index 1ad5cda48..c3ad76191 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -12,14 +12,14 @@ import ( "github.com/oracle/oci-go-sdk/common" "github.com/ovh/go-ovh/ovh" "github.com/scaleway/scaleway-sdk-go/scw" - . "github.com/tailwarden/komiser/models" + "github.com/tailwarden/komiser/models" tccvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" "go.mongodb.org/atlas/mongodbatlas" "golang.org/x/oauth2/google" "k8s.io/client-go/kubernetes" ) -type FetchDataFunction func(ctx context.Context, client ProviderClient) ([]Resource, error) +type FetchDataFunction func(ctx context.Context, client ProviderClient) ([]models.Resource, error) type ProviderClient struct { AWSClient *aws.Config diff --git a/providers/scaleway/scaleway.go b/providers/scaleway/scaleway.go index 7ad09d926..779945f86 100644 --- a/providers/scaleway/scaleway.go +++ b/providers/scaleway/scaleway.go @@ -31,6 +31,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { wp.SubmitTask(func() { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources resources, err := fetchResources(ctx, client) if err != nil { log.Printf("[%s][Scaleway] %s", client.Name, err) diff --git a/providers/tencent/tencent.go b/providers/tencent/tencent.go index 440415d40..38b3327d5 100644 --- a/providers/tencent/tencent.go +++ b/providers/tencent/tencent.go @@ -3,7 +3,6 @@ package tencent import ( "context" - "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus" "github.com/tailwarden/komiser/providers" @@ -22,6 +21,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) { for _, fetchResources := range listOfSupportedServices() { + fetchResources := fetchResources regions, err := client.TencentClient.DescribeRegionsWithContext(ctx, tccvm.NewDescribeRegionsRequest()) if err != nil { log.Errorf("[%s][Tencent] Couldn't fetch the list of regions: %s", client.Name, err) @@ -45,7 +45,7 @@ func FetchResources(ctx context.Context, client providers.ProviderClient, db *bu 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 { - logrus.WithError(err).Error("db trigger failed") + log.WithError(err).Error("db trigger failed") } } if telemetry {