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

feat(autodiscovery): support extra_dbname when templating a database instance #31138

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions comp/core/autodiscovery/listeners/dbm_aurora.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ func (d *DBMAuroraService) GetExtraConfig(key string) (string, error) {
return strconv.FormatBool(d.instance.IamEnabled), nil
case "dbclusteridentifier":
return d.clusterID, nil
case "dbname":
return d.instance.DbName, nil
}

return "", ErrNotSupported
}

Expand Down
38 changes: 38 additions & 0 deletions comp/core/autodiscovery/listeners/dbm_aurora_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,44 @@ func TestDBMAuroraListener(t *testing.T) {
}
}

func TestGetExtraConfig(t *testing.T) {
testCases := []struct {
service *DBMAuroraService
expectedExtra map[string]string
}{
{
service: &DBMAuroraService{
adIdentifier: dbmPostgresADIdentifier,
entityID: "f7fee36c58e3da8a",
checkName: "postgres",
clusterID: "my-cluster-1",
region: "us-east-1",
instance: &aws.Instance{
Endpoint: "my-endpoint",
Port: 5432,
IamEnabled: true,
Engine: "aurora-postgresql",
DbName: "app",
},
},
expectedExtra: map[string]string{
"dbname": "app",
"region": "us-east-1",
"managed_authentication_enabled": "true",
"dbclusteridentifier": "my-cluster-1",
},
},
}

for _, tc := range testCases {
for key, value := range tc.expectedExtra {
v, err := tc.service.GetExtraConfig(key)
assert.NoError(t, err)
assert.Equal(t, value, v)
}
}
}

func contextWithTimeout(t time.Duration) gomock.Matcher {
return contextWithTimeoutMatcher{
timeout: t,
Expand Down
5 changes: 4 additions & 1 deletion pkg/databasemonitoring/aws/aurora.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Instance struct {
Port int32
IamEnabled bool
Engine string
DbName string
}

const (
Expand All @@ -46,7 +47,6 @@ func (c *Client) GetAuroraClusterEndpoints(ctx context.Context, dbClusterIdentif
return nil, fmt.Errorf("at least one database cluster identifier is required")
}
clusters := make(map[string]*AuroraCluster, 0)

for _, clusterID := range dbClusterIdentifiers {
// TODO: Seth Samuel: This method is not paginated, so if there are more than 100 instances in a cluster, we will only get the first 100
// We should add pagination support to this method at some point
Expand Down Expand Up @@ -82,6 +82,9 @@ func (c *Client) GetAuroraClusterEndpoints(ctx context.Context, dbClusterIdentif
if db.Engine != nil {
instance.Engine = *db.Engine
}
if db.DBName != nil {
instance.DbName = *db.DBName
}
if _, ok := clusters[*db.DBClusterIdentifier]; !ok {
clusters[*db.DBClusterIdentifier] = &AuroraCluster{
Instances: make([]*Instance, 0),
Expand Down
20 changes: 20 additions & 0 deletions pkg/databasemonitoring/aws/aurora_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("available"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
},
}, nil).Times(1)
Expand All @@ -81,6 +82,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
Port: 5432,
IamEnabled: true,
Engine: "aurora-postgresql",
DbName: "postgres",
},
},
},
Expand All @@ -101,6 +103,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("available"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
{
Endpoint: &types.Endpoint{
Expand All @@ -112,6 +115,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("available"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
{
Endpoint: &types.Endpoint{
Expand All @@ -123,6 +127,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("available"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
},
}, nil).Times(1)
Expand All @@ -136,18 +141,21 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
Port: 5432,
IamEnabled: true,
Engine: "aurora-postgresql",
DbName: "postgres",
},
{
Endpoint: "test-endpoint-2",
Port: 5432,
IamEnabled: false,
Engine: "aurora-postgresql",
DbName: "postgres",
},
{
Endpoint: "test-endpoint-3",
Port: 5444,
IamEnabled: false,
Engine: "aurora-postgresql",
DbName: "postgres",
},
},
},
Expand All @@ -168,6 +176,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("available"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
{
Endpoint: &types.Endpoint{
Expand All @@ -179,6 +188,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("terminating"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
{
Endpoint: &types.Endpoint{
Expand All @@ -190,6 +200,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("terminating"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
},
}, nil).Times(1)
Expand All @@ -203,6 +214,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
Port: 5432,
IamEnabled: true,
Engine: "aurora-postgresql",
DbName: "postgres",
},
},
},
Expand All @@ -223,6 +235,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("available"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
},
}, nil).Times(1)
Expand All @@ -239,6 +252,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
Port: 5432,
IamEnabled: true,
Engine: "aurora-postgresql",
DbName: "postgres",
},
},
},
Expand All @@ -259,6 +273,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("available"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
{
Endpoint: &types.Endpoint{
Expand All @@ -270,6 +285,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1a"),
DBInstanceStatus: aws.String("available"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
},
}, nil).Times(1)
Expand All @@ -286,6 +302,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
AvailabilityZone: aws.String("us-east-1c"),
DBInstanceStatus: aws.String("available"),
Engine: aws.String("aurora-postgresql"),
DBName: aws.String("postgres"),
},
},
}, nil).Times(1)
Expand All @@ -299,12 +316,14 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
Port: 5432,
IamEnabled: true,
Engine: "aurora-postgresql",
DbName: "postgres",
},
{
Endpoint: "test-endpoint-2",
Port: 5432,
IamEnabled: false,
Engine: "aurora-postgresql",
DbName: "postgres",
},
},
},
Expand All @@ -315,6 +334,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
Port: 5444,
IamEnabled: true,
Engine: "aurora-postgresql",
DbName: "postgres",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Each section from every release note are combined when the
# CHANGELOG.rst is rendered. So the text needs to be worded so that
# it does not depend on any information only available in another
# section. This may mean repeating some details, but each section
# must be readable independently of the other.
#
# Each section note must be formatted as reStructuredText.
---
enhancements:
- |
Extends extra configuration available for templating from Aurora Database Discovery
to include %%extra_dbname%% allowing instances which are configured with non-standard
DBName field to be discovered successfully
Loading