Skip to content

Commit

Permalink
add ElastiCache engine label
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinFrazar committed Jan 17, 2025
1 parent 38cb3e1 commit af46ab3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/cloud/mocks/aws_elasticache.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (m *ElastiCacheClient) ModifyUser(_ context.Context, input *elasticache.Mod
func ElastiCacheCluster(name, region string, opts ...func(*ectypes.ReplicationGroup)) *ectypes.ReplicationGroup {
cluster := &ectypes.ReplicationGroup{
ARN: aws.String(fmt.Sprintf("arn:aws:elasticache:%s:123456789012:replicationgroup:%s", region, name)),
Engine: aws.String("redis"),
ReplicationGroupId: aws.String(name),
Status: aws.String("available"),
TransitEncryptionEnabled: aws.Bool(true),
Expand Down
1 change: 1 addition & 0 deletions lib/srv/discovery/common/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@ func ExtraElastiCacheLabels(cluster *ectypes.ReplicationGroup, tags []ectypes.Ta
}
}

labels[types.DiscoveryLabelEngine] = aws.ToString(cluster.Engine)
// Add AWS resource tags.
return addLabels(labels, libcloudaws.TagsToLabels(tags))
}
Expand Down
9 changes: 7 additions & 2 deletions lib/srv/discovery/common/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,7 @@ func TestDatabaseFromMemoryDBClusterNameOverride(t *testing.T) {
func TestExtraElastiCacheLabels(t *testing.T) {
cluster := &ectypes.ReplicationGroup{
ReplicationGroupId: aws.String("my-redis"),
Engine: aws.String("redis"),
}
tags := []ectypes.Tag{
{Key: aws.String("key1"), Value: aws.String("value1")},
Expand Down Expand Up @@ -1831,6 +1832,7 @@ func TestExtraElastiCacheLabels(t *testing.T) {
expectLabels: map[string]string{
"key1": "value1",
"key2": "value2",
"engine": "redis",
"engine-version": "6.6.6",
"vpc-id": "my-vpc",
},
Expand All @@ -1841,6 +1843,7 @@ func TestExtraElastiCacheLabels(t *testing.T) {
inputNodes: nodes,
inputSubnetGroups: subnetGroups,
expectLabels: map[string]string{
"engine": "redis",
"engine-version": "6.6.6",
"vpc-id": "my-vpc",
},
Expand All @@ -1853,8 +1856,9 @@ func TestExtraElastiCacheLabels(t *testing.T) {

// Without subnet group name from nodes, VPC ID cannot be found.
expectLabels: map[string]string{
"key1": "value1",
"key2": "value2",
"key1": "value1",
"key2": "value2",
"engine": "redis",
},
},
{
Expand All @@ -1865,6 +1869,7 @@ func TestExtraElastiCacheLabels(t *testing.T) {
expectLabels: map[string]string{
"key1": "value1",
"key2": "value2",
"engine": "redis",
"engine-version": "6.6.6",
},
},
Expand Down
8 changes: 7 additions & 1 deletion lib/srv/discovery/fetchers/db/aws_elasticache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestElastiCacheFetcher(t *testing.T) {
t.Parallel()

elasticacheProd, elasticacheDatabasesProd, elasticacheProdTags := makeElastiCacheCluster(t, "ec1", "us-east-1", "prod", mocks.WithElastiCacheReaderEndpoint)
elasticacheQA, elasticacheDatabasesQA, elasticacheQATags := makeElastiCacheCluster(t, "ec2", "us-east-1", "qa", mocks.WithElastiCacheConfigurationEndpoint)
elasticacheQA, elasticacheDatabasesQA, elasticacheQATags := makeElastiCacheCluster(t, "ec2", "us-east-1", "qa", mocks.WithElastiCacheConfigurationEndpoint, withElastiCacheEngine("valkey"))
elasticacheUnavailable, _, elasticacheUnavailableTags := makeElastiCacheCluster(t, "ec4", "us-east-1", "prod", func(cluster *ectypes.ReplicationGroup) {
cluster.Status = aws.String("deleting")
})
Expand Down Expand Up @@ -127,3 +127,9 @@ func makeElastiCacheCluster(t *testing.T, name, region, env string, opts ...func
}
return cluster, databases, tags
}

func withElastiCacheEngine(engine string) func(*ectypes.ReplicationGroup) {
return func(rg *ectypes.ReplicationGroup) {
rg.Engine = &engine
}
}

0 comments on commit af46ab3

Please sign in to comment.