Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
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: 4 additions & 0 deletions cmd/pmm-managed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ var (
agentRDSExporterConfigF = flag.String("agent-rds-exporter-config", "/etc/percona-rds-exporter.yml", "rds_exporter configuration file path")
agentQANBaseF = flag.String("agent-qan-base", "/usr/local/percona/qan-agent", "qan-agent installation base path")

rdsEnableGovCloud = flag.Bool("rds-enable-gov-cloud", false, "Enable GOV cloud for RDS")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a downside of always trying govcloud?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the default value to true, but keep the flag for now. It will make testing this feature by the customer easier, but allow us to change it later. I will ask @michaelcoburn what to do there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, request returns 403 error.
InvalidClientTokenId: The security token included in the request is invalid.\n\tstatus code: 403

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prepared feature build for customer to test it. Percona-Lab/pmm-submodules#148


debugF = flag.Bool("debug", false, "Enable debug logging")
)

Expand Down Expand Up @@ -173,6 +175,8 @@ func makeRDSService(ctx context.Context, deps *serviceDependencies) (*rds.Servic
DB: deps.db,
PortsRegistry: deps.portsRegistry,
QAN: deps.qan,

RDSEnableGovCloud: *rdsEnableGovCloud,
}
rdsService, err := rds.NewService(&rdsConfig)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion services/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestAddListRemove(t *testing.T) {
Address: pointer.ToString("localhost"),
Port: pointer.ToUint16(3306),
Engine: pointer.ToString("Percona Server"),
EngineVersion: pointer.ToString("5.7.23"),
EngineVersion: pointer.ToString("5.7.24"),
},
}}
assert.Equal(t, expected, actual)
Expand Down
132 changes: 70 additions & 62 deletions services/rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type ServiceConfig struct {
DB *reform.DB
PortsRegistry *ports.Registry
QAN *qan.Service

RDSEnableGovCloud bool
}

// Service is responsible for interactions with AWS RDS.
Expand Down Expand Up @@ -260,74 +262,80 @@ func (svc *Service) Discover(ctx context.Context, accessKey, secretKey string) (
var g errgroup.Group
instances := make(chan Instance)

for _, r := range endpoints.AwsPartition().Services()[endpoints.RdsServiceID].Regions() {
region := r.ID()
g.Go(func() error {
// use given credentials, or default credential chain
var creds *credentials.Credentials
if accessKey != "" || secretKey != "" {
creds = credentials.NewCredentials(&credentials.StaticProvider{
Value: credentials.Value{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
},
})
}
config := &aws.Config{
CredentialsChainVerboseErrors: aws.Bool(true),
Credentials: creds,
Region: aws.String(region),
HTTPClient: svc.httpClient,
Logger: aws.LoggerFunc(l.Debug),
}
if l.Level >= logrus.DebugLevel {
config.LogLevel = aws.LogLevel(aws.LogDebug)
}
s, err := session.NewSession(config)
if err != nil {
return errors.WithStack(err)
}
partitions := []endpoints.Partition{endpoints.AwsPartition()}
if svc.RDSEnableGovCloud {
partitions = append(partitions, endpoints.AwsUsGovPartition())
}
for _, p := range partitions {
for _, r := range p.Services()[endpoints.RdsServiceID].Regions() {
region := r.ID()
g.Go(func() error {
// use given credentials, or default credential chain
var creds *credentials.Credentials
if accessKey != "" || secretKey != "" {
creds = credentials.NewCredentials(&credentials.StaticProvider{
Value: credentials.Value{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
},
})
}
config := &aws.Config{
CredentialsChainVerboseErrors: aws.Bool(true),
Credentials: creds,
Region: aws.String(region),
HTTPClient: svc.httpClient,
Logger: aws.LoggerFunc(l.Debug),
}
if l.Level >= logrus.DebugLevel {
config.LogLevel = aws.LogLevel(aws.LogDebug)
}
s, err := session.NewSession(config)
if err != nil {
return errors.WithStack(err)
}

out, err := rds.New(s).DescribeDBInstancesWithContext(ctx, new(rds.DescribeDBInstancesInput))
if err != nil {
l.Error(err)
out, err := rds.New(s).DescribeDBInstancesWithContext(ctx, new(rds.DescribeDBInstancesInput))
if err != nil {
l.Error(err)

if err, ok := err.(awserr.Error); ok {
if err.OrigErr() != nil && err.OrigErr() == ctx.Err() {
// ignore timeout, let other goroutines return partial data
return nil
}
switch err.Code() {
case "InvalidClientTokenId", "EmptyStaticCreds":
return status.Error(codes.InvalidArgument, err.Message())
default:
return err
if err, ok := err.(awserr.Error); ok {
if err.OrigErr() != nil && err.OrigErr() == ctx.Err() {
// ignore timeout, let other goroutines return partial data
return nil
}
switch err.Code() {
case "InvalidClientTokenId", "EmptyStaticCreds":
return status.Error(codes.InvalidArgument, err.Message())
default:
return err
}
}
return errors.WithStack(err)
}
return errors.WithStack(err)
}

l.Debugf("Got %d instances from %s.", len(out.DBInstances), region)
for _, db := range out.DBInstances {
instances <- Instance{
Node: models.RDSNode{
Type: models.RDSNodeType,
Name: *db.DBInstanceIdentifier,

Region: region,
},
Service: models.RDSService{
Type: models.RDSServiceType,

Address: db.Endpoint.Address,
Port: pointer.ToUint16(uint16(*db.Endpoint.Port)),
Engine: db.Engine,
EngineVersion: db.EngineVersion,
},
l.Debugf("Got %d instances from %s.", len(out.DBInstances), region)
for _, db := range out.DBInstances {
instances <- Instance{
Node: models.RDSNode{
Type: models.RDSNodeType,
Name: *db.DBInstanceIdentifier,

Region: region,
},
Service: models.RDSService{
Type: models.RDSServiceType,

Address: db.Endpoint.Address,
Port: pointer.ToUint16(uint16(*db.Endpoint.Port)),
Engine: db.Engine,
EngineVersion: db.EngineVersion,
},
}
}
}
return nil
})
return nil
})
}
}

go func() {
Expand Down