ecs probe: Allow cache settings to be tweaked

This commit is contained in:
Mike Lang
2017-01-12 11:37:23 -08:00
parent 513977081d
commit 685af493bf
4 changed files with 15 additions and 7 deletions

View File

@@ -60,7 +60,7 @@ 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) (ecsClient, error) {
sess := session.New()
region, err := ec2metadata.New(sess).Region()

View File

@@ -78,13 +78,17 @@ func getLabelInfo(rpt report.Report) map[string]map[string]*taskLabelInfo {
// Reporter implements Tagger, Reporter
type Reporter struct {
clientsByCluster map[string]*ecsClient
clientsByCluster map[string]ecsClient
cacheSize int
cacheExpiry time.Duration
}
// Make creates a new Reporter
func Make() Reporter {
func Make(cacheSize int, cacheExpiry time.Duration) Reporter {
return Reporter{
clientsByCluster: map[string]*ecsClient{},
clientsByCluster: map[string]ecsClient{},
cacheSize: cacheSize,
cacheExpiry: cacheExpiry,
}
}
@@ -101,7 +105,7 @@ func (r Reporter) Tag(rpt report.Report) (report.Report, error) {
if !ok {
log.Debugf("Creating new ECS client")
var err error
client, err = newClient(cluster, 1e6, time.Hour) // TODO remove these temporary magic values
client, err = newClient(cluster, r.cacheSize, r.cacheExpiry)
if err != nil {
return rpt, err
}

View File

@@ -104,7 +104,9 @@ type probeFlags struct {
kubernetesEnabled bool
kubernetesConfig kubernetes.ClientConfig
ecsEnabled bool
ecsEnabled bool
ecsCacheSize int
ecsCacheExpiry time.Duration
weaveEnabled bool
weaveAddr string
@@ -287,6 +289,8 @@ func main() {
// AWS ECS
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")
// Weave
flag.StringVar(&flags.probe.weaveAddr, "probe.weave.addr", "127.0.0.1:6784", "IP address & port of the Weave router")

View File

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