Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ECS Cluster Region option #2854

Merged
merged 1 commit into from Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions probe/awsecs/client.go
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
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
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
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