Skip to content

Commit

Permalink
fix: Resource fetching performance improvement for Scaleway (tailward…
Browse files Browse the repository at this point in the history
…en#1212)

Co-authored-by: Azanul Haque <[email protected]>
  • Loading branch information
tanbirali and Azanul committed Dec 6, 2023
1 parent d344687 commit cad8aff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func triggerFetchingWorfklow(ctx context.Context, client providers.ProviderClien
case "Azure":
azure.FetchResources(ctx, client, db, telemetry, analytics, wp)
case "Scaleway":
scaleway.FetchResources(ctx, client, db, telemetry, analytics)
scaleway.FetchResources(ctx, client, db, telemetry, analytics, wp)
case "MongoDBAtlas":
mongodbatlas.FetchResources(ctx, client, db, telemetry, analytics, wp)
case "GCP":
Expand Down
36 changes: 19 additions & 17 deletions providers/scaleway/scaleway.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,26 @@ func listOfSupportedServices() []providers.FetchDataFunction {
}
}

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics) {
for _, fetchResources := range listOfSupportedServices() {
resources, err := fetchResources(ctx, client)
if err != nil {
log.Printf("[%s][Scaleway] %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 {
logrus.WithError(err).Errorf("db trigger failed")
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() {
resources, err := fetchResources(ctx, client)
if err != nil {
log.Printf("[%s][Scaleway] %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 {
logrus.WithError(err).Errorf("db trigger failed")
}
}
if telemetry {
analytics.TrackEvent("discovered_resources", map[string]interface{}{
"provider": "Scaleway",
"resources": len(resources),
})
}
}
if telemetry {
analytics.TrackEvent("discovered_resources", map[string]interface{}{
"provider": "Scaleway",
"resources": len(resources),
})
}
}
}
})
}

0 comments on commit cad8aff

Please sign in to comment.