Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 429 errors in AWS and Azure #1552

Merged
merged 5 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/BurntSushi/toml"
"github.com/aws/aws-sdk-go-v2/aws"
awsConfig "github.com/aws/aws-sdk-go-v2/config"
"github.com/civo/civogo"
"github.com/digitalocean/godo"
Expand Down Expand Up @@ -104,10 +105,11 @@ func Load(configPath string, telemetry bool, analytics utils.Analytics) (*models
Name: account.Name,
})
} else {
cfg, err := awsConfig.LoadDefaultConfig(context.Background(), awsConfig.WithSharedConfigProfile(account.Profile))
cfg, err := awsConfig.LoadDefaultConfig(context.Background(), awsConfig.WithSharedConfigProfile(account.Profile), awsConfig.WithRetryMode(aws.RetryModeAdaptive))
if err != nil {
return nil, nil, nil, err
}

clients = append(clients, providers.ProviderClient{
AWSClient: &cfg,
Name: account.Name,
Expand Down
15 changes: 14 additions & 1 deletion providers/azure/compute/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
log "github.com/sirupsen/logrus"

Expand All @@ -16,7 +17,19 @@ import (
func Disks(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)

svc, err := armcompute.NewDisksClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{})
retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

svc, err := armcompute.NewDisksClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions)
if err != nil {
return resources, err
}
Expand Down
15 changes: 14 additions & 1 deletion providers/azure/compute/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
log "github.com/sirupsen/logrus"

Expand All @@ -16,7 +17,19 @@ import (
func Images(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)

svc, err := armcompute.NewImagesClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{})
retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

svc, err := armcompute.NewImagesClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions)
if err != nil {
return resources, err
}
Expand Down
15 changes: 14 additions & 1 deletion providers/azure/compute/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
log "github.com/sirupsen/logrus"

Expand All @@ -16,7 +17,19 @@ import (
func Snapshots(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)

svc, err := armcompute.NewSnapshotsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{})
retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

svc, err := armcompute.NewSnapshotsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions)
if err != nil {
return resources, err
}
Expand Down
19 changes: 16 additions & 3 deletions providers/azure/compute/virtual_machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy"
armPolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement"
Expand All @@ -19,12 +20,24 @@ import (
func VirtualMachines(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)

svc, err := armcompute.NewVirtualMachinesClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{})
retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

svc, err := armcompute.NewVirtualMachinesClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions)
if err != nil {
return resources, err
}

costClient, err := armcostmanagement.NewQueryClient(client.AzureClient.Credentials, &policy.ClientOptions{})
costClient, err := armcostmanagement.NewQueryClient(client.AzureClient.Credentials, &armPolicy.ClientOptions{})
if err != nil {
return resources, err
}
Expand Down
15 changes: 14 additions & 1 deletion providers/azure/databases/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
Expand All @@ -16,7 +17,19 @@ import (
func Sql(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)

svc, err := armsql.NewServersClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{})
retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

svc, err := armsql.NewServersClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions)

if err != nil {
return resources, err
Expand Down
15 changes: 14 additions & 1 deletion providers/azure/networking/application_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
log "github.com/sirupsen/logrus"

Expand All @@ -16,10 +17,22 @@ import (
func ApplicationGateways(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)

retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

appGatewayClient, err := armnetwork.NewApplicationGatewaysClient(
client.AzureClient.SubscriptionId,
client.AzureClient.Credentials,
&arm.ClientOptions{},
clientOptions,
)
if err != nil {
return resources, err
Expand Down
15 changes: 14 additions & 1 deletion providers/azure/networking/firewalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
log "github.com/sirupsen/logrus"

Expand All @@ -16,7 +17,19 @@ import (
func Firewalls(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)

svc, err := armnetwork.NewAzureFirewallsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{})
retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

svc, err := armnetwork.NewAzureFirewallsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions)
if err != nil {
return resources, err
}
Expand Down
15 changes: 14 additions & 1 deletion providers/azure/networking/load_balancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
log "github.com/sirupsen/logrus"

Expand All @@ -16,10 +17,22 @@ import (
func LoadBalancers(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)

retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

loadBalancerClient, err := armnetwork.NewLoadBalancersClient(
client.AzureClient.SubscriptionId,
client.AzureClient.Credentials,
&arm.ClientOptions{},
clientOptions,
)
if err != nil {
return resources, err
Expand Down
18 changes: 16 additions & 2 deletions providers/azure/networking/local_network_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package networking
import (
"context"
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
log "github.com/sirupsen/logrus"
"github.com/tailwarden/komiser/providers/azure/resourcegroup"
"time"

"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
Expand All @@ -24,10 +26,22 @@ func LocalNetworkGateways(ctx context.Context, client providers.ProviderClient)
return resources, nil
}

retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

localNetworkGatewayClient, err := armnetwork.NewLocalNetworkGatewaysClient(
client.AzureClient.SubscriptionId,
client.AzureClient.Credentials,
&arm.ClientOptions{},
clientOptions,
)
if err != nil {
return resources, err
Expand Down
18 changes: 16 additions & 2 deletions providers/azure/resourcegroup/resource_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,35 @@ package resourcegroup
import (
"context"
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
log "github.com/sirupsen/logrus"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
"time"
)

func ResourceGroups(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)

retryOptions := policy.RetryOptions{
MaxRetries: 6,
RetryDelay: 2 * time.Second,
MaxRetryDelay: 120 * time.Second,
}

clientOptions := &arm.ClientOptions{
ClientOptions: policy.ClientOptions{
Retry: retryOptions,
},
}

resourceGroupClient, err := armresources.NewResourceGroupsClient(
client.AzureClient.SubscriptionId,
client.AzureClient.Credentials,
&arm.ClientOptions{},
clientOptions,
)

if err != nil {
Expand Down
Loading