Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
janboll committed Sep 23, 2022
1 parent d1c5bdb commit 0ed9bda
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 56 deletions.
6 changes: 3 additions & 3 deletions aws-resource-exporter-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ rds:
regions:
- "us-east-1"
vpc:
enabled: true
enabled: false
regions:
- "us-east-1"
- "eu-central-1"
- "eu-west-1"
route53:
enabled: true
enabled: false
region: "us-east-1"
ec2:
enabled: true
enabled: false
regions:
- "us-east-1"
- "eu-central-1"
Expand Down
Binary file added aws-resource-exporter-main
Binary file not shown.
20 changes: 20 additions & 0 deletions pkg/awsclient/awsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package awsclient

import (
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/aws/aws-sdk-go/service/servicequotas"
"github.com/aws/aws-sdk-go/service/servicequotas/servicequotasiface"

Expand All @@ -20,19 +21,37 @@ type Client interface {
//EC2
DescribeTransitGatewaysWithContext(ctx aws.Context, input *ec2.DescribeTransitGatewaysInput, opts ...request.Option) (*ec2.DescribeTransitGatewaysOutput, error)

//RDS
DescribeDBInstancesPagesWithContext(ctx aws.Context, input *rds.DescribeDBInstancesInput, fn func(*rds.DescribeDBInstancesOutput, bool) bool, opts ...request.Option) error
DescribeDBLogFilesPagesWithContext(ctx aws.Context, input *rds.DescribeDBLogFilesInput, fn func(*rds.DescribeDBLogFilesOutput, bool) bool, opts ...request.Option) error
DescribePendingMaintenanceActionsPagesWithContext(ctx aws.Context, input *rds.DescribePendingMaintenanceActionsInput, fn func(*rds.DescribePendingMaintenanceActionsOutput, bool) bool, opts ...request.Option) error

// Service Quota
GetServiceQuotaWithContext(ctx aws.Context, input *servicequotas.GetServiceQuotaInput, opts ...request.Option) (*servicequotas.GetServiceQuotaOutput, error)
}

type awsClient struct {
ec2Client ec2iface.EC2API
rdsClient rds.RDS
serviceQuotasClient servicequotasiface.ServiceQuotasAPI
}

func (c *awsClient) DescribeTransitGatewaysWithContext(ctx aws.Context, input *ec2.DescribeTransitGatewaysInput, opts ...request.Option) (*ec2.DescribeTransitGatewaysOutput, error) {
return c.ec2Client.DescribeTransitGatewaysWithContext(ctx, input, opts...)
}

func (c *awsClient) DescribeDBLogFilesPagesWithContext(ctx aws.Context, input *rds.DescribeDBLogFilesInput, fn func(*rds.DescribeDBLogFilesOutput, bool) bool, opts ...request.Option) error {
return c.rdsClient.DescribeDBLogFilesPagesWithContext(ctx, input, fn, opts...)
}

func (c *awsClient) DescribeDBInstancesPagesWithContext(ctx aws.Context, input *rds.DescribeDBInstancesInput, fn func(*rds.DescribeDBInstancesOutput, bool) bool, opts ...request.Option) error {
return c.rdsClient.DescribeDBInstancesPagesWithContext(ctx, input, fn, opts...)
}

func (c *awsClient) DescribePendingMaintenanceActionsPagesWithContext(ctx aws.Context, input *rds.DescribePendingMaintenanceActionsInput, fn func(*rds.DescribePendingMaintenanceActionsOutput, bool) bool, opts ...request.Option) error {
return c.rdsClient.DescribePendingMaintenanceActionsPagesWithContext(ctx, input, fn, opts...)
}

func (c *awsClient) GetServiceQuotaWithContext(ctx aws.Context, input *servicequotas.GetServiceQuotaInput, opts ...request.Option) (*servicequotas.GetServiceQuotaOutput, error) {
return c.serviceQuotasClient.GetServiceQuotaWithContext(ctx, input, opts...)
}
Expand All @@ -41,5 +60,6 @@ func NewClientFromSession(sess *session.Session) Client {
return &awsClient{
ec2Client: ec2.New(sess),
serviceQuotasClient: servicequotas.New(sess),
rdsClient: *rds.New(sess),
}
}
58 changes: 58 additions & 0 deletions pkg/awsclient/mock/zz_generated.mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type BaseConfig struct {
Enabled bool `yaml:"enabled"`
Interval *time.Duration `yaml:"interval"`
Timeout *time.Duration `yaml:"timeout"`
CacheTTL *time.Duration `yaml:"cache_ttl"`
}

Expand All @@ -23,20 +24,17 @@ type RDSConfig struct {

type VPCConfig struct {
BaseConfig `yaml:"base,inline"`
Timeout *time.Duration `yaml:"timeout"`
Regions []string `yaml:"regions"`
Regions []string `yaml:"regions"`
}

type Route53Config struct {
BaseConfig `yaml:"base,inline"`
Timeout *time.Duration `yaml:"timeout"`
Region string `yaml:"region"` // Use only a single Region for now, as the current metric is global
Region string `yaml:"region"` // Use only a single Region for now, as the current metric is global
}

type EC2Config struct {
BaseConfig `yaml:"base,inline"`
Timeout *time.Duration `yaml:"timeout"`
Regions []string `yaml:"regions"`
Regions []string `yaml:"regions"`
}

type Config struct {
Expand Down Expand Up @@ -81,6 +79,9 @@ func LoadExporterConfiguration(logger log.Logger, configFile string) (*Config, e
config.EC2Config.Interval = durationPtr(15 * time.Second)
}

if config.RdsConfig.Timeout == nil {
config.RdsConfig.Timeout = durationPtr(10 * time.Second)
}
if config.VpcConfig.Timeout == nil {
config.VpcConfig.Timeout = durationPtr(10 * time.Second)
}
Expand Down
Loading

0 comments on commit 0ed9bda

Please sign in to comment.