Skip to content

Commit

Permalink
fix rds instance url, add elasticache reader endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
greedy52 committed Aug 6, 2023
1 parent b14c519 commit fd1238b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
25 changes: 17 additions & 8 deletions lib/cloud/mocks/aws_elasticache.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,23 @@ func ElastiCacheCluster(name, region string, opts ...func(*elasticache.Replicati
return cluster
}

// WithElastiCacheConfigurationEndpoint returns an option function for
// MakeElastiCacheCluster to set a configuration endpoint.
func WithElastiCacheConfigurationEndpoint() func(*elasticache.ReplicationGroup) {
return func(cluster *elasticache.ReplicationGroup) {
cluster.ClusterEnabled = aws.Bool(true)
cluster.ConfigurationEndpoint = &elasticache.Endpoint{
Address: aws.String(fmt.Sprintf("clustercfg.%v-shards.xxxxxx.use1.cache.amazonaws.com", aws.StringValue(cluster.ReplicationGroupId))),
// WithElastiCacheReaderEndpoint is an option function for
// MakeElastiCacheCluster to set a reader endpoint.
func WithElastiCacheReaderEndpoint(cluster *elasticache.ReplicationGroup) {
cluster.NodeGroups = append(cluster.NodeGroups, &elasticache.NodeGroup{
ReaderEndpoint: &elasticache.Endpoint{
Address: aws.String(fmt.Sprintf("replica.%v-cluster.xxxxxx.use1.cache.amazonaws.com", aws.StringValue(cluster.ReplicationGroupId))),
Port: aws.Int64(6379),
}
},
})
}

// WithElastiCacheConfigurationEndpoint in an option function for
// MakeElastiCacheCluster to set a configuration endpoint.
func WithElastiCacheConfigurationEndpoint(cluster *elasticache.ReplicationGroup) {
cluster.ClusterEnabled = aws.Bool(true)
cluster.ConfigurationEndpoint = &elasticache.Endpoint{
Address: aws.String(fmt.Sprintf("clustercfg.%v-shards.xxxxxx.use1.cache.amazonaws.com", aws.StringValue(cluster.ReplicationGroupId))),
Port: aws.Int64(6379),
}
}
2 changes: 1 addition & 1 deletion lib/cloud/mocks/aws_rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func RDSInstance(name, region string, labels map[string]string, opts ...func(*rd
Engine: aws.String("postgres"),
DBInstanceStatus: aws.String("available"),
Endpoint: &rds.Endpoint{
Address: aws.String("localhost"),
Address: aws.String(fmt.Sprintf("%v.aabbccdd.%v.rds.amazonaws.com", name, region)),
Port: aws.Int64(5432),
},
TagList: libcloudaws.LabelsToTags[rds.Tag](labels),
Expand Down
23 changes: 12 additions & 11 deletions lib/srv/discovery/fetchers/db/aws_elasticache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
func TestElastiCacheFetcher(t *testing.T) {
t.Parallel()

elasticacheProd, elasticacheDatabaseProd, elasticacheProdTags := makeElastiCacheCluster(t, "ec1", "us-east-1", "prod")
elasticacheQA, elasticacheDatabaseQA, elasticacheQATags := makeElastiCacheCluster(t, "ec2", "us-east-1", "qa", mocks.WithElastiCacheConfigurationEndpoint())
elasticacheProd, elasticacheDatabasesProd, elasticacheProdTags := makeElastiCacheCluster(t, "ec1", "us-east-1", "prod", mocks.WithElastiCacheReaderEndpoint)
elasticacheQA, elasticacheDatabasesQA, elasticacheQATags := makeElastiCacheCluster(t, "ec2", "us-east-1", "qa", mocks.WithElastiCacheConfigurationEndpoint)
elasticacheUnavailable, _, elasticacheUnavailableTags := makeElastiCacheCluster(t, "ec4", "us-east-1", "prod", func(cluster *elasticache.ReplicationGroup) {
cluster.Status = aws.String("deleting")
})
Expand All @@ -58,7 +58,7 @@ func TestElastiCacheFetcher(t *testing.T) {
},
},
inputMatchers: makeAWSMatchersForType(services.AWSMatcherElastiCache, "us-east-1", wildcardLabels),
wantDatabases: types.Databases{elasticacheDatabaseProd, elasticacheDatabaseQA},
wantDatabases: append(elasticacheDatabasesProd, elasticacheDatabasesQA...),
},
{
name: "fetch prod",
Expand All @@ -69,7 +69,7 @@ func TestElastiCacheFetcher(t *testing.T) {
},
},
inputMatchers: makeAWSMatchersForType(services.AWSMatcherElastiCache, "us-east-1", envProdLabels),
wantDatabases: types.Databases{elasticacheDatabaseProd},
wantDatabases: elasticacheDatabasesProd,
},
{
name: "skip unavailable",
Expand All @@ -80,7 +80,7 @@ func TestElastiCacheFetcher(t *testing.T) {
},
},
inputMatchers: makeAWSMatchersForType(services.AWSMatcherElastiCache, "us-east-1", wildcardLabels),
wantDatabases: types.Databases{elasticacheDatabaseProd},
wantDatabases: elasticacheDatabasesProd,
},
{
name: "skip unsupported",
Expand All @@ -91,13 +91,13 @@ func TestElastiCacheFetcher(t *testing.T) {
},
},
inputMatchers: makeAWSMatchersForType(services.AWSMatcherElastiCache, "us-east-1", wildcardLabels),
wantDatabases: types.Databases{elasticacheDatabaseProd},
wantDatabases: elasticacheDatabasesProd,
},
}
testAWSFetchers(t, tests...)
}

func makeElastiCacheCluster(t *testing.T, name, region, env string, opts ...func(*elasticache.ReplicationGroup)) (*elasticache.ReplicationGroup, types.Database, []*elasticache.Tag) {
func makeElastiCacheCluster(t *testing.T, name, region, env string, opts ...func(*elasticache.ReplicationGroup)) (*elasticache.ReplicationGroup, types.Databases, []*elasticache.Tag) {
cluster := mocks.ElastiCacheCluster(name, region, opts...)

tags := []*elasticache.Tag{{
Expand All @@ -110,12 +110,13 @@ func makeElastiCacheCluster(t *testing.T, name, region, env string, opts ...func
database, err := services.NewDatabaseFromElastiCacheConfigurationEndpoint(cluster, extraLabels)
require.NoError(t, err)
common.ApplyAWSDatabaseNameSuffix(database, services.AWSMatcherElastiCache)
return cluster, database, tags
return cluster, types.Databases{database}, tags
}

databases, err := services.NewDatabasesFromElastiCacheNodeGroups(cluster, extraLabels)
require.NoError(t, err)
require.Len(t, databases, 1)
common.ApplyAWSDatabaseNameSuffix(databases[0], services.AWSMatcherElastiCache)
return cluster, databases[0], tags
for _, database := range databases {
common.ApplyAWSDatabaseNameSuffix(database, services.AWSMatcherElastiCache)
}
return cluster, databases, tags
}

0 comments on commit fd1238b

Please sign in to comment.