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 bdeaaeb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
15 changes: 9 additions & 6 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()

region, err := ec2metadata.New(sess).Region()
if err != nil {
return nil, err
var err error

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
19 changes: 11 additions & 8 deletions prog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ var (
// set at build time
version = "dev"
// tokens to be elided when logging
serviceTokenFlag = "service-token"
probeTokenFlag = "probe.token"
kubernetesPasswordFlag = "probe.kubernetes.password"
kubernetesTokenFlag = "probe.kubernetes.token"
sensitiveFlags = []string{
serviceTokenFlag = "service-token"
probeEcsClusterRegionFlag = "probe.ecs.cluster.region"
probeTokenFlag = "probe.token"
kubernetesPasswordFlag = "probe.kubernetes.password"
kubernetesTokenFlag = "probe.kubernetes.token"
sensitiveFlags = []string{
serviceTokenFlag,
probeTokenFlag,
kubernetesPasswordFlag,
Expand Down Expand Up @@ -124,9 +125,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 +325,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, probeEcsClusterRegionFlag, "", "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 bdeaaeb

Please sign in to comment.