Merge pull request #2854 from galindro/ecs-region

Adds ECS Cluster Region option
This commit is contained in:
Mike Lang
2017-09-18 16:46:32 -07:00
committed by GitHub
4 changed files with 18 additions and 11 deletions

View File

@@ -70,16 +70,19 @@ type EcsInfo struct {
TaskServiceMap map[string]string
}
func newClient(cluster string, cacheSize int, cacheExpiry time.Duration) (EcsClient, error) {
func newClient(cluster string, cacheSize int, cacheExpiry time.Duration, clusterRegion string) (EcsClient, error) {
sess := session.New()
var err error
region, err := ec2metadata.New(sess).Region()
if err != nil {
return nil, err
if clusterRegion == "" {
clusterRegion, err = ec2metadata.New(sess).Region()
if err != nil {
return nil, err
}
}
return &ecsClientImpl{
client: ecs.New(sess, &aws.Config{Region: aws.String(region)}),
client: ecs.New(sess, &aws.Config{Region: aws.String(clusterRegion)}),
cluster: cluster,
taskCache: gcache.New(cacheSize).LRU().Expiration(cacheExpiry).Build(),
serviceCache: gcache.New(cacheSize).LRU().Expiration(cacheExpiry).Build(),

View File

@@ -87,16 +87,18 @@ type Reporter struct {
ClientsByCluster map[string]EcsClient // Exported for test
cacheSize int
cacheExpiry time.Duration
clusterRegion string
handlerRegistry *controls.HandlerRegistry
probeID string
}
// Make creates a new Reporter
func Make(cacheSize int, cacheExpiry time.Duration, handlerRegistry *controls.HandlerRegistry, probeID string) Reporter {
func Make(cacheSize int, cacheExpiry time.Duration, clusterRegion string, handlerRegistry *controls.HandlerRegistry, probeID string) Reporter {
r := Reporter{
ClientsByCluster: map[string]EcsClient{},
cacheSize: cacheSize,
cacheExpiry: cacheExpiry,
clusterRegion: clusterRegion,
handlerRegistry: handlerRegistry,
probeID: probeID,
}
@@ -114,7 +116,7 @@ func (r Reporter) getClient(cluster string) (EcsClient, error) {
if !ok {
log.Debugf("Creating new ECS client")
var err error
client, err = newClient(cluster, r.cacheSize, r.cacheExpiry)
client, err = newClient(cluster, r.cacheSize, r.cacheExpiry, r.clusterRegion)
if err != nil {
return nil, err
}

View File

@@ -124,9 +124,10 @@ type probeFlags struct {
kubernetesClientConfig kubernetes.ClientConfig
kubernetesKubeletPort uint
ecsEnabled bool
ecsCacheSize int
ecsCacheExpiry time.Duration
ecsEnabled bool
ecsCacheSize int
ecsCacheExpiry time.Duration
ecsClusterRegion string
weaveEnabled bool
weaveAddr string
@@ -323,6 +324,7 @@ func setupFlags(flags *flags) {
flag.BoolVar(&flags.probe.ecsEnabled, "probe.ecs", false, "Collect ecs-related attributes for containers on this node")
flag.IntVar(&flags.probe.ecsCacheSize, "probe.ecs.cache.size", 1024*1024, "Max size of cached info for each ECS cluster")
flag.DurationVar(&flags.probe.ecsCacheExpiry, "probe.ecs.cache.expiry", time.Hour, "How long to keep cached ECS info")
flag.StringVar(&flags.probe.ecsClusterRegion, "probe.ecs.cluster.region", "", "ECS Cluster Region")
// Weave
flag.StringVar(&flags.probe.weaveAddr, "probe.weave.addr", "127.0.0.1:6784", "IP address & port of the Weave router")

View File

@@ -226,7 +226,7 @@ func probeMain(flags probeFlags, targets []appclient.Target) {
}
if flags.ecsEnabled {
reporter := awsecs.Make(flags.ecsCacheSize, flags.ecsCacheExpiry, handlerRegistry, probeID)
reporter := awsecs.Make(flags.ecsCacheSize, flags.ecsCacheExpiry, flags.ecsClusterRegion, handlerRegistry, probeID)
defer reporter.Stop()
p.AddReporter(reporter)
p.AddTagger(reporter)