mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
ecs probe: Allow cache settings to be tweaked
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user