Skip to content

Commit d2c4983

Browse files
wparr-circlelu-zhengdawdhif
authored
feat(autodiscovery): support extra_dbname when templating a database instance (#31138)
Co-authored-by: lu-zhengda <[email protected]> Co-authored-by: wdhif <[email protected]>
1 parent 8fc171e commit d2c4983

File tree

5 files changed

+78
-1
lines changed

5 files changed

+78
-1
lines changed

comp/core/autodiscovery/listeners/dbm_aurora.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ func (d *DBMAuroraService) GetExtraConfig(key string) (string, error) {
277277
return strconv.FormatBool(d.instance.IamEnabled), nil
278278
case "dbclusteridentifier":
279279
return d.clusterID, nil
280+
case "dbname":
281+
return d.instance.DbName, nil
280282
}
283+
281284
return "", ErrNotSupported
282285
}
283286

comp/core/autodiscovery/listeners/dbm_aurora_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,44 @@ func TestDBMAuroraListener(t *testing.T) {
279279
}
280280
}
281281

282+
func TestGetExtraConfig(t *testing.T) {
283+
testCases := []struct {
284+
service *DBMAuroraService
285+
expectedExtra map[string]string
286+
}{
287+
{
288+
service: &DBMAuroraService{
289+
adIdentifier: dbmPostgresADIdentifier,
290+
entityID: "f7fee36c58e3da8a",
291+
checkName: "postgres",
292+
clusterID: "my-cluster-1",
293+
region: "us-east-1",
294+
instance: &aws.Instance{
295+
Endpoint: "my-endpoint",
296+
Port: 5432,
297+
IamEnabled: true,
298+
Engine: "aurora-postgresql",
299+
DbName: "app",
300+
},
301+
},
302+
expectedExtra: map[string]string{
303+
"dbname": "app",
304+
"region": "us-east-1",
305+
"managed_authentication_enabled": "true",
306+
"dbclusteridentifier": "my-cluster-1",
307+
},
308+
},
309+
}
310+
311+
for _, tc := range testCases {
312+
for key, value := range tc.expectedExtra {
313+
v, err := tc.service.GetExtraConfig(key)
314+
assert.NoError(t, err)
315+
assert.Equal(t, value, v)
316+
}
317+
}
318+
}
319+
282320
func contextWithTimeout(t time.Duration) gomock.Matcher {
283321
return contextWithTimeoutMatcher{
284322
timeout: t,

pkg/databasemonitoring/aws/aurora.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Instance struct {
3232
Port int32
3333
IamEnabled bool
3434
Engine string
35+
DbName string
3536
}
3637

3738
const (
@@ -46,7 +47,6 @@ func (c *Client) GetAuroraClusterEndpoints(ctx context.Context, dbClusterIdentif
4647
return nil, fmt.Errorf("at least one database cluster identifier is required")
4748
}
4849
clusters := make(map[string]*AuroraCluster, 0)
49-
5050
for _, clusterID := range dbClusterIdentifiers {
5151
// 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
5252
// We should add pagination support to this method at some point
@@ -82,6 +82,9 @@ func (c *Client) GetAuroraClusterEndpoints(ctx context.Context, dbClusterIdentif
8282
if db.Engine != nil {
8383
instance.Engine = *db.Engine
8484
}
85+
if db.DBName != nil {
86+
instance.DbName = *db.DBName
87+
}
8588
if _, ok := clusters[*db.DBClusterIdentifier]; !ok {
8689
clusters[*db.DBClusterIdentifier] = &AuroraCluster{
8790
Instances: make([]*Instance, 0),

pkg/databasemonitoring/aws/aurora_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
6868
AvailabilityZone: aws.String("us-east-1a"),
6969
DBInstanceStatus: aws.String("available"),
7070
Engine: aws.String("aurora-postgresql"),
71+
DBName: aws.String("postgres"),
7172
},
7273
},
7374
}, nil).Times(1)
@@ -81,6 +82,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
8182
Port: 5432,
8283
IamEnabled: true,
8384
Engine: "aurora-postgresql",
85+
DbName: "postgres",
8486
},
8587
},
8688
},
@@ -101,6 +103,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
101103
AvailabilityZone: aws.String("us-east-1a"),
102104
DBInstanceStatus: aws.String("available"),
103105
Engine: aws.String("aurora-postgresql"),
106+
DBName: aws.String("postgres"),
104107
},
105108
{
106109
Endpoint: &types.Endpoint{
@@ -112,6 +115,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
112115
AvailabilityZone: aws.String("us-east-1a"),
113116
DBInstanceStatus: aws.String("available"),
114117
Engine: aws.String("aurora-postgresql"),
118+
DBName: aws.String("postgres"),
115119
},
116120
{
117121
Endpoint: &types.Endpoint{
@@ -123,6 +127,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
123127
AvailabilityZone: aws.String("us-east-1a"),
124128
DBInstanceStatus: aws.String("available"),
125129
Engine: aws.String("aurora-postgresql"),
130+
DBName: aws.String("postgres"),
126131
},
127132
},
128133
}, nil).Times(1)
@@ -136,18 +141,21 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
136141
Port: 5432,
137142
IamEnabled: true,
138143
Engine: "aurora-postgresql",
144+
DbName: "postgres",
139145
},
140146
{
141147
Endpoint: "test-endpoint-2",
142148
Port: 5432,
143149
IamEnabled: false,
144150
Engine: "aurora-postgresql",
151+
DbName: "postgres",
145152
},
146153
{
147154
Endpoint: "test-endpoint-3",
148155
Port: 5444,
149156
IamEnabled: false,
150157
Engine: "aurora-postgresql",
158+
DbName: "postgres",
151159
},
152160
},
153161
},
@@ -168,6 +176,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
168176
AvailabilityZone: aws.String("us-east-1a"),
169177
DBInstanceStatus: aws.String("available"),
170178
Engine: aws.String("aurora-postgresql"),
179+
DBName: aws.String("postgres"),
171180
},
172181
{
173182
Endpoint: &types.Endpoint{
@@ -179,6 +188,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
179188
AvailabilityZone: aws.String("us-east-1a"),
180189
DBInstanceStatus: aws.String("terminating"),
181190
Engine: aws.String("aurora-postgresql"),
191+
DBName: aws.String("postgres"),
182192
},
183193
{
184194
Endpoint: &types.Endpoint{
@@ -190,6 +200,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
190200
AvailabilityZone: aws.String("us-east-1a"),
191201
DBInstanceStatus: aws.String("terminating"),
192202
Engine: aws.String("aurora-postgresql"),
203+
DBName: aws.String("postgres"),
193204
},
194205
},
195206
}, nil).Times(1)
@@ -203,6 +214,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
203214
Port: 5432,
204215
IamEnabled: true,
205216
Engine: "aurora-postgresql",
217+
DbName: "postgres",
206218
},
207219
},
208220
},
@@ -223,6 +235,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
223235
AvailabilityZone: aws.String("us-east-1a"),
224236
DBInstanceStatus: aws.String("available"),
225237
Engine: aws.String("aurora-postgresql"),
238+
DBName: aws.String("postgres"),
226239
},
227240
},
228241
}, nil).Times(1)
@@ -239,6 +252,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
239252
Port: 5432,
240253
IamEnabled: true,
241254
Engine: "aurora-postgresql",
255+
DbName: "postgres",
242256
},
243257
},
244258
},
@@ -259,6 +273,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
259273
AvailabilityZone: aws.String("us-east-1a"),
260274
DBInstanceStatus: aws.String("available"),
261275
Engine: aws.String("aurora-postgresql"),
276+
DBName: aws.String("postgres"),
262277
},
263278
{
264279
Endpoint: &types.Endpoint{
@@ -270,6 +285,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
270285
AvailabilityZone: aws.String("us-east-1a"),
271286
DBInstanceStatus: aws.String("available"),
272287
Engine: aws.String("aurora-postgresql"),
288+
DBName: aws.String("postgres"),
273289
},
274290
},
275291
}, nil).Times(1)
@@ -286,6 +302,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
286302
AvailabilityZone: aws.String("us-east-1c"),
287303
DBInstanceStatus: aws.String("available"),
288304
Engine: aws.String("aurora-postgresql"),
305+
DBName: aws.String("postgres"),
289306
},
290307
},
291308
}, nil).Times(1)
@@ -299,12 +316,14 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
299316
Port: 5432,
300317
IamEnabled: true,
301318
Engine: "aurora-postgresql",
319+
DbName: "postgres",
302320
},
303321
{
304322
Endpoint: "test-endpoint-2",
305323
Port: 5432,
306324
IamEnabled: false,
307325
Engine: "aurora-postgresql",
326+
DbName: "postgres",
308327
},
309328
},
310329
},
@@ -315,6 +334,7 @@ func TestGetAuroraClusterEndpoints(t *testing.T) {
315334
Port: 5444,
316335
IamEnabled: true,
317336
Engine: "aurora-postgresql",
337+
DbName: "postgres",
318338
},
319339
},
320340
},
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Each section from every release note are combined when the
2+
# CHANGELOG.rst is rendered. So the text needs to be worded so that
3+
# it does not depend on any information only available in another
4+
# section. This may mean repeating some details, but each section
5+
# must be readable independently of the other.
6+
#
7+
# Each section note must be formatted as reStructuredText.
8+
---
9+
enhancements:
10+
- |
11+
Extends extra configuration available for templating from Aurora Database Discovery
12+
to include %%extra_dbname%% allowing instances which are configured with non-standard
13+
DBName field to be discovered successfully

0 commit comments

Comments
 (0)