diff --git a/comp/core/autodiscovery/listeners/dbm_aurora.go b/comp/core/autodiscovery/listeners/dbm_aurora.go index bce4704331fa1e..c0b61641c4e612 100644 --- a/comp/core/autodiscovery/listeners/dbm_aurora.go +++ b/comp/core/autodiscovery/listeners/dbm_aurora.go @@ -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 } diff --git a/comp/core/autodiscovery/listeners/dbm_aurora_test.go b/comp/core/autodiscovery/listeners/dbm_aurora_test.go index 1243cd9beceece..33be75f09834c9 100644 --- a/comp/core/autodiscovery/listeners/dbm_aurora_test.go +++ b/comp/core/autodiscovery/listeners/dbm_aurora_test.go @@ -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, diff --git a/pkg/databasemonitoring/aws/aurora.go b/pkg/databasemonitoring/aws/aurora.go index 9d5270b4df9163..5c47ee10595357 100644 --- a/pkg/databasemonitoring/aws/aurora.go +++ b/pkg/databasemonitoring/aws/aurora.go @@ -11,11 +11,12 @@ package aws import ( "context" "fmt" + "hash/fnv" + "strconv" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/rds" "github.com/aws/aws-sdk-go-v2/service/rds/types" - "hash/fnv" - "strconv" "strings" ) @@ -31,6 +32,7 @@ type Instance struct { Port int32 IamEnabled bool Engine string + DbName string } const ( @@ -77,6 +79,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), diff --git a/pkg/databasemonitoring/aws/aurora_test.go b/pkg/databasemonitoring/aws/aurora_test.go index 4cb7fed6c50fc0..7f4595d1737e74 100644 --- a/pkg/databasemonitoring/aws/aurora_test.go +++ b/pkg/databasemonitoring/aws/aurora_test.go @@ -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) @@ -81,6 +82,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) { Port: 5432, IamEnabled: true, Engine: "aurora-postgresql", + DbName: "postgres", }, }, }, @@ -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{ @@ -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{ @@ -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) @@ -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", }, }, }, @@ -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{ @@ -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{ @@ -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) @@ -203,6 +214,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) { Port: 5432, IamEnabled: true, Engine: "aurora-postgresql", + DbName: "postgres", }, }, }, @@ -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) @@ -236,6 +249,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) { Port: 5432, IamEnabled: true, Engine: "aurora-postgresql", + DbName: "postgres", }, }, }, @@ -256,6 +270,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{ @@ -267,6 +282,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{ @@ -278,6 +294,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) @@ -291,12 +308,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", }, }, }, @@ -307,6 +326,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) { Port: 5444, IamEnabled: true, Engine: "aurora-postgresql", + DbName: "postgres", }, }, }, diff --git a/pkg/databasemonitoring/aws/client.go b/pkg/databasemonitoring/aws/client.go index 7248c31e81d2b8..f1107562107d89 100644 --- a/pkg/databasemonitoring/aws/client.go +++ b/pkg/databasemonitoring/aws/client.go @@ -9,10 +9,11 @@ package aws import ( "context" + "time" + "github.com/DataDog/datadog-agent/pkg/util/ec2" awsconfig "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/rds" - "time" ) //go:generate mockgen -source=$GOFILE -package=$GOPACKAGE -destination=rdsclient_mockgen.go