Skip to content

Commit

Permalink
Adds ECS Cluster Region option
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Galindro da Costa committed Sep 18, 2017
1 parent b0cd180 commit cd21baf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
13 changes: 8 additions & 5 deletions probe/awsecs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 4 additions & 2 deletions probe/awsecs/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions prog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion prog/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cd21baf

Please sign in to comment.